Debian Codegraph @

editor/drawworld.cpp

raw
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 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/editor/drawworld.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003-08-26 03:57:37 $
23 * $Author: kevinb $
24 *
25 * Code to draw wireframe world for editor
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 36 4/22/99 5:17p Matt
30 * Changed the and & or fields in the grCodes struct to cc_and & cc_or,
31 * since the former names didn't work with some compilers.
32 *
33 * 35 3/01/99 2:58p Dan
34 * Set lighting type before wireframe search, because sometimes it was set
35 * wrong & the search wouldn't work. (MattT on Dan's machine)
36 *
37 * 34 2/28/99 6:18p Matt
38 * Commented-out Int3()
39 *
40 * 33 2/13/99 6:29p Matt
41 * Always check current room when searching, because if the render radius
42 * is low it was getting checked.
43 *
44 * 32 2/03/99 1:10p Matt
45 * Changed the paletted room current faces to be stored in a seperate
46 * array, instead of in the room structure.
47 *
48 * 31 12/01/98 11:17p Matt
49 * Added menu option to disable drawing objects in the wireframe view
50 *
51 * 30 10/04/98 1:25p Matt
52 *
53 * 29 9/04/98 12:29p Matt
54 * Added marked edge & vertex in the editor
55 *
56 * 28 9/01/98 12:04p Matt
57 * Ripped out multi-face portal code
58 *
59 * 27 5/20/98 3:48p Matt
60 * Added suport for variable-depth face selection in wireframe view.
61 *
62 * 26 5/14/98 12:56p Jason
63 * changes to help lower memory usage
64 *
65 * 25 2/16/98 1:08p Matt
66 * Draw the current vertex in the wireframe view
67 *
68 * 24 1/29/98 5:50p Matt
69 * Changed old camera object type to be viewer object (for editor), and
70 * now camera objects will just be for game cameras.
71 *
72 * 23 1/12/98 3:34p Jason
73 * sped up indoor rendering by clipping faces against portals
74 *
75 * 22 12/19/97 5:23p Samir
76 * Clear before frame in Wireframe.
77 *
78 * 21 12/19/97 12:26p Samir
79 * Replaced g3_StartFrame with StartEditorFrame
80 *
81 * 20 10/15/97 5:20p Jason
82 * did a HUGE overhaul of the bitmap system
83 *
84 * 19 9/29/97 12:09p Jason
85 * added functionality to doorway system
86 *
87 * 18 9/22/97 5:21p Matt
88 * Got box selection working for room engine
89 *
90 * 17 9/17/97 1:01p Matt
91 * Ripped out segment code
92 *
93 * 16 9/17/97 11:34a Matt
94 * Ripped out segment code
95 *
96 * 15 9/11/97 7:08p Matt
97 * Added code to draw floating trigger faces
98 *
99 * 14 9/09/97 3:58p Matt
100 * Ripped out segment engine renderer
101 *
102 * 13 9/06/97 3:16p Matt
103 * Added current portal system
104 *
105 * 12 9/04/97 4:39p Matt
106 * Added includes needed as a result of removing includes from d3edit.h
107 *
108 * 11 8/29/97 5:35p Matt
109 * Massive changes: ripped out segment code, make current & selection
110 * rooms draw special, made facing & nonfacing edges draw in different
111 * colors.
112 *
113 * 10 8/22/97 9:31a Matt
114 * Terrain portals now draw in blue.
115 *
116 * 9 8/20/97 10:39a Matt
117 * If a frame hasn't been previously rendered when the findroomface
118 * function is called, handle it gracefully.
119 *
120 * 8 8/18/97 6:59p Matt
121 * Implemented Place Room/Attach room system
122 *
123 * 7 8/05/97 10:48a Matt
124 * Draw marked face
125 *
126 * 6 7/29/97 12:16p Matt
127 * Made wireframe seach work for rooms & faces
128 *
129 * 5 7/24/97 6:11p Matt
130 * Created symbolic constant for default zoom, and used it every place
131 * that specifies zoom
132 *
133 * 4 7/22/97 7:07p Matt
134 * Cleaned up D3EditState, moving some vars in and some out, and renaming
135 * and changing a few others
136 *
137 * 3 7/16/97 4:18p Matt
138 * Changes to work with changed 3d draw functions
139 *
140 * 22 5/21/97 12:29p Jason
141 * added the ability to draw terrain dots in mine view
142 *
143 * 21 5/15/97 3:27a Jason
144 * implemented terrain magnification
145 *
146 * 20 5/13/97 7:47p Matt
147 * Added code to compress mine before saving.
148 * Cleaned up code dealing with num vertices & segments.
149 *
150 * 19 5/12/97 11:41a Jason
151 * made game work (default) to 16bit no mip maps mode
152 * Saves us alot of memory
153 *
154 * 18 5/01/97 6:06p Matt
155 * Deleted commented-out code
156 *
157 * 17 4/30/97 3:15p Jason
158 * changes to support both 8bit and 16bit rendering in software
159 *
160 * 16 4/10/97 4:39p Jason
161 * Made selection manager stuff work with terrain topographical map
162 *
163 * 15 4/01/97 10:51p Matt
164 * Draw viewer based on object type
165 *
166 * 14 4/01/97 5:18p Matt
167 * Draw objects as spheres in wireframe view
168 *
169 * 13 3/20/97 11:55a Jason
170 * changes for terrain editing/drawing
171 *
172 * 12 3/17/97 11:59a Matt
173 * Added code to draw warning segments
174 *
175 * 11 3/17/97 11:10a Jason
176 * added wireframe terrain view
177 *
178 * 10 2/28/97 6:38p Matt
179 * Fixed box selection bug, & added supprt for two box selection modes
180 *
181 * 9 2/28/97 4:00p Matt
182 * Added code to handle the list of selected segments
183 *
184 * 8 2/28/97 9:33a Matt
185 * Improved code that checked for segments by writing a pixel and reading
186 * that pixel after rendering.
187 *
188 * 7 2/26/97 5:59p Matt
189 * Renamed 3d lib structs for D3 naming convention
190 *
191 * 6 2/24/97 5:57p Matt
192 * Restored code to draw marked seg in different color
193 *
194 * 5 2/24/97 12:23p Matt
195 * Changed the name of some segment struct elements
196 *
197 * 4 2/19/97 5:37p Matt
198 * Added code to set curseg from clicking in wireframe window
199 *
200 * 3 2/07/97 6:02p Matt
201 * Enabled code that draws current seg, side, & edge
202 *
203 * $NoKeywords: $
204 */
205
206 #include "drawworld.h"
207
208 #include <stdlib.h>
209
210 #include "3d.h"
211
212 #include "descent.h"
213 #include "d3edit.h"
214 #include "selectedroom.h"
215 #include "terrain.h"
216 #include "object.h"
217 #include "erooms.h"
218 #include "group.h"
219 #include "renderer.h"
220
221 int Draw_all_rooms = 1;
222
223 // the viewport we're currently drawing to
224 grViewport *Draw_viewport;
225
226 // Colors for rooms/edges
227 #define FACING_COLOR GR_RGB(198, 198, 198)
228 #define NOTFACING_COLOR GR_RGB(125, 125, 125) // GR_RGB( 158, 158, 158)
229 #define PLACED_COLOR GR_RGB(255, 0, 255)
230 #define SELECTED_COLOR GR_RGB(255, 166, 0)
231 #define TERR_PORTAL_COLOR GR_RGB(0, 0, 255)
232 #define CURROOM_COLOR GR_RGB(255, 255, 255)
233 #define CURFACE_COLOR GR_RGB(255, 255, 0)
234 #define CUREDGE_COLOR GR_RGB(0, 255, 0)
235 #define MARKEDFACE_COLOR GR_RGB(0, 255, 255)
236 #define MARKEDEDGE_COLOR GR_RGB(0, 150, 150)
237 #define CURPORTAL_COLOR GR_RGB(200, 150, 255)
238 #define FLOAT_TRIG_COLOR GR_RGB(255, 100, 100)
239
240 // Unused for now
241 #define FOUND_COLOR GR_RGB(0, 121, 182)
242 #define WARNING_COLOR GR_RGB(255, 0, 0)
243 #define MARKEDROOM_COLOR GR_RGB(0, 255, 0)
244
245 // Colors for objects
246 #define ROBOT_COLOR GR_RGB(255, 0, 0) // a robot
247 #define PLAYER_COLOR GR_RGB(0, 255, 0) // a player object
248 #define VIEWER_COLOR GR_RGB(100, 0, 100) // a viewer
249 #define POWERUP_COLOR GR_RGB(0, 0, 255) // a powerup
250 #define MISCOBJ_COLOR GR_RGB(0, 100, 100) // some other object
251 #define CAMERA_COLOR GR_RGB(255, 255, 0) // a camera
252
253 // vars for WireframeFindRoomFace()
254 static int Search_mode = 0; // if 1, searching for point, if 2, searching for box
255 static int Search_x, Search_y;
256 static int Search_find_mode;
257 static float Search_min_dist = 0.0;
258 static int Search_left, Search_top, Search_right, Search_bot;
259 static int Search_roomnum, Search_facenum;
260 static vector Search_viewer; // used to determine closest room
261 static int Found_roomnum;
262 static int Found_facenum;
263 static float Found_dist;
264 static grViewport *last_vp;
265 static vector last_viewer_position;
266 static vector last_viewer_target;
267 static matrix last_view_orient;
268 static int last_start_seg;
269 static int last_start_room;
270 static float last_rad;
271 static float last_zoom;
272
273 extern vector *TS_View_position;
274 extern matrix *TS_View_matrix;
275 extern matrix View_matrix;
276 void PreRotateTerrain();
277 void Terrain_start_frame(vector *eye, matrix *view_orient);
278
279 void DrawTerrainPoints(vector *view_pos, matrix *view_orient) {
280 g3Point terr_point;
281 int i;
282
283 Terrain_start_frame(view_pos, &View_matrix);
284
285 for (i = 0; i < TERRAIN_DEPTH * TERRAIN_WIDTH; i++) {
286 GetPreRotatedPoint(&terr_point, i % TERRAIN_WIDTH, i / TERRAIN_WIDTH, Terrain_seg[i].ypos);
287 terr_point.p3_flags = 0;
288 g3_CodePoint(&terr_point);
289 if (!terr_point.p3_codes) {
290 g3_ProjectPoint(&terr_point);
291 Draw_viewport->setpixel(GR_RGB(255, 255, 255), terr_point.p3_sx, terr_point.p3_sy);
292 }
293 }
294 }
295
296 // edge types - lower number types have precedence
297 #define ET_EMPTY 255 // this entry in array is empty
298 #define ET_FACING 0 // this edge on a facing face
299 #define ET_NOTFACING 1 // this edge on a non-facing face
300 #define N_EDGE_TYPES 2 // how many edge types there are
301
302 struct seg_edge {
303 union {
304 struct {
305 int16_t v0, v1;
306 };
307 int32_t vv;
308 };
309 uint16_t type;
310 };
311
312 #define MAX_EDGES (MAX_VERTS_PER_ROOM * 2)
313
314 seg_edge edge_list[MAX_EDGES];
315
316 int16_t used_list[MAX_EDGES]; // which entries in edge_list have been used
317 int n_used;
318
319 int edge_list_size; // set each frame
320
321 #define HASH(a, b) ((a * 5 + b) % edge_list_size)
322
323 #define swap(a, b) \
324 do { \
325 int t; \
326 t = (a); \
327 (a) = (b); \
328 (b) = t; \
329 } while (0)
330
331 // finds edge, filling in edge_ptr. if found old edge, returns index, else return -1
332 int FindEdge(int v0, int v1, seg_edge **edge_ptr) {
333 int32_t vv;
334 int16_t hash, oldhash;
335 int ret;
336
337 vv = (v1 << 16) + v0;
338
339 oldhash = hash = HASH(v0, v1);
340
341 ret = -1;
342
343 while (ret == -1) {
344
345 if (edge_list[hash].type == ET_EMPTY)
346 ret = 0;
347 else if (edge_list[hash].vv == vv)
348 ret = 1;
349 else {
350 if (++hash == edge_list_size)
351 hash = 0;
352 if (hash == oldhash)
353 Error("Edge list full!");
354 }
355 }
356
357 *edge_ptr = &edge_list[hash];
358
359 if (ret == 0)
360 return -1;
361 else
362 return hash;
363 }
364
365 // adds an edge to the edge list
366 void AddEdge(int v0, int v1, uint8_t type) {
367 int found;
368
369 seg_edge *e;
370
371 // mprintf(0, "Verts = %2i %2i, type = %i ", v0, v1, type);
372 if (v0 > v1)
373 swap(v0, v1);
374
375 found = FindEdge(v0, v1, &e);
376
377 if (found == -1) {
378 e->v0 = v0;
379 e->v1 = v1;
380 e->type = type;
381 used_list[n_used] = e - edge_list;
382 n_used++;
383 } else {
384 if (type < e->type)
385 e->type = type;
386 }
387 }
388
389 // If searching for a point, see if this room draws at the search x,y position, and if so,
390 // if it's the closest to the viewer. If searching for a box, see if any of the room points are
391 // inside the box.
392 void CheckRoom(room *rp) {
393 uint8_t codes_and = 0xff;
394 int vn;
395
396 // Rotate all the points
397 for (vn = 0; vn < rp->num_verts; vn++)
398 codes_and &= g3_RotatePoint((g3Point *)&World_point_buffer[vn], &rp->verts[vn]);
399
400 if (!codes_and) { // all off screen?
401
402 if (Search_mode == 1) { // searching for a point
403 int fn;
404 ddgr_color oldcolor;
405 face *fp;
406
407 rend_SetLighting(LS_NONE);
408 rend_SetTextureType(TT_FLAT);
409
410 for (fn = 0, fp = rp->faces; fn < rp->num_faces; fn++, fp++) {
411 g3Point *vert_list[MAX_VERTS_PER_FACE];
412
413 codes_and = 0xff;
414 for (vn = 0; vn < fp->num_verts; vn++) {
415 vert_list[vn] = (g3Point *)&World_point_buffer[fp->face_verts[vn]];
416 codes_and &= vert_list[vn]->p3_codes;
417 }
418
419 if (!codes_and) {
420
421 Draw_viewport->setpixel(GR_RGB(0, 0, 0), Search_x, Search_y);
422 oldcolor = Draw_viewport->getpixel(Search_x, Search_y); // will be different in 15/16-bit color
423 rend_SetFlatColor(GR_RGB(255, 255, 255));
424
425 g3_CheckAndDrawPoly(fp->num_verts, vert_list, 0, NULL, NULL);
426
427 if (Draw_viewport->getpixel(Search_x, Search_y) != oldcolor) {
428 vector t;
429 float dist;
430
431 ComputeCenterPointOnFace(&t, rp, fn);
432
433 dist = vm_VectorDistance(&t, &Search_viewer);
434
435 if (Search_find_mode == FM_SPECIFIC) {
436 if ((ROOMNUM(rp) == Search_roomnum) && (fn == Search_facenum)) {
437 Found_roomnum = ROOMNUM(rp);
438 Found_facenum = fn;
439 Found_dist = dist;
440 }
441 } else if ((Found_roomnum == -1 || dist < Found_dist) && (dist > Search_min_dist)) {
442 Found_roomnum = ROOMNUM(rp);
443 Found_facenum = fn;
444 Found_dist = dist;
445 }
446 }
447 }
448 }
449 } else if (Search_mode == 2) { // searching in a box
450 int v;
451
452 for (v = 0; v < rp->num_verts; v++) {
453 int x, y;
454
455 g3_ProjectPoint((g3Point *)&World_point_buffer[v]);
456
457 x = Round(World_point_buffer[v].p3_sx);
458 y = Round(World_point_buffer[v].p3_sy);
459
460 if ((x >= Search_left) && (y >= Search_top) && (x <= Search_right) && (y <= Search_bot)) {
461 if ((D3EditState.box_selection_mode == ACROSS_EDGE) || (v == rp->num_verts - 1)) {
462 AddRoomToSelectedList(ROOMNUM(rp));
463 Found_roomnum++; // doubles as a counter
464 break; // no need to check rest of verts
465 }
466 } else // this point not in window
467 if (D3EditState.box_selection_mode == IN_WINDOW) // seg not entirely in window
468 break; //..so stop checking this room
469 }
470 } else
471 Int3(); // unknown Search_mode
472 }
473 }
474
475 void DrawLine(ddgr_color color, int pnum0, int pnum1) {
476 g3Point pnt1, pnt2;
477
478 pnt1 = *((g3Point *)&World_point_buffer[pnum0]);
479 pnt2 = *((g3Point *)&World_point_buffer[pnum1]);
480
481 g3_DrawLine(color, &pnt1, &pnt2);
482 }
483
484 void DrawEdges(int room_color = -1);
485
486 void DrawEdges(int room_color) {
487 int i, type;
488 seg_edge *e;
489 ddgr_color edge_colors[] = {FACING_COLOR, NOTFACING_COLOR};
490
491 for (type = N_EDGE_TYPES - 1; type >= 0; type--) {
492 for (i = 0; i < n_used; i++) {
493 e = &edge_list[used_list[i]];
494 if (e->type == type)
495 DrawLine((room_color == -1) ? edge_colors[type] : room_color, e->v0, e->v1);
496 }
497 }
498 }
499
500 void DrawAllRooms(vector *view_target, float rad);
501 void DrawRoom(room *rp, int room_type = -1);
502
503 // Finds the closest room:face to the viewer at a given x,y screen position in the wireframe view
504 // Parameters: vp - the viewport we're checking. Must be the same viewport as the last wireframe view rendered
505 // x,y - the screen coordinates clicked on
506 // roomnum,facenum - pointers to variables to be filled in
507 // find_mode - see values in header file
508 // Returns: true if found a room/face
509 bool WireframeFindRoomFace(grViewport *vp, int x, int y, int *roomnum, int *facenum, int find_mode) {
510 if (last_vp == NULL)
511 return 0;
512
513 if (vp != last_vp) {
514 // Int3();
515 return 0;
516 }
517
518 Draw_viewport = vp;
519
520 vp->clear();
521
522 StartEditorFrame(vp, &last_viewer_position, &last_view_orient, last_zoom);
523
524 Search_mode = 1;
525 Search_find_mode = find_mode;
526 Search_x = x;
527 Search_y = y;
528 Search_viewer = last_viewer_position;
529 Search_min_dist = (find_mode == FM_NEXT) ? Found_dist : 0.0;
530 Search_roomnum = *roomnum;
531 Search_facenum = *facenum;
532 Found_roomnum = -1;
533 Found_facenum = -1;
534
535 if (Editor_view_mode == VM_ROOM) {
536 ASSERT(D3EditState.current_room != -1);
537 CheckRoom(&Rooms[D3EditState.current_room]);
538 } else {
539 DrawAllRooms(&last_viewer_target, last_rad);
540 CheckRoom(Curroomp);
541 }
542
543 EndEditorFrame();
544
545 Search_mode = 0;
546
547 if (Found_roomnum != -1) {
548 *roomnum = Found_roomnum;
549 *facenum = Found_facenum;
550 return 1;
551 } else
552 return 0;
553 }
554
555 // Adds all the rooms that have a vertex inside of a given screen box to the selected list
556 // Parameters: vp - the viewport we're checking. Must be the same viewport as the last wireframe view rendered
557 // left,top,right,bot - the screen coordinates of the box
558 // Returns: the number of rooms found
559 int SelectRoomsInBox(grViewport *vp, int left, int top, int right, int bot) {
560
561 // TEMP: The caller doesn't know the viewport, so we set it here
562 vp = last_vp;
563
564 if (vp != last_vp) {
565 Int3();
566 return -1;
567 }
568
569 Draw_viewport = vp;
570
571 vp->clear();
572
573 StartEditorFrame(vp, &last_viewer_position, &last_view_orient, last_zoom);
574
575 Search_mode = 2;
576 Search_left = left;
577 Search_top = top;
578 Search_right = right;
579 Search_bot = bot;
580 Search_viewer = last_viewer_position;
581 Found_roomnum = 0; // we use this as a counter
582
583 DrawAllRooms(&last_viewer_target, last_rad);
584
585 EndEditorFrame();
586
587 Search_mode = 0;
588
589 return Found_roomnum;
590 }
591
592 // Resets the edge list
593 void ResetEdgeList(int size) {
594 int i;
595
596 edge_list_size = __min(size, MAX_EDGES); // make maybe smaller than max
597
598 for (i = 0; i < edge_list_size; i++) {
599 edge_list[i].type = ET_EMPTY;
600 }
601
602 n_used = 0;
603 }
604
605 // Draw a room
606 void DrawRoom(room *rp, int room_color) {
607 int fn, vn;
608 face *fp;
609 int edge_type;
610
611 ResetEdgeList(MAX_EDGES);
612
613 // Rotate all the points
614 for (vn = 0; vn < rp->num_verts; vn++)
615 g3_RotatePoint((g3Point *)&World_point_buffer[vn], &rp->verts[vn]);
616
617 for (fn = 0, fp = rp->faces; fn < rp->num_faces; fn++, fp++) {
618 if (fp->flags & FF_FLOATING_TRIG) {
619 for (vn = 0; vn < fp->num_verts; vn++)
620 DrawLine(FLOAT_TRIG_COLOR, fp->face_verts[vn], fp->face_verts[(vn + 1) % fp->num_verts]);
621 DrawLine(FLOAT_TRIG_COLOR, fp->face_verts[0], fp->face_verts[2]);
622 DrawLine(FLOAT_TRIG_COLOR, fp->face_verts[1], fp->face_verts[3]);
623 } else if (fp->portal_num == -1) {
624 bool facing = g3_CheckNormalFacing(&rp->verts[fp->face_verts[0]], &fp->normal);
625 for (vn = 0; vn < fp->num_verts; vn++) {
626 if (facing)
627 edge_type = ET_NOTFACING;
628 else
629 edge_type = ET_FACING;
630
631 AddEdge(fp->face_verts[vn], fp->face_verts[(vn + 1) % fp->num_verts], edge_type);
632 }
633 }
634 }
635
636 DrawEdges(room_color);
637
638 // Now draw the terrain portals
639 for (int p = 0; p < rp->num_portals; p++) {
640 portal *pp = &rp->portals[p];
641 if (pp->croom == -1) { // terrain portal
642 fp = &rp->faces[pp->portal_face];
643 for (vn = 0; vn < fp->num_verts; vn++)
644 DrawLine(TERR_PORTAL_COLOR, fp->face_verts[vn], fp->face_verts[(vn + 1) % fp->num_verts]);
645 }
646 }
647 }
648
649 // Draw a room rotated and placed in space
650 void DrawRoomRotated(room *rp, vector *rotpoint, matrix *rotmat, vector *placepoint, int room_color) {
651 int fn, vn;
652 face *fp;
653
654 ResetEdgeList(MAX_EDGES);
655
656 // Rotate all the points
657 for (vn = 0; vn < rp->num_verts; vn++) {
658 vector tv;
659 tv = (rp->verts[vn] - *rotpoint) * *rotmat + *placepoint;
660 g3_RotatePoint((g3Point *)&World_point_buffer[vn], &tv);
661 }
662
663 for (fn = 0, fp = rp->faces; fn < rp->num_faces; fn++, fp++)
664 for (vn = 0; vn < fp->num_verts; vn++)
665 AddEdge(fp->face_verts[vn], fp->face_verts[(vn + 1) % fp->num_verts], ET_FACING);
666
667 DrawEdges(room_color);
668 }
669
670 void DrawRoomFace(ddgr_color color, room *rp, int facenum) {
671 face *fp = &rp->faces[facenum];
672 g3Codes cc;
673 int i;
674
675 // Rotate the points in this face
676 cc.cc_and = 0xff;
677 cc.cc_or = 0;
678 for (i = 0; i < fp->num_verts; i++) {
679 int vertnum = fp->face_verts[i];
680 g3_RotatePoint((g3Point *)&World_point_buffer[vertnum], &rp->verts[vertnum]);
681 cc.cc_and &= World_point_buffer[vertnum].p3_codes;
682 cc.cc_or |= World_point_buffer[vertnum].p3_codes;
683 }
684
685 if (!cc.cc_and) // if not all off screen
686 for (i = 0; i < fp->num_verts; i++)
687 DrawLine(color, fp->face_verts[i], fp->face_verts[(i + 1) % fp->num_verts]);
688 }
689
690 void DrawFaceEdge(ddgr_color color, room *rp, int facenum, int edgenum) {
691 face *fp = &rp->faces[facenum];
692 int v0, v1;
693
694 v0 = fp->face_verts[edgenum];
695 v1 = fp->face_verts[(edgenum + 1) % fp->num_verts];
696
697 g3_RotatePoint((g3Point *)&World_point_buffer[v0], &rp->verts[v0]);
698 g3_RotatePoint((g3Point *)&World_point_buffer[v1], &rp->verts[v1]);
699
700 if (!(World_point_buffer[v0].p3_codes & World_point_buffer[v1].p3_codes))
701 DrawLine(color, v0, v1);
702 }
703
704 // Draw the objects in a room as spheres
705 void DrawRoomObjects(room *rp) {
706 int objnum;
707
708 if (!D3EditState.objects_in_wireframe)
709 return;
710
711 for (objnum = rp->objects; objnum != -1; objnum = Objects[objnum].next) {
712 object *obj = &Objects[objnum];
713 g3Point sphere_point;
714 ddgr_color color;
715
716 switch (obj->type) {
717 case OBJ_POWERUP:
718 color = POWERUP_COLOR;
719 break;
720 case OBJ_ROBOT:
721 color = ROBOT_COLOR;
722 break;
723 case OBJ_PLAYER:
724 color = PLAYER_COLOR;
725 break;
726 case OBJ_VIEWER:
727 color = VIEWER_COLOR;
728 break;
729 case OBJ_CAMERA:
730 color = CAMERA_COLOR;
731 break;
732 default:
733 color = MISCOBJ_COLOR;
734 break;
735 }
736
737 if (obj->type == OBJ_DOOR) // don't draw doors
738 continue;
739
740 g3_RotatePoint(&sphere_point, &obj->pos);
741 g3_DrawSphere(color, &sphere_point, obj->size);
742 }
743 }
744
745 void DrawAllRooms(vector *view_target, float rad) {
746 int r;
747 room *rp;
748
749 for (r = 0, rp = Rooms; r <= Highest_room_index; r++, rp++) {
750 if (rp->used && (vm_VectorDistance(&rp->verts[0], view_target) < rad)) {
751 if (Search_mode)
752 CheckRoom(rp);
753 else {
754 DrawRoom(rp);
755 DrawRoomObjects(rp);
756 }
757 }
758 }
759 }
760
761 #define CROSS_WIDTH 8.0
762 #define CROSS_HEIGHT 8.0
763
764 void DrawVertBox(vector *v, ddgr_color color) {
765 // Draw a box at the marked vert
766 g3Point p0;
767 uint8_t c0 = g3_RotatePoint(&p0, v);
768 if (!c0) { // on screen?
769 g3_ProjectPoint(&p0);
770 rend_SetFlatColor(color);
771 rend_DrawLine(p0.p3_sx - CROSS_WIDTH, p0.p3_sy, p0.p3_sx, p0.p3_sy - CROSS_HEIGHT);
772 rend_DrawLine(p0.p3_sx, p0.p3_sy - CROSS_HEIGHT, p0.p3_sx + CROSS_WIDTH, p0.p3_sy);
773 rend_DrawLine(p0.p3_sx + CROSS_WIDTH, p0.p3_sy, p0.p3_sx, p0.p3_sy + CROSS_HEIGHT);
774 rend_DrawLine(p0.p3_sx, p0.p3_sy + CROSS_HEIGHT, p0.p3_sx - CROSS_WIDTH, p0.p3_sy);
775 }
776 }
777
778 void DrawWorld(grViewport *vp, vector *view_target, matrix *view_orient, float view_dist, int start_room, float rad) {
779 vector viewer_position;
780 float zoom = D3_DEFAULT_ZOOM;
781
782 ASSERT(Curroomp != NULL);
783
784 viewer_position = *view_target - (view_orient->fvec * view_dist);
785
786 // save for possible use by find function
787 last_vp = vp;
788 last_viewer_position = viewer_position;
789 last_viewer_target = *view_target;
790 last_view_orient = *view_orient;
791 last_start_room = start_room;
792 last_rad = rad;
793 last_zoom = zoom;
794
795 Draw_viewport = vp;
796
797 vp->clear();
798 StartEditorFrame(vp, &viewer_position, view_orient, zoom);
799
800 if (Editor_view_mode == VM_ROOM) {
801 ASSERT(D3EditState.current_room != -1);
802 if (Search_mode)
803 CheckRoom(&Rooms[D3EditState.current_room]);
804 else {
805 room *rp = &Rooms[D3EditState.current_room];
806 DrawRoom(rp);
807 ASSERT(D3EditState.current_room >= FIRST_PALETTE_ROOM);
808 if (Current_faces[D3EditState.current_room - FIRST_PALETTE_ROOM] != -1)
809 DrawRoomFace(CURFACE_COLOR, rp, Current_faces[D3EditState.current_room - FIRST_PALETTE_ROOM]);
810 }
811 } else {
812 if (D3EditState.terrain_dots)
813 DrawTerrainPoints(&viewer_position, view_orient);
814
815 // Draw all rooms or only connected rooms.
816 if (Draw_all_rooms) {
817 int r;
818 room *rp;
819 for (r = 0, rp = Rooms; r <= Highest_room_index; r++, rp++) {
820 if (rp->used && (vm_VectorDistance(&rp->verts[0], view_target) < rad)) {
821 if (rp != Curroomp) {
822 int color = -1;
823 if (IsRoomSelected(r))
824 color = SELECTED_COLOR;
825 DrawRoom(rp, color);
826 }
827 DrawRoomObjects(rp);
828 }
829 }
830 } else
831 Error("No support yet for Draw_all_rooms==0");
832 //??DrawMine(mine_ptr,depth);
833
834 if (Placed_room != -1)
835 if (Rooms[Placed_room].used)
836 DrawRoomRotated(&Rooms[Placed_room], &Placed_room_origin, &Placed_room_rotmat, &Placed_room_attachpoint,
837 PLACED_COLOR);
838
839 if (Placed_group)
840 for (int r = 0; r < Placed_group->nrooms; r++)
841 DrawRoomRotated(&Placed_group->rooms[r], &Placed_room_origin, &Placed_room_rotmat, &Placed_room_attachpoint,
842 PLACED_COLOR);
843
844 //@@DrawWarningSegments();
845 //@@draw_group_segments();
846 //@@draw_found_segments();
847 //@@DrawSelectedSegments();
848 //@@draw_special_segments();
849
850 // Highlight marked room side.
851 if (Markedroomp) {
852 DrawRoomFace(MARKEDFACE_COLOR, Markedroomp, Markedface);
853 DrawFaceEdge(MARKEDEDGE_COLOR, Markedroomp, Markedface, Markededge);
854 DrawVertBox(&Markedroomp->verts[Markedroomp->faces[Markedface].face_verts[Markedvert]], MARKEDEDGE_COLOR);
855 }
856
857 // Draw current room, face, & edge
858 DrawRoom(Curroomp, CURROOM_COLOR);
859 if (Curportal != -1)
860 DrawRoomFace(CURPORTAL_COLOR, Curroomp, Curroomp->portals[Curportal].portal_face);
861 DrawRoomFace(CURFACE_COLOR, Curroomp, Curface);
862 DrawFaceEdge(CUREDGE_COLOR, Curroomp, Curface, Curedge);
863 DrawVertBox(&Curroomp->verts[Curroomp->faces[Curface].face_verts[Curvert]], CUREDGE_COLOR);
864 }
865
866 EndEditorFrame();
867 }