Debian Codegraph @

renderer/HardwareInstance.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "3d.h"cxx . . $ `<file>/lib/3d.h`/
20 #include "HardwareInternal.h"cxx . . $ `<file>/renderer/HardwareInternal.h`/
21 #include <string.h>
22
23 struct InstanceContextcxx . . $ InstanceContext# {
24 matrixcxx . . $ matrix# m_viewMatrixcxx . . $ InstanceContext#m_viewMatrix.; // matrix
25 matrixcxx . . $ matrix# m_unscaledMatrixcxx . . $ InstanceContext#m_unscaledMatrix.; // unscaled matrix
26 vectorcxx . . $ vector# m_viewPositioncxx . . $ InstanceContext#m_viewPosition.; // position
27 float m_modelViewcxx . . $ InstanceContext#m_modelView.[4][4]; // model/view transform
28 };
29
30 #define MAX_INSTANCE_DEPTHcxx . . $ `renderer/HardwareInstance.cpp:30:9`! 30
31 static InstanceContextcxx . . $ InstanceContext# sInstanceStackcxx . . $ sInstanceStack.[MAX_INSTANCE_DEPTHcxx . . $ `renderer/HardwareInstance.cpp:30:9`!];
32 static int sInstanceDepthcxx . . $ sInstanceDepth. = 0;
33
34 // instance at specified point with specified orientation
35 void g3_StartInstanceMatrixcxx . . $ g3_StartInstanceMatrix(bc315f98e1febb02).(vectorcxx . . $ vector# *pos, matrixcxx . . $ matrix# *orient) {
36 ASSERTcxx . . $ `misc/pserror.h:246:9`!(orient != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
37 ASSERTcxx . . $ `misc/pserror.h:246:9`!(sInstanceDepth < MAX_INSTANCE_DEPTHcxx . . $ `renderer/HardwareInstance.cpp:30:9`!);
38
39 sInstanceStackcxx . . $ sInstanceStack.[sInstanceDepthcxx . . $ sInstanceDepth.].m_viewMatrixcxx . . $ InstanceContext#m_viewMatrix. =cxx . . $ matrix#`operator=`(4c6f8b29806742). View_matrixcxx . . $ View_matrix.;
40 sInstanceStackcxx . . $ sInstanceStack.[sInstanceDepthcxx . . $ sInstanceDepth.].m_viewPositioncxx . . $ InstanceContext#m_viewPosition. =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). View_positioncxx . . $ View_position.;
41 sInstanceStackcxx . . $ sInstanceStack.[sInstanceDepthcxx . . $ sInstanceDepth.].m_unscaledMatrixcxx . . $ InstanceContext#m_unscaledMatrix. =cxx . . $ matrix#`operator=`(4c6f8b29806742). Unscaled_matrixcxx . . $ Unscaled_matrix.;
42 memcpy(sInstanceStackcxx . . $ sInstanceStack.[sInstanceDepthcxx . . $ sInstanceDepth.].m_modelViewcxx . . $ InstanceContext#m_modelView., gTransformModelViewcxx . . $ gTransformModelView., sizeof(gTransformModelViewcxx . . $ gTransformModelView.));
43 ++sInstanceDepthcxx . . $ sInstanceDepth.;
44
45 // step 1: subtract object position from view position
46 vectorcxx . . $ vector# tempv = View_positioncxx . . $ View_position. -cxx . . $ operator-(b77b703cd1e43e33). *pos;
47
48 // step 2: rotate view vector through object matrix
49 View_positioncxx . . $ View_position. =cxx . . $ vector#`operator=`(c0842353a20857d). tempv *cxx . . $ `operator*`(14b8f9ac5c1e7b85). *orient;
50
51 // step 3: rotate object matrix through view_matrix (vm = ob * vm)
52 matrixcxx . . $ matrix# tempm, tempm2 = ~cxx . . $ `operator~`(1e820934589b6814).*orient;
53
54 tempm =cxx . . $ matrix#`operator=`(e859ffc26b91394f). tempm2 *cxx . . $ `operator*`(683f8e040c904cb). View_matrixcxx . . $ View_matrix.;
55 View_matrixcxx . . $ View_matrix. =cxx . . $ matrix#`operator=`(4c6f8b29806742). tempm;
56
57 tempm =cxx . . $ matrix#`operator=`(e859ffc26b91394f). tempm2 *cxx . . $ `operator*`(683f8e040c904cb). Unscaled_matrixcxx . . $ Unscaled_matrix.;
58 Unscaled_matrixcxx . . $ Unscaled_matrix. =cxx . . $ matrix#`operator=`(4c6f8b29806742). tempm;
59
60 // transform the model/view matrix
61 g3_GetModelViewMatrixcxx . . $ g3_GetModelViewMatrix(f698744c99c0df38).(&View_positioncxx . . $ View_position., &Unscaled_matrixcxx . . $ Unscaled_matrix., (float *)gTransformModelViewcxx . . $ gTransformModelView.);
62 g3_UpdateFullTransformcxx . . $ g3_UpdateFullTransform(49f6e7a06ebc5aa8).();
63 }
64
65 // instance at specified point with specified orientation
66 void g3_StartInstanceAnglescxx . . $ g3_StartInstanceAngles(5a7036e8e0f776d8).(vectorcxx . . $ vector# *pos, angveccxx . . $ angvec# *angles) {
67 if (angles == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
68 matrixcxx . . $ matrix# ident;
69 vm_MakeIdentitycxx . . $ vm_MakeIdentity(dca75c48c9ab5b54).(&ident);
70 g3_StartInstanceMatrixcxx . . $ g3_StartInstanceMatrix(bc315f98e1febb02).(pos, &ident);
71 return;
72 }
73
74 matrixcxx . . $ matrix# tm;
75 vm_AnglesToMatrixcxx . . $ vm_AnglesToMatrix(654fa9e3c9c3be99).(&tm, angles->pcxx . . $ angvec#p., angles->hcxx . . $ angvec#h., angles->bcxx . . $ angvec#b.);
76
77 g3_StartInstanceMatrixcxx . . $ g3_StartInstanceMatrix(bc315f98e1febb02).(pos, &tm);
78 }
79
80 // pops the old context
81 void g3_DoneInstancecxx . . $ g3_DoneInstance(49f6e7a06ebc5aa8).() {
82 --sInstanceDepthcxx . . $ sInstanceDepth.;
83 ASSERTcxx . . $ `misc/pserror.h:246:9`!(sInstanceDepth >= 0);
84
85 View_positioncxx . . $ View_position. =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). sInstanceStackcxx . . $ sInstanceStack.[sInstanceDepthcxx . . $ sInstanceDepth.].m_viewPositioncxx . . $ InstanceContext#m_viewPosition.;
86 View_matrixcxx . . $ View_matrix. =cxx . . $ matrix#`operator=`(4c6f8b29806742). sInstanceStackcxx . . $ sInstanceStack.[sInstanceDepthcxx . . $ sInstanceDepth.].m_viewMatrixcxx . . $ InstanceContext#m_viewMatrix.;
87 Unscaled_matrixcxx . . $ Unscaled_matrix. =cxx . . $ matrix#`operator=`(4c6f8b29806742). sInstanceStackcxx . . $ sInstanceStack.[sInstanceDepthcxx . . $ sInstanceDepth.].m_unscaledMatrixcxx . . $ InstanceContext#m_unscaledMatrix.;
88 memcpy(gTransformModelViewcxx . . $ gTransformModelView., sInstanceStackcxx . . $ sInstanceStack.[sInstanceDepthcxx . . $ sInstanceDepth.].m_modelViewcxx . . $ InstanceContext#m_modelView., sizeof(gTransformModelViewcxx . . $ gTransformModelView.));
89 g3_UpdateFullTransformcxx . . $ g3_UpdateFullTransform(49f6e7a06ebc5aa8).();
90 }