MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / SetViewerFromRoomFace

Function SetViewerFromRoomFace

editor/HView.cpp:133–208  ·  view source on GitHub ↗

Set the viewer in the specified room facing the specified face If room_center is true, put viewer at the center of the room facing the face If room_center is false, put the viewer directly in front of the selected face If the room is external, put the viewer a distance away from the room, facing either the center (if room_center is true) or the specified face

Source from the content-addressed store, hash-verified

131// If the room is external, put the viewer a distance away from the room,
132// facing either the center (if room_center is true) or the specified face
133void SetViewerFromRoomFace(room *roomp, int facenum, bool room_center) {
134 vector vp, newpos;
135 matrix orient;
136 int roomnum;
137 bool outside_mine = 0;
138
139 ComputeCenterPointOnFace(&vp, roomp, facenum);
140 roomnum = ROOMNUM(roomp);
141
142 if (room_center) {
143
144 // Get position
145 ComputeRoomCenter(&newpos, roomp);
146
147 if (roomp->flags & RF_EXTERNAL) {
148 vector t;
149 float rad = ComputeRoomBoundingSphere(&t, roomp);
150
151 newpos.z -= rad * 1.5;
152
153 if (newpos.x < 1.0)
154 newpos.x = 1.0;
155 if (newpos.x > TERRAIN_WIDTH * TERRAIN_SIZE - 1.0)
156 newpos.x = TERRAIN_WIDTH * TERRAIN_SIZE - 1.0;
157 if (newpos.z < 1.0)
158 newpos.z = 1.0;
159 if (newpos.z > TERRAIN_DEPTH * TERRAIN_SIZE - 1.0)
160 newpos.z = TERRAIN_WIDTH * TERRAIN_SIZE - 1.0;
161
162 orient = Identity_matrix;
163
164 roomnum = GetTerrainRoomFromPos(&newpos);
165 } else {
166 // Get orientation
167 vp -= newpos; // vector from center of room to face
168 vm_VectorToMatrix(&orient, &vp, NULL, NULL);
169 }
170 } else {
171 face *fp = &roomp->faces[facenum];
172
173 newpos = vp + fp->normal * FACE_VIEW_DIST;
174
175 vector t = -fp->normal;
176 vm_VectorToMatrix(&orient, &t, NULL, NULL);
177
178 if (roomp->flags & RF_EXTERNAL) {
179 if (newpos.x < 1.0)
180 newpos.x = 1.0;
181 if (newpos.x > TERRAIN_WIDTH * TERRAIN_SIZE - 1.0)
182 newpos.x = TERRAIN_WIDTH * TERRAIN_SIZE - 1.0;
183 if (newpos.z < 1.0)
184 newpos.z = 1.0;
185 if (newpos.z > TERRAIN_DEPTH * TERRAIN_SIZE - 1.0)
186 newpos.z = TERRAIN_WIDTH * TERRAIN_SIZE - 1.0;
187 roomnum = GetTerrainRoomFromPos(&newpos);
188 } else {
189 int new_roomnum = FindPointRoom(&newpos);
190 if (new_roomnum == -1)

Calls 7

ComputeCenterPointOnFaceFunction · 0.85
ComputeRoomCenterFunction · 0.85
GetTerrainRoomFromPosFunction · 0.85
FindPointRoomFunction · 0.85
MoveViewerFunction · 0.85
vm_VectorToMatrixFunction · 0.50

Tested by

no test coverage detected