Debian Codegraph @

Descent3/renderobject.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 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/renderobject.cpp $
21 * $Revision: 182 $
22 * $Date: 10/03/01 11:35p $
23 * $Author: Kevin $
24 *
25 * Code to render objects
26 *
27 * $Log: /DescentIII/Main/renderobject.cpp $
28 *
29 * 182 10/03/01 11:35p Kevin
30 * multiplayer stripes appear in demo playback
31 *
32 * 181 10/12/99 11:07a Jeff
33 * created virus infected effect
34 *
35 * 180 9/21/99 2:55p Jeff
36 * use powerup color for spark colors
37 *
38 * 179 9/20/99 5:35p Jeff
39 * added -nosparkles command line option to turn off powerup sparkles
40 *
41 * 178 9/20/99 5:30p Jeff
42 * added pretty powerup particles for Katmai systems
43 *
44 * 177 9/18/99 9:28p Jeff
45 * motion blur robots and debris
46 *
47 * 176 8/09/99 3:27p Jeff
48 * fixed render bug with typing indicator
49 *
50 * 175 7/28/99 3:44p Kevin
51 * Mac!
52 *
53 * 174 7/20/99 1:00p Jason
54 * added auto katmai support
55 *
56 * 173 7/08/99 5:47p Jason
57 * changes for new bumpmapping system in 1.1 update patch
58 *
59 * 172 5/26/99 3:03a Jason
60 * fixed bug where flags attached to players would render incorrectly in
61 * multplayer (specifially ctf flags)
62 *
63 * 171 5/13/99 3:41p Ardussi
64 * changes for compiling on the Mac
65 *
66 * 170 5/12/99 3:25p Jason
67 * don't render powerup glows if their render type is RT_NONE
68 *
69 * 169 5/08/99 1:50p Jason
70 * fixed some player colors
71 *
72 * 168 5/03/99 9:27p Jason
73 * fixed one of Chris's bugs with the attach system
74 *
75 * 167 4/29/99 4:58p Jason
76 * fixed typing indicator problem
77 *
78 * 166 4/21/99 11:05a Kevin
79 * new ps_rand and ps_srand to replace rand & srand
80 *
81 * 165 4/19/99 3:25p Jason
82 *
83 * 164 4/19/99 3:46a Jeff
84 * fixed min/max for Linux
85 *
86 * 163 4/17/99 4:51p Jason
87 * fixed stupid headlight issue for good
88 *
89 * 162 4/16/99 11:53a Jason
90 * fixed some lighting issues
91 *
92 * 161 4/14/99 7:21p Jason
93 * made ships more visible in multiplayer
94 *
95 * 160 4/14/99 3:57a Jeff
96 * fixed case mismatch in #includes
97 *
98 * 159 4/09/99 7:04p Jason
99 * changed some texture defines
100 *
101 * 158 4/06/99 1:51p Jason
102 * added new mass driver effect
103 *
104 * 157 4/06/99 10:23a Chris
105 * More "render even though the parent is invisible" cases
106 *
107 * 156 4/03/99 4:56p Jason
108 * fixed deform effect just a little
109 *
110 * 155 4/03/99 2:20p Jason
111 * added better heat damage effect
112 *
113 * 154 3/29/99 4:02p Chris
114 * Patched/Hacked a solution to the invis. after landing problem.
115 *
116 * 153 3/22/99 11:16a Jason
117 * Katmai enhancements
118 *
119 * 152 3/04/99 11:44a Jeff
120 * made it so typing indicator is at max 64x64 when rendering
121 *
122 * 151 3/03/99 4:51p Jason
123 * fixed divide by zero problem
124 *
125 * 150 2/24/99 11:51p Jason
126 * fixed object bug for matt
127 *
128 * 149 2/23/99 12:40p Jason
129 * added more options for generic objects
130 *
131 * 148 2/22/99 3:37p Jason
132 * fixed LOD problems
133 *
134 * 147 2/21/99 4:20p Matt
135 * Added SoundSource objects (and reformatted parts of the object header
136 * files).
137 *
138 * 146 2/18/99 11:05a Jason
139 * fixed some cloak effects
140 *
141 * 145 2/17/99 1:05p Jason
142 * revamped object/face/terrain selection code
143 *
144 * 144 2/15/99 4:11p Jason
145 * made non-vis objects kill all their attach sounds/objects
146 *
147 * 143 2/10/99 12:47p Jeff
148 * fixed up typing indicator
149 *
150 * 142 2/09/99 6:53p Jeff
151 * implemented 'typing inidcator' in multiplayer...players that are typing
152 * messages have an icon on them
153 *
154 * 141 2/09/99 9:59a Chris
155 * Massive BOA update :) Terrain happy now. Vis happy now. Sound happy
156 * now.
157 *
158 * 140 2/05/99 3:00p Jason
159 * fixed bug with my last rev
160 *
161 * 139 2/05/99 12:19p Jason
162 * fixed object selection
163 *
164 * 138 2/02/99 8:43a Chris
165 * I made buildings with AI work correctly (ie really big robots should be
166 * buildings)
167 * anim to and from states are now shorts instead of bytes
168 *
169 * 137 1/27/99 6:08p Jason
170 * first pass at markers
171 *
172 * 136 1/21/99 11:29p Jason
173 * took out misplaced no_glow flag
174 *
175 * 135 1/20/99 5:36p Jason
176 * added custom glows for teams
177 *
178 * 134 1/19/99 4:22p Matt
179 * Added the ability for objects to have their own lighting info,
180 * different from the default lighting for that type of object.
181 *
182 * 133 1/13/99 12:43p Jason
183 * added some more detail settings
184 *
185 * 132 1/13/99 6:38a Jeff
186 * fixed object.h. There were numerous struct declarations that were the
187 * same name as the instance of the struct (gcc doesn't like this).
188 * Changed the struct name. Also added some #ifdef's for linux build,
189 * along with fixing case-sensitive includes
190 *
191 * 131 1/08/99 2:56p Samir
192 * Ripped out OSIRIS1.
193 *
194 * 130 12/14/98 10:53a Jason
195 * added bright player ships option
196 *
197 * 129 12/10/98 7:09p Jason
198 * added cloak fade
199 *
200 * 128 12/10/98 12:27p Jason
201 * added cooler specular mapping for objects
202 *
203 * 127 12/07/98 3:02p Jason
204 * added multi_logo_state
205 *
206 * 126 11/11/98 7:18p Jeff
207 * changes made so that a dedicated server's team is always -1 (team game
208 * or not)
209 *
210 * 125 11/11/98 12:33p Jason
211 * changed black player color
212 *
213 * 124 10/21/98 9:28p Jason
214 * Made no lightmaps work globally
215 *
216 * 123 10/21/98 7:55p Jason
217 * d3d changes
218 *
219 * 122 10/21/98 7:30p Jason
220 * more direct3d changes
221 *
222 * 121 10/19/98 3:16p Jason
223 * additional error checking for lightning
224 *
225 * 120 10/18/98 4:25p Jason
226 * fixes for fogged objects
227 *
228 * 119 10/16/98 3:39p Chris
229 * Improved the object linking system and AI and physics
230 *
231 * 118 10/16/98 2:38p Jason
232 * made powerup halo detail setting work
233 *
234 * 117 10/16/98 2:24p Jason
235 * changes for the demo
236 *
237 * 116 10/14/98 6:24p Jason
238 * made object complexity work
239 *
240 * 115 10/08/98 5:59p Jason
241 * fixed object and room popping with small views
242 *
243 * 114 10/07/98 5:04p Jason
244 * made spheres work in WindowGL mode
245 *
246 * 113 10/02/98 1:47p Jason
247 * added lod player ships
248 *
249 * 112 10/02/98 12:23p Jason
250 * took off sight vector
251 *
252 * 111 10/02/98 11:46a Jason
253 * checked in for samir
254 *
255 * 110 10/01/98 6:10p Jason
256 * added EVT_CLIENT_GETCOLOREDNAME
257 *
258 * 109 10/01/98 4:41p Jason
259 * fixed colors in team games
260 *
261 * 108 10/01/98 4:09p Jason
262 * added multicolor ship stuff
263 *
264 * 107 9/29/98 12:49p Jason
265 * worked on matcen effects and lightning
266 *
267 * 106 9/24/98 12:57p Jason
268 * more state limited optimizations
269 *
270 * 105 9/21/98 5:08p Jason
271 * made damage shield not rotate when you get hit
272 *
273 * 104 9/21/98 1:03p Jason
274 * make sparky damage lightning ramp up depending on amount of damage
275 *
276 * 103 9/18/98 8:23p Jason
277 * fixed insidious vis effect errors
278 *
279 * 102 9/17/98 6:08p Jason
280 * more tweaks for effects
281 *
282 * 101 9/17/98 3:03p Jason
283 * added lightning and invul hit effects
284 *
285 * 100 9/10/98 12:18p Jason
286 * more changes to afterburner/thrust effect
287 *
288 * 99 9/09/98 7:09p Jason
289 * changed afterburner effect for ships
290 *
291 * 98 8/27/98 5:19p Jason
292 * added first rev of reflected surfaces
293 *
294 * 97 8/24/98 1:01p Jason
295 * made object specular faces selectable by texture
296 *
297 * 96 8/19/98 2:19p Jeff
298 * moved detail globals to a struct
299 *
300 * 95 8/18/98 11:38a Jason
301 * fixed polymodel fog lighting
302 *
303 * 94 8/14/98 4:00p Jason
304 * added specular objects outside
305 *
306 * 93 8/13/98 6:57p Jason
307 * made fogged objects render correctly
308 *
309 * 92 8/12/98 6:38p Jeff
310 * don't render ghosted objects (type==OBJ_DUMMY)
311 *
312 * 91 8/03/98 3:59p Chris
313 * Added support for FQ_IGNORE_WEAPONS, added .000001 attach code, fix a
314 * bug in polymodel collision detection
315 *
316 * 90 8/03/98 2:59p Jeff
317 * player names only check doors for visibility
318 *
319 * 89 8/03/98 11:06a Jason
320 * made custom textures work correctly
321 *
322 * 88 7/30/98 11:12a Jason
323 * fixed player names showing up when cloaked
324 *
325 * 87 7/28/98 3:29p Jason
326 * fixed z buffer bug with damage disk
327 *
328 * 86 7/27/98 5:59p Jason
329 * added piggyback mode plus multiplayer colors
330 *
331 * 85 7/02/98 6:30p Jason
332 * added some multiplayer stuff for Jeff
333 *
334 * 84 6/30/98 6:36p Chris
335 * Added rev .1 of multiplayer animations - BTW It is totally not done.
336 *
337 * 83 6/25/98 5:17p Jason
338 * added multiple colored balls for players
339 *
340 * 82 6/22/98 12:27p Jason
341 * fixed stupid bug with my last rev
342 *
343 * 81 6/22/98 12:15p Jason
344 * took out cheap LOD effect with robots
345 *
346 * 80 6/15/98 4:00p Jason
347 * replaced monochromatic polymodel lighting with rgb lighting
348 *
349 * 79 6/11/98 12:48p Jason
350 * added better spewing weapons
351 *
352 * 78 5/11/98 10:41a Jason
353 * made clutter object lodable
354 *
355 * 77 5/05/98 6:26p Chris
356 * Added BBoxs and spheres to external rooms (in mode 2)
357 *
358 * 76 5/04/98 7:26p Chris
359 * Allowed turning off of submodels on robots
360 *
361 * 75 5/04/98 3:51p Matt
362 * Finished (for now) with breaking glass.
363 *
364 * 74 5/04/98 12:28p Matt
365 * Added shard objects
366 *
367 * 73 5/03/98 8:42p Chris
368 *
369 * 72 5/03/98 8:36p Chris
370 * Additional debug info
371 *
372 * 71 4/30/98 12:22p Jason
373 * did some lo-res model optimizations
374 *
375 * 70 4/23/98 6:38p Jason
376 * made bitmaps use 1555 format
377 *
378 * 69 4/19/98 5:00p Jason
379 * added cool napalm effect, plus made object effects dynamically
380 * allocated
381 *
382 * 68 4/17/98 3:57p Jason
383 * added microwave effect
384 *
385 * 67 4/17/98 1:59p Jason
386 * added cool object effects
387 *
388 * 66 4/15/98 3:28p Jason
389 * changed glow stuff to work with new system
390 *
391 * 65 4/13/98 3:51p Chris
392 * Added sphere bubbles to weapons (when wanted) and fixed a small FVI
393 * bug
394 *
395 * 64 4/10/98 12:41p Jason
396 * sped up lighting a little
397 *
398 * 63 4/08/98 12:58p Jason
399 * fixed cloak effect in software
400 *
401 * 62 4/07/98 5:01p Jason
402 * more tweaks to cloak effect
403 *
404 * 61 4/07/98 4:49p Jason
405 * fixed cloak problem
406 *
407 * 60 4/06/98 2:54p Jason
408 * yet more multiplayer changes
409 *
410 * 59 4/02/98 12:24p Jason
411 * trimmed some fat from our structures
412 *
413 * 58 4/01/98 6:23p Jason
414 * added a slew of stuff for multiplayer
415 *
416 * 57 4/01/98 12:02p Jason
417 * incremental checkin for rendering changes
418 *
419 * 56 3/20/98 5:51p Jason
420 * more changes for multiplayer
421 *
422 * 55 3/20/98 2:18p Jason
423 * changes for multiplayer
424 *
425 * 54 3/19/98 7:15p Jason
426 * more changes for multiplayer
427 *
428 * 53 3/13/98 7:00p Chris
429 * EDITOR to _DEBUG
430 *
431 * 52 3/13/98 12:10p Jason
432 * draw a bit of a ring around polygon glows
433 *
434 * 51 3/11/98 4:59p Chris
435 * Added a few new sphere types (wall and anim)
436 *
437 * 50 3/10/98 5:15p Chris
438 * DEL+B shows the bounding-sphere of an object
439 *
440 * 49 3/09/98 5:58p Jason
441 * draw powerups with saturated alpha rings
442 *
443 * 48 3/09/98 4:54p Jason
444 * don't render objects that can't been seen through a portal
445 *
446 * 47 2/25/98 4:31p Jason
447 * changes for explosions
448 *
449 * 46 2/25/98 2:05p Jason
450 * did FOV and object visibility changes
451 *
452 * 45 2/20/98 1:46p Chris
453 * JASON: Made dynamic lighting only occur if the object is rendered
454 *
455 * 44 2/11/98 6:58p Matt
456 * Changed the way cameras are rendered, so they show up on the terrain as
457 * well.
458 *
459 * 43 2/11/98 6:38p Jason
460 * tweaking the glow effects for engines
461 *
462 * 42 2/04/98 6:09p Matt
463 * Changed object room number to indicate a terrain cell via a flag. Got
464 * rid of the object flag which used to indicate terrain.
465 *
466 * 41 2/04/98 2:52p Jason
467 * made length of glow dependant on whether or not the player is thrusting
468 *
469 * 40 1/30/98 6:07p Matt
470 * Added code and menu items to deal with camera objects
471 *
472 * 39 1/30/98 2:56p Matt
473 * Added support for small views. Made R toggle rear view, and Delete-F8
474 * show a view from object 2. Also changed main window render flow so
475 * could share code with small views.
476 *
477 * 38 1/28/98 5:37p Jason
478 * added streamer weapons
479 *
480 * 37 1/23/98 11:21a Jason
481 * incremental multiplayer checkin
482 *
483 * 36 1/21/98 6:09p Jason
484 * Got player deaths working in multiplayer
485 *
486 * 35 1/21/98 1:11p Jason
487 * incremental checkin for multiplayer
488 *
489 * 34 1/20/98 2:17p Jason
490 * fixed weird sorting problem with objects and viseffects
491 *
492 * 33 1/20/98 12:10p Jason
493 * implemented vis effect system
494 *
495 * 32 1/13/98 4:04p Jason
496 * changes for engine glow
497 *
498 * 31 1/13/98 3:09p Jason
499 * added glow effect for engines
500 *
501 * 30 1/05/98 5:59p Jason
502 * tweaked z bias code
503 *
504 * 29 12/08/97 6:18p Jason
505 * more tweaks for destroyable buildings
506 *
507 * 28 12/08/97 5:22p Jason
508 * added code for destroyable buildings that leave their base object
509 * around
510 *
511 * 27 11/25/97 1:36p Jason
512 * adjusted LOD switch levels
513 *
514 * 26 11/25/97 1:17p Jason
515 * added lod system for certain objects
516 *
517 * 25 11/18/97 12:26a Sean
518 * I don't know (Chris)
519 *
520 * 24 11/11/97 8:40p Chris
521 * Added an assert.
522 *
523 * 23 11/05/97 6:03p Jason
524 * added disky colored lighting effects
525 *
526 * 22 11/05/97 12:20p Jason
527 * made powerups render with halos
528 *
529 * 21 10/28/97 11:34a Chris
530 * Fixed a bug in the animation code (if keyframe = 0 and the object
531 * animates, we need to set the angles)
532 *
533 * 20 10/23/97 11:34p Chris
534 * Fixed problems with idle animations
535 *
536 * 19 10/23/97 5:36p Jason
537 * added splinter objects (probably temporary)
538 *
539 * 18 10/20/97 4:46p Jason
540 * changes for explosions
541 *
542 * 17 10/03/97 5:57p Chris
543 * Added support for debug fvi_line
544 *
545 * 16 10/03/97 4:43p Chris
546 * added debug fvi call and object type line
547 *
548 * 15 10/01/97 7:00p Jason
549 * did more work on object lightmaps
550 *
551 * 14 10/01/97 11:35a Jason
552 * added IsObjectVisible function
553 *
554 * 13 9/30/97 5:08p Chris
555 * No changes
556 *
557 * 12 9/22/97 6:20p Matt
558 * Removed obsolete code
559 *
560 * 11 9/16/97 5:04p Matt
561 * Changed conditional for debug code
562 *
563 * 10 9/12/97 5:38p Jason
564 * got doors working
565 *
566 * 9 9/10/97 5:17p Jason
567 * more lighting improvements
568 *
569 * 8 9/09/97 6:15p Jason
570 * made dynamic lighting on objects more memory efficient
571 *
572 * 7 9/03/97 2:12p Chris
573 * Added new weapon battery system and made the animation system usable.
574 *
575 * 6 8/20/97 5:19p Matt
576 * Draw selected bracket instead of box for current object
577 *
578 * $NoKeywords: $
579 */
580 #include "object.h"
581 #include "object_lighting.h"
582 #include "3d.h"
583 #include "polymodel.h"
584 #include "renderer.h"
585 #include "weapon.h"
586 #include "fireball.h"
587 #include "descent.h"
588 #include "renderobject.h"
589 #include "AIMain.h"
590 #include "objinfo.h"
591 #include "splinter.h"
592 #include "fireball.h"
593 #include "descent.h"
594 #include "render.h"
595 #include "gametexture.h"
596 #include "game.h"
597 #include "player.h"
598 #include "damage.h"
599 #include "gameloop.h"
600 #include "findintersection.h"
601 #include "grtext.h"
602 #include "gamefont.h"
603 #include "config.h"
604 #include "viseffect.h"
605 #include "game2dll.h"
606 #include "marker.h"
607 #include "ship.h"
608 #include "psrand.h"
609
610 #include <string.h>
611 #ifdef EDITOR
612 #include "editor\d3edit.h"
613 #endif
614
615 #include <algorithm>
616
617 // what darkening level to use when cloaked
618 #define CLOAKED_FADE_LEVEL 28
619 #define CLOAK_FADEIN_DURATION_PLAYER F2_0
620 #define CLOAK_FADEOUT_DURATION_PLAYER F2_0
621 #define CLOAK_FADEIN_DURATION_ROBOT F1_0
622 #define CLOAK_FADEOUT_DURATION_ROBOT F1_0
623 #define RO_STATIC 0
624 #define RO_GOURAUD 1
625 #define RO_LIGHTMAPS 2
626 extern uint8_t Use_motion_blur;
627 uint8_t RenderObjectType = RO_STATIC;
628 float RenderObjectStaticRedValue = 1.0f;
629 float RenderObjectStaticGreenValue = 1.0f;
630 float RenderObjectStaticBlueValue = 1.0f;
631 float RenderObjectStaticScalar = 1.0f;
632 uint8_t *RenderObjectGouraudValue = NULL;
633 lightmap_object *RenderObjectLightmapObject = NULL;
634 vector RenderObject_LightDirection;
635
636 float Last_powerup_sparkle_time = 0.0f;
637 bool Render_powerup_sparkles = false;
638 // Do powerup sparkles and stuff
639 void DrawPowerupSparkles(object *obj);
640
641 // Draws the glowing disk around a powerup
642 void DrawPowerupGlowDisk(object *obj);
643 // Draws a damage disk around a powerup
644 void DrawPlayerDamageDisk(object *obj);
645 void DrawPlayerInvulSphere(object *obj);
646 void DrawPlayerSightVector(object *obj);
647 // Draws this players name on the hud
648 void DrawPlayerNameOnHud(object *obj);
649 // Draws a rotating ball around the player
650 void DrawPlayerRotatingBall(object *obj);
651 // Creates lightning sparks on a damaged object
652 void DrawSparkyDamageLightning(object *obj);
653 // Creates Virus infected lightning on an object
654 void DrawVirusLightning(object *obj);
655
656 #ifdef EDITOR
657 // Draws the little corner brackets around the selected object
658 // Actually, only draws those either in front or in back of the object, based on front_flag
659 void DrawObjectSelectionBrackets(object *obj, bool front_flag) {
660 vector viewvec;
661 poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num];
662 float line_len;
663 // Get vector from object to viewer
664 g3_GetViewPosition(&viewvec);
665 viewvec -= obj->pos;
666 // Get length of line segments we're drawing
667 line_len = (pm->maxs.x - pm->mins.x) * 0.2f;
668 // Do each corner
669 for (int c = 0; c < 8; c++) {
670 vector corner;
671 // Get the corner relative to the object
672 corner = (obj->orient.rvec * ((c & 1) ? pm->mins.x : pm->maxs.x)) +
673 (obj->orient.uvec * ((c & 2) ? pm->mins.y : pm->maxs.y)) +
674 (obj->orient.fvec * ((c & 4) ? pm->mins.z : pm->maxs.z));
675 // See if this corner is in front or in back of the object, as specified
676 if (((corner * viewvec) > 0.0) != front_flag)
677 continue;
678 // Get absolute position in 3-space
679 corner += obj->pos;
680 // Draw line for each axis at this corner
681 for (int a = 0; a < 3; a++) {
682 g3Point pp0, pp1;
683 vector t;
684 // Grab the x,y, or z axis, and scale by the line segment length
685 t = corner + ((((vector *)&obj->orient)[a]) * ((c & (1 << a)) ? line_len : -line_len));
686 // Rotate both ends of the line
687 g3_RotatePoint(&pp0, &corner);
688 g3_RotatePoint(&pp1, &t);
689 // Draw!
690 g3_DrawLine(GR_RGB(255, 255, 255), &pp0, &pp1);
691 }
692 }
693 }
694 #endif
695 #ifdef _DEBUG
696 static float ArrayX[10][20] = {{-1, 1, 1, -1, -1},
697 {-.25, 0.0, 0.0, 0.0, -1.0, 1.0},
698 {-1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0, -1.0, 1.0},
699 {-1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -.5},
700 {-1.0, -1.0, -1.0, 1.0, 1.0, 1.0},
701 {-1.0, 1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, -1.0, 1.0},
702 {-1.0, 1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, -1.0, 1.0},
703 {-1.0, 1.0, 1.0, 1.0},
704 {-1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0, -1.0, 1.0},
705 {1.0, -1.0, -1.0, 1.0, 1.0, 1.0}};
706 static float ArrayY[10][20] = {{1, 1, -1, -1, 1},
707 {.75, 1.0, 1.0, -1.0, -1.0, -1.0},
708 {1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0},
709 {1.0, 1.0, -1.0, -1.0, -1.0, 0, 0.0},
710 {1.0, 0.0, 0.0, 0.0, 1.0, -1.0},
711 {1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0},
712 {1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0},
713 {1.0, 1.0, 1.0, -1.0},
714 {1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 0.0, 0.0},
715 {1.0, 1.0, 0.0, 0.0, 1.0, -1.0}};
716 static int NumOfPoints[] = {5, 6, 10, 7, 6, 10, 10, 4, 10, 6};
717 static void DrawNumber(int num, vector pos, float size, ddgr_color c1) {
718 g3Point basepnt, rot_pnt[20];
719 int num_array[10];
720 int i, j;
721 int total = num;
722 size /= 2;
723 if (num < 0) {
724 num *= -1;
725 num += 10000;
726 }
727 int num_numbers = (int)(log10f((float)num) + 1);
728 if (num_numbers > 10) {
729 mprintf(0, "Cannot represent a number with over 10 digits\n");
730 Int3();
731 return;
732 }
733
734 for (j = num_numbers - 1; j >= 0; j--) {
735 num_array[j] = total / ((int)powf(10.0f, (float)j));
736 total -= num_array[j] * (int)powf(10.0f, (float)j);
737 }
738 for (j = 0; j < num_numbers; j++) {
739 vector cur_pos;
740
741 if (num_numbers & 0x00000001)
742 cur_pos = pos + (2.1 * size * ((num_numbers >> 1) - j)) * Viewer_object->orient.rvec;
743 else
744 cur_pos = pos + (2.1 * size * ((num_numbers >> 1) - j) - size) * Viewer_object->orient.rvec;
745 g3_RotatePoint(&basepnt, &cur_pos);
746 for (i = 0; i < NumOfPoints[num_array[j]]; i++) {
747 rot_pnt[i] = basepnt;
748 rot_pnt[i].p3_vec.x += (ArrayX[num_array[j]][i] * size);
749 rot_pnt[i].p3_vec.y += (ArrayY[num_array[j]][i] * size);
750 rot_pnt[i].p3_flags = 0;
751 g3_CodePoint(&rot_pnt[i]);
752 g3_ProjectPoint(&rot_pnt[i]);
753 }
754 for (i = 0; i < NumOfPoints[num_array[j]] - 1; i++) {
755 g3Point p1, p2;
756 p1 = rot_pnt[i];
757 p2 = rot_pnt[i + 1];
758
759 g3_DrawLine(c1, &p1, &p2);
760 }
761 }
762 }
763 static inline bool object_object_AABB(object *obj1, object *obj2) {
764 bool overlap = true;
765 if (obj1->max_xyz.x < obj2->min_xyz.x || obj2->max_xyz.x < obj1->min_xyz.x || obj1->max_xyz.z < obj2->min_xyz.z ||
766 obj2->max_xyz.z < obj1->min_xyz.z || obj1->max_xyz.y < obj2->min_xyz.y || obj2->max_xyz.y < obj1->min_xyz.y)
767 overlap = false;
768
769 return overlap;
770 }
771 // Given a face, computes the upper left corner of the face
772 void ComputeDebugVisFaceUpperLeft(room *rp, face *fp, vector *upper_left, float *xdiff, float *ydiff, vector *center) {
773 matrix face_matrix, trans_matrix;
774 vector fvec;
775 vector avg_vert;
776 vector verts[MAX_VERTS_PER_FACE];
777 vector rot_vert;
778 int i;
779
780 // find the center point of this face
781 vm_MakeZero(&avg_vert);
782 for (i = 0; i < fp->num_verts; i++)
783 avg_vert += rp->verts[fp->face_verts[i]];
784 avg_vert /= fp->num_verts;
785 // Make the orientation matrix
786 // Reverse the normal because we're looking "at" the face, not from it
787 fvec = -fp->normal;
788
789 vm_VectorToMatrix(&face_matrix, &fvec, NULL, NULL);
790 // Make the transformation matrix
791
792 angvec avec;
793 vm_ExtractAnglesFromMatrix(&avec, &face_matrix);
794 vm_AnglesToMatrix(&trans_matrix, avec.p, avec.h, avec.b);
795
796 // Rotate all the points
797 for (i = 0; i < fp->num_verts; i++) {
798 vector vert = rp->verts[fp->face_verts[i]];
799
800 vert -= avg_vert;
801 vm_MatrixMulVector(&rot_vert, &vert, &trans_matrix);
802 verts[i] = rot_vert;
803 }
804 // Find left most point
805 int leftmost_point = -1;
806 float leftmost_x = 900000.00f; // a big number
807 for (i = 0; i < fp->num_verts; i++) {
808 if (verts[i].x < leftmost_x) {
809 leftmost_point = i;
810 leftmost_x = verts[i].x;
811 }
812 }
813 ASSERT(leftmost_point != -1);
814 // Find top most point
815 int topmost_point = -1;
816 float topmost_y = -900000.0f; // a big number
817 for (i = 0; i < fp->num_verts; i++) {
818 if (verts[i].y > topmost_y) {
819 topmost_point = i;
820 topmost_y = verts[i].y;
821 }
822 }
823 ASSERT(topmost_point != -1);
824 // Find right most point
825 int rightmost_point = -1;
826 float rightmost_x = -900000.00f; // a big number
827 for (i = 0; i < fp->num_verts; i++) {
828 if (verts[i].x > rightmost_x) {
829 rightmost_point = i;
830 rightmost_x = verts[i].x;
831 }
832 }
833 ASSERT(rightmost_point != -1);
834 // Find bottom most point
835 int bottommost_point = -1;
836 float bottommost_y = 900000.0f; // a big number
837 for (i = 0; i < fp->num_verts; i++) {
838 if (verts[i].y < bottommost_y) {
839 bottommost_point = i;
840 bottommost_y = verts[i].y;
841 }
842 }
843 ASSERT(bottommost_point != -1);
844 // now set the base vertex, which is where we base uv 0,0 on
845 vector base_vector;
846 base_vector.x = verts[leftmost_point].x;
847 base_vector.y = verts[topmost_point].y;
848 base_vector.z = 0;
849 // Figure out grid resolution
850 *xdiff = verts[rightmost_point].x - verts[leftmost_point].x;
851 *ydiff = verts[topmost_point].y - verts[bottommost_point].y;
852
853 // Find upper left corner
854 vm_TransposeMatrix(&trans_matrix);
855 vm_MatrixMulVector(&rot_vert, &base_vector, &trans_matrix);
856 *upper_left = rot_vert + avg_vert;
857 *center = avg_vert;
858 }
859
860 #define VIS_TABLE_RESOLUTION 6
861 void DrawRoomVisPnts(object *obj) {
862 int roomnum = obj->roomnum;
863 if ((!ROOMNUM_OUTSIDE(roomnum)) && (roomnum != -1) && (Rooms[roomnum].used)) {
864 room *rp = &Rooms[roomnum];
865 int t;
866 int j;
867 for (t = 0; t < rp->num_portals; t++) {
868 face *src_fp = &rp->faces[rp->portals[t].portal_face];
869 float src_width, src_height;
870 vector src_upper_left, src_center;
871 matrix src_matrix;
872 vector src_verts[MAX_VERTS_PER_FACE], *src_vertp[MAX_VERTS_PER_FACE];
873 for (j = 0; j < src_fp->num_verts; j++) {
874 src_verts[j] = rp->verts[src_fp->face_verts[j]];
875 src_vertp[j] = &src_verts[j];
876 }
877 vector fvec = -src_fp->normal;
878 vm_VectorToMatrix(&src_matrix, &fvec, NULL, NULL);
879 ComputeDebugVisFaceUpperLeft(rp, src_fp, &src_upper_left, &src_width, &src_height, &src_center);
880
881 if (src_width > VIS_TABLE_RESOLUTION) {
882 float num = src_width / VIS_TABLE_RESOLUTION;
883 src_width = VIS_TABLE_RESOLUTION;
884 src_upper_left += (src_matrix.rvec * (num / 2));
885 src_matrix.rvec *= num;
886 }
887 if (src_height > VIS_TABLE_RESOLUTION) {
888 float num = src_height / VIS_TABLE_RESOLUTION;
889 src_height = VIS_TABLE_RESOLUTION;
890 src_upper_left -= (src_matrix.uvec * (num / 2));
891 src_matrix.uvec *= num;
892 }
893 vector src_vector, src_ybase;
894 src_ybase = src_upper_left;
895 for (int sy = 0; sy < src_height; sy++, src_ybase -= src_matrix.uvec) {
896 src_vector = src_ybase;
897 for (int sx = 0; sx < src_width; sx++, src_vector += src_matrix.rvec) {
898 vector src2 = src_vector;
899 // vector subvec=src_center-src_vector;
900 // float mag=vm_GetMagnitudeFast (&subvec);
901 // subvec/=(mag*4);
902 // src2+=subvec;
903 if ((check_point_to_face(&src2, &src_fp->normal, src_fp->num_verts, src_vertp))) {
904 DrawColoredDisk(&src2, 1.0f, 0.0f, 0.0f, .1f, .7f, 0.25f, 1);
905 continue;
906 }
907
908 src2 += 0.1f * rp->faces[rp->portals[t].portal_face].normal;
909 if (!fvi_QuickRoomCheck(&src2, rp, false) && !fvi_QuickRoomCheck(&src2, rp, true)) {
910 DrawColoredDisk(&src2, 0.0f, 1.0f, 0.0f, .1f, .7f, 0.25f, 1);
911 continue;
912 }
913 DrawColoredDisk(&src2, 0.0f, 0.0f, 1.0f, .1f, .7f, 0.25f, 1);
914 }
915 }
916 }
917 }
918 }
919 void DrawDebugInfo(object *obj) {
920 matrix m;
921 m = obj->orient;
922 vm_TransposeMatrix(&m);
923 if (obj->type == OBJ_ROOM) {
924 DrawColoredDisk(&obj->pos, 0.0f, 0.0f, 1.0f, .1f, .7f, obj->size, 1);
925 } else {
926 if (Game_show_sphere == 1) {
927 vector center = obj->pos + Poly_models[obj->rtype.pobj_info.model_num].wall_size_offset * m;
928 DrawColoredDisk(&center, 0.0f, 0.0f, 1.0f, .1f, .7f, Poly_models[obj->rtype.pobj_info.model_num].wall_size, 1);
929 } else if (Game_show_sphere == 2) {
930 vector center = obj->pos + Poly_models[obj->rtype.pobj_info.model_num].anim_size_offset * m;
931 DrawColoredDisk(&center, 0.0f, 0.1f, .9f, .1f, .7f, Poly_models[obj->rtype.pobj_info.model_num].anim_size, 1);
932 } else if (Game_show_sphere == 3) {
933 DrawColoredDisk(&obj->pos, 0.1f, 0.2f, .9f, .1f, .7f, obj->size, 1);
934 }
935 }
936 g3Point g3p[8];
937 memset(g3p, 0, 8 * sizeof(g3Point));
938 vector pos[9];
939 // g3p[0].p3_vec = obj->pos;
940 // g3p[1].p3_vec = obj->rtype.line_info.end_pos;
941
942 ddgr_color c1;
943 if (!object_object_AABB(obj, Player_object))
944 c1 = GR_RGB(255, 0, 0);
945 else
946 c1 = GR_RGB(255, 255, 255);
947 pos[0] = obj->max_xyz;
948 pos[1] = obj->max_xyz;
949 pos[1].z = obj->min_xyz.z;
950 pos[2] = obj->min_xyz;
951 pos[2].y = obj->max_xyz.y;
952 pos[3] = obj->max_xyz;
953 pos[3].x = obj->min_xyz.x;
954 pos[4] = obj->max_xyz;
955 pos[4].y = obj->min_xyz.y;
956 pos[5] = obj->min_xyz;
957 pos[5].x = obj->max_xyz.x;
958 pos[6] = obj->min_xyz;
959 pos[7] = obj->min_xyz;
960 pos[7].z = obj->max_xyz.z;
961
962 pos[8] = obj->pos;
963 pos[8].y += .8f * obj->size;
964 g3_RotatePoint(&g3p[0], &pos[0]);
965 g3_RotatePoint(&g3p[1], &pos[1]);
966 g3_RotatePoint(&g3p[2], &pos[2]);
967 g3_RotatePoint(&g3p[3], &pos[3]);
968 g3_RotatePoint(&g3p[4], &pos[4]);
969 g3_RotatePoint(&g3p[5], &pos[5]);
970 g3_RotatePoint(&g3p[6], &pos[6]);
971 g3_RotatePoint(&g3p[7], &pos[7]);
972 g3_DrawLine(c1, &g3p[0], &g3p[1]);
973 g3_DrawLine(c1, &g3p[1], &g3p[2]);
974 g3_DrawLine(c1, &g3p[2], &g3p[3]);
975 g3_DrawLine(c1, &g3p[3], &g3p[0]);
976 g3_DrawLine(c1, &g3p[0], &g3p[4]);
977 g3_DrawLine(c1, &g3p[1], &g3p[5]);
978 g3_DrawLine(c1, &g3p[2], &g3p[6]);
979 g3_DrawLine(c1, &g3p[3], &g3p[7]);
980 g3_DrawLine(c1, &g3p[4], &g3p[5]);
981 g3_DrawLine(c1, &g3p[5], &g3p[6]);
982 g3_DrawLine(c1, &g3p[6], &g3p[7]);
983 g3_DrawLine(c1, &g3p[7], &g3p[4]);
984 DrawNumber(OBJNUM(obj), obj->pos, 1.0, GR_RGB(255, 255, 255));
985
986 if (!OBJECT_OUTSIDE(obj)) {
987 if (obj->roomnum != Player_object->roomnum)
988 c1 = GR_RGB(255, 0, 0);
989 else
990 c1 = GR_RGB(255, 255, 255);
991 DrawNumber(obj->roomnum, obj->max_xyz, 0.50, c1);
992 }
993 }
994 #endif
995 // Draw a shard
996 void DrawShardObject(object *obj) {
997 shard_info_s *si = &obj->rtype.shard_info;
998 bool flip = 0;
999 g3Point rotated_points[3];
1000 g3Point *pointlist[3];
1001 uint8_t codes_and = 0xff;
1002 g3_StartInstanceMatrix(&obj->pos, &obj->orient);
1003 // Build list of points and UVLs for this face
1004 for (int i = 0; i < 3; i++) {
1005 uint8_t c;
1006 g3Point *p = &rotated_points[i];
1007 c = g3_RotatePoint(p, &si->points[i]);
1008 codes_and &= c;
1009 p->p3_uvl.u = si->u[i];
1010 p->p3_uvl.v = si->v[i];
1011 p->p3_uvl.a = 1.0; // GameTextures[si->tmap].alpha;
1012 p->p3_flags |= PF_UV; // + PF_L; // + PF_UV2 + PF_RGBA; //has uv and l set
1013 p->p3_uvl.l = 1.0;
1014 pointlist[i] = &rotated_points[i];
1015 }
1016 // Check for backside
1017 if (!g3_CheckNormalFacing(&obj->pos, &si->normal)) {
1018 g3Point *t = pointlist[1];
1019 pointlist[1] = pointlist[2];
1020 pointlist[2] = t;
1021 }
1022 // Done with 3D
1023 g3_DoneInstance();
1024 // Check if face off screen
1025 if (codes_and)
1026 return;
1027 // Get bitmap handle
1028 int bm_handle = GetTextureBitmap(si->tmap, 0);
1029 ASSERT(bm_handle != -1);
1030 float alpha = GameTextures[si->tmap].alpha;
1031 alpha = 0.2 + alpha * 0.8; // Make less transparent
1032 // Set alpha, transparency, & lighting for this face
1033 rend_SetAlphaType(ATF_CONSTANT);
1034 rend_SetAlphaValue(alpha * 255);
1035 rend_SetLighting(LS_GOURAUD);
1036 rend_SetColorModel(CM_MONO);
1037 rend_SetOverlayType(OT_NONE);
1038 // Select texture type
1039 rend_SetTextureType(TT_LINEAR);
1040 // Draw the polygon
1041 g3_DrawPoly(3, pointlist, bm_handle);
1042 }
1043 // Sets up the light states for an outdoor object to be rendered
1044 bool SetupTerrainObject(object *obj) {
1045 vector camlight = Terrain_sky.lightsource;
1046 vm_NormalizeVector(&camlight);
1047 #ifdef EDITOR
1048 if (!Terrain_render_ext_room_objs)
1049 return false;
1050 #endif
1051
1052 obj->flags |= OF_SAFE_TO_RENDER;
1053 RenderObject_SetLightDirection(&camlight);
1054 rend_SetColorModel(CM_MONO);
1055 if (obj->render_type == RT_POLYOBJ ||
1056 (obj->render_type == RT_WEAPON &&
1057 !((Weapons[obj->id].flags & WF_IMAGE_BITMAP) || (Weapons[obj->id].flags & WF_IMAGE_VCLIP)))) {
1058 float scalar_r, scalar_g, scalar_b, scalar;
1059 if (obj->type == OBJ_POWERUP) {
1060 scalar = 1.0;
1061 scalar_r = 1.0;
1062 scalar_g = 1.0;
1063 scalar_b = 1.0;
1064 } else {
1065 scalar = GetTerrainDynamicScalar(&obj->pos, CELLNUM(obj->roomnum));
1066 if (obj->effect_info && (obj->effect_info->type_flags & EF_VOLUME_LIT)) {
1067 scalar_r = std::min<float>(1, scalar + (obj->effect_info->dynamic_red));
1068 scalar_g = std::min<float>(1, scalar + (obj->effect_info->dynamic_green));
1069 scalar_b = std::min<float>(1, scalar + (obj->effect_info->dynamic_blue));
1070 // If this is a robot, make it at least 10% for each RGB component
1071 if (obj->type == OBJ_ROBOT) {
1072 scalar_r = std::max<float>(.1, scalar_r);
1073 scalar_g = std::max<float>(.1, scalar_g);
1074 scalar_b = std::max<float>(.1, scalar_b);
1075 }
1076 if (obj->type == OBJ_PLAYER && ((Players[obj->id].flags & PLAYER_FLAGS_HEADLIGHT) ||
1077 ((Game_mode & GM_MULTI) && (Netgame.flags & NF_BRIGHT_PLAYERS)))) {
1078 scalar_r = 1;
1079 scalar_g = 1;
1080 scalar_b = 1;
1081 }
1082 } else {
1083 scalar_r = scalar;
1084 scalar_g = scalar;
1085 scalar_b = scalar;
1086 }
1087 }
1088
1089 if (obj->lighting_render_type == LRT_STATIC || Poly_models[obj->rtype.pobj_info.model_num].new_style == 0)
1090 RenderObject_SetStatic(scalar_r, scalar_g, scalar_b);
1091 else if (obj->lighting_render_type == LRT_GOURAUD || NoLightmaps) {
1092 vector lightdir = {0, -1.0, 0}; // straight down for now
1093 RenderObject_SetGouraud(&lightdir, scalar_r, scalar_g, scalar_b, scalar);
1094 } else if (obj->lighting_render_type == LRT_LIGHTMAPS) {
1095 if (obj->lm_object.used == 0)
1096 RenderObject_SetStatic(scalar_r, scalar_g, scalar_b);
1097 else
1098 RenderObject_SetLightmaps(&obj->lm_object);
1099 }
1100 } else {
1101 RenderObject_SetStatic(1, 1, 1);
1102 }
1103 return true;
1104 }
1105 // Sets up the light states for an indoor object to be rendered
1106 bool SetupMineObject(object *objp) {
1107 if (objp->lighting_render_type == LRT_STATIC || Poly_models[objp->rtype.pobj_info.model_num].new_style == 0) {
1108 RenderObject_SetStatic(1.0f, 1.0f, 1.0f);
1109 } else if (objp->lighting_render_type == LRT_GOURAUD || NoLightmaps) {
1110 float scalar_r = 1.0, scalar_g = 1.0, scalar_b = 1.0;
1111
1112 vector lightdir = {0, -1.0, 0}; // straight down for now
1113
1114 // Get the volume light for this object
1115 if (objp->effect_info && (objp->effect_info->type_flags & EF_VOLUME_LIT) &&
1116 !(Rooms[objp->roomnum].flags & RF_EXTERNAL)) {
1117 vector vpos = objp->pos;
1118 if (Render_mirror_for_room)
1119 vpos = objp->last_pos;
1120 if (objp->effect_info->type_flags & EF_VOLUME_CHANGING) {
1121 float old_r, old_g, old_b;
1122 float new_r, new_g, new_b;
1123 GetRoomDynamicScalar(&objp->effect_info->volume_old_pos, &Rooms[objp->effect_info->volume_old_room], &old_r,
1124 &old_g, &old_b);
1125 GetRoomDynamicScalar(&vpos, &Rooms[objp->roomnum], &new_r, &new_g, &new_b);
1126 scalar_r =
1127 (old_r * objp->effect_info->volume_change_time) + ((1 - objp->effect_info->volume_change_time) * new_r);
1128 scalar_g =
1129 (old_g * objp->effect_info->volume_change_time) + ((1 - objp->effect_info->volume_change_time) * new_g);
1130 scalar_b =
1131 (old_b * objp->effect_info->volume_change_time) + ((1 - objp->effect_info->volume_change_time) * new_b);
1132 } else
1133 GetRoomDynamicScalar(&vpos, &Rooms[objp->roomnum], &scalar_r, &scalar_g, &scalar_b);
1134
1135 scalar_r = std::min<float>(1, scalar_r + (objp->effect_info->dynamic_red));
1136 scalar_g = std::min<float>(1, scalar_g + (objp->effect_info->dynamic_green));
1137 scalar_b = std::min<float>(1, scalar_b + (objp->effect_info->dynamic_blue));
1138 // If this is a robot, make it at least 10% for each RGB component
1139 if (objp->type == OBJ_ROBOT) {
1140 scalar_r = std::max<float>(.1, scalar_r);
1141 scalar_g = std::max<float>(.1, scalar_g);
1142 scalar_b = std::max<float>(.1, scalar_b);
1143 }
1144
1145 if (objp->type == OBJ_PLAYER && (Game_mode & GM_MULTI)) {
1146 if (Netgame.flags & NF_BRIGHT_PLAYERS) {
1147 scalar_r = 1;
1148 scalar_g = 1;
1149 scalar_b = 1;
1150 } else {
1151 // Make this ship brighter based on its speed
1152 float speed_norm;
1153 speed_norm = std::min<float>(vm_GetMagnitudeFast(&objp->mtype.phys_info.velocity) / 20.0, 1);
1154 speed_norm *= 1;
1155 speed_norm += 1;
1156 scalar_r = std::min<float>(1, scalar_r * speed_norm);
1157 scalar_g = std::min<float>(1, scalar_g * speed_norm);
1158 scalar_b = std::min<float>(1, scalar_b * speed_norm);
1159 }
1160 }
1161 if (objp->type == OBJ_PLAYER && (Players[objp->id].flags & PLAYER_FLAGS_HEADLIGHT)) {
1162 scalar_r = 1;
1163 scalar_g = 1;
1164 scalar_b = 1;
1165 }
1166 }
1167 RenderObject_SetGouraud(&lightdir, scalar_r, scalar_g, scalar_b);
1168 } else if (objp->lighting_render_type == LRT_LIGHTMAPS) {
1169 if (objp->lm_object.used == 0)
1170 RenderObject_SetStatic(1.0f, 1.0f, 1.0f);
1171 else
1172 RenderObject_SetLightmaps(&objp->lm_object);
1173 }
1174 return true;
1175 }
1176
1177 bool GetLinearPosition(vector *points, float *times, int num_points, float t, vector *pos) {
1178 // find between which points is the time
1179 int min_point;
1180 for (min_point = 0; min_point < num_points - 1; min_point++) {
1181 if (times[min_point] <= t && t <= times[min_point + 1]) {
1182 break;
1183 }
1184 }
1185 if (min_point == (num_points - 1))
1186 return false;
1187 ASSERT(times[min_point] <= t && t <= times[min_point + 1]);
1188
1189 t -= times[min_point];
1190 float d = times[min_point + 1] - times[min_point];
1191 float newt = t / d;
1192
1193 vector vd;
1194 float mag;
1195 vd = points[min_point + 1] - points[min_point];
1196 mag = vm_GetMagnitude(&vd);
1197 vm_NormalizeVector(&vd);
1198 vd *= (mag * newt);
1199
1200 *pos = points[min_point] + vd;
1201 return true;
1202 }
1203
1204 // -----------------------------------------------------------------------------
1205 // Render an object. Calls one of several routines based on type
1206 void RenderObject(object *obj) {
1207 float normalized_time[MAX_SUBOBJECTS];
1208 bool render_it = false;
1209 if (obj->type == OBJ_NONE) {
1210 mprintf(1, "ERROR!!!! Bogus obj %d in room %d is rendering!\n", OBJNUM(obj), obj->roomnum);
1211 Int3();
1212 return;
1213 }
1214 if (obj->type == OBJ_DUMMY)
1215 return;
1216 if (obj->flags & OF_ATTACHED) {
1217 // See if we should be rendered, because our attach parent might be invisible
1218 object *parent_obj = ObjGet(obj->attach_ultimate_handle);
1219 if (!parent_obj)
1220 return;
1221 if (parent_obj->render_type == RT_NONE && parent_obj->type != OBJ_POWERUP &&
1222 (parent_obj->type == OBJ_PLAYER || parent_obj->movement_type != MT_NONE))
1223 return;
1224 }
1225 if (OBJECT_OUTSIDE(obj))
1226 render_it = SetupTerrainObject(obj);
1227 else
1228 render_it = SetupMineObject(obj);
1229 if (!render_it)
1230 return;
1231 if (!(obj->flags & OF_SAFE_TO_RENDER))
1232 return;
1233 // Mark this a rendered this frame
1234 obj->flags |= OF_RENDERED;
1235 // If we're not rendering from a mirror, mark this object as rendered
1236 if (Render_mirror_for_room == false)
1237 obj->flags &= ~OF_SAFE_TO_RENDER;
1238 obj->renderframe = FrameCount % 65536;
1239 if (obj->control_type == CT_AI && (GetFunctionMode() == GAME_MODE || GetFunctionMode() == EDITOR_GAME_MODE)) {
1240 AI_RenderedList[AI_NumRendered] = OBJNUM(obj);
1241 AI_NumRendered += 1;
1242 }
1243 #ifdef EDITOR
1244 ddgr_color oldcolor;
1245 if (TSearch_on && obj->type != OBJ_ROOM) {
1246 rend_SetPixel(GR_RGB(16, 255, 64), TSearch_x, TSearch_y);
1247 oldcolor = rend_GetPixel(TSearch_x, TSearch_y); // will be different in 15/16-bit color
1248 }
1249 #endif
1250 switch (obj->render_type) {
1251 case RT_NONE:
1252 break;
1253 case RT_EDITOR_SPHERE: // to render objects in editor mode
1254 #ifdef EDITOR
1255 if ((GetFunctionMode() == EDITOR_MODE)) { // only render if in editor mode
1256 if (!UseHardware) {
1257 g3Point sphere_point;
1258 g3_RotatePoint(&sphere_point, &obj->pos);
1259 g3_DrawSphere(obj->rtype.sphere_color, &sphere_point, obj->size);
1260 } else {
1261 // Let me take this opportunity to say how much it pisses me off that
1262 // the DrawColoredDisk() function takes r,g,b as floats, when the standard
1263 // in our graphics system is to pass color as a ddgr_color
1264 float r = (float)GR_COLOR_RED(obj->rtype.sphere_color) / 255.0,
1265 g = (float)GR_COLOR_GREEN(obj->rtype.sphere_color) / 255.0,
1266 b = (float)GR_COLOR_BLUE(obj->rtype.sphere_color) / 255.0;
1267 DrawColoredDisk(&obj->pos, r, g, b, 1, 1, obj->size, 0);
1268 }
1269 }
1270 #endif
1271 break;
1272 case RT_POLYOBJ:
1273 #ifdef EDITOR
1274 if ((GetFunctionMode() == EDITOR_MODE) && (obj - Objects == Cur_object_index))
1275 DrawObjectSelectionBrackets(obj, 0); // draw back brackets
1276 #endif
1277 if (obj->rtype.pobj_info.anim_frame || (Poly_models[obj->rtype.pobj_info.model_num].frame_max !=
1278 Poly_models[obj->rtype.pobj_info.model_num].frame_min)) {
1279 SetNormalizedTimeObj(obj, normalized_time);
1280 RenderObject_DrawPolymodel(obj, normalized_time);
1281 } else {
1282 RenderObject_DrawPolymodel(obj, NULL);
1283 }
1284
1285 ////////////////////////////////////////////
1286 /////////////MOTION BLUR////////////////////
1287 if (Use_motion_blur && (obj->type == OBJ_ROBOT || obj->type == OBJ_DEBRIS) &&
1288 Object_map_position_history[OBJNUM(obj)] != -1) {
1289 float vel_mag; // velocity magnitude
1290 float sphere_size_perc = 0.20f; // percentage of object size
1291 float AFT = 1.0f / 20.0f; // Assumed frame time
1292 int num_iterations; // number of iterations
1293
1294 vel_mag = fabs(vm_GetMagnitude(&obj->mtype.phys_info.velocity));
1295 num_iterations = (vel_mag * AFT) / (sphere_size_perc * obj->size);
1296
1297 if (num_iterations > 12)
1298 num_iterations = 12;
1299
1300 if (num_iterations >= 1) {
1301 vector saved_pos;
1302 float saved_alpha_fac;
1303 vector positions[MAX_POSITION_HISTORY + 1];
1304 float times[MAX_POSITION_HISTORY + 1];
1305
1306 // save the position of the object, because we'll have to restore it
1307 saved_pos = obj->pos;
1308 saved_alpha_fac = rend_GetAlphaFactor();
1309
1310 int pos_slot = Object_map_position_history[OBJNUM(obj)];
1311 int i, c_pos = Object_position_head;
1312
1313 // fill in the positions, starting with our current one
1314 for (i = 0; i < MAX_POSITION_HISTORY + 1; i++) {
1315 if (i == 0) {
1316 positions[i] = obj->pos;
1317 times[i] = 0;
1318 } else {
1319 positions[i] = Object_position_samples[pos_slot].pos[c_pos];
1320 times[i] = Gametime - Last_position_history_update[c_pos];
1321 c_pos++;
1322 c_pos = c_pos % MAX_POSITION_HISTORY;
1323 }
1324 }
1325
1326 float t_interval; // time interval
1327 float alpha_step; // opacity stepping
1328 float total_time; // total time of samples
1329
1330 t_interval = AFT / ((float)num_iterations + 1);
1331 alpha_step = 1.0f / (num_iterations + 1);
1332 total_time = times[MAX_POSITION_HISTORY] - times[0];
1333 ASSERT(total_time > 0);
1334
1335 float curr_alpha = 1.0f - alpha_step;
1336 float curr_t = t_interval;
1337 float full_time = AFT / total_time; // how much of the interval we want to go across
1338
1339 for (i = 0; i < num_iterations; i++) {
1340 if (!GetLinearPosition(positions, times, MAX_POSITION_HISTORY + 1, curr_t, &obj->pos))
1341 break;
1342
1343 rend_SetAlphaFactor(curr_alpha);
1344
1345 // render the iteration
1346 if (obj->rtype.pobj_info.anim_frame || (Poly_models[obj->rtype.pobj_info.model_num].frame_max !=
1347 Poly_models[obj->rtype.pobj_info.model_num].frame_min)) {
1348 RenderObject_DrawPolymodel(obj, normalized_time);
1349 } else {
1350 RenderObject_DrawPolymodel(obj, NULL);
1351 }
1352
1353 // update
1354 curr_alpha -= alpha_step;
1355 curr_t += t_interval;
1356 }
1357
1358 obj->pos = saved_pos;
1359 rend_SetAlphaFactor(saved_alpha_fac);
1360 }
1361 }
1362 ////////////////////////////////////////////
1363
1364 #ifdef _DEBUG
1365 if (Game_show_sphere) {
1366 DrawDebugInfo(obj);
1367 }
1368 #endif
1369
1370 // Render that powerup glow
1371 if (obj->type == OBJ_POWERUP) {
1372 DrawPowerupGlowDisk(obj);
1373 DrawPowerupSparkles(obj);
1374 }
1375
1376 if (obj->type == OBJ_PLAYER) {
1377 DrawPlayerDamageDisk(obj);
1378 DrawPlayerRotatingBall(obj);
1379 DrawPlayerNameOnHud(obj);
1380 DrawPlayerTypingIndicator(obj);
1381 DrawPlayerInvulSphere(obj);
1382 }
1383 if (obj->type == OBJ_PLAYER || obj->type == OBJ_ROBOT || (obj->type == OBJ_BUILDING && obj->ai_info)) {
1384 DrawSparkyDamageLightning(obj);
1385 DrawVirusLightning(obj);
1386 }
1387
1388 break;
1389 case RT_FIREBALL:
1390 DrawFireballObject(obj);
1391 break;
1392 case RT_WEAPON:
1393 DrawWeaponObject(obj);
1394
1395 #ifdef _DEBUG
1396 if (Game_show_sphere) {
1397 DrawDebugInfo(obj);
1398 }
1399 #endif
1400 break;
1401 case RT_SPLINTER:
1402 DrawSplinterObject(obj);
1403 break;
1404 case RT_SHARD:
1405 DrawShardObject(obj);
1406 break;
1407 #ifdef _DEBUG
1408 case RT_LINE: {
1409 g3Point g3p[2];
1410 memset(g3p, 0, 2 * sizeof(g3Point));
1411 // g3p[0].p3_vec = obj->pos;
1412 // g3p[1].p3_vec = obj->rtype.line_info.end_pos;
1413
1414 g3_RotatePoint(&g3p[0], &obj->pos);
1415 g3_RotatePoint(&g3p[1], &obj->rtype.line_info.end_pos);
1416 g3_DrawLine(GR_RGB(255, 255, 255), &g3p[0], &g3p[1]);
1417 break;
1418 }
1419 #endif
1420 default:
1421 Error("Unknown render_type <%d>", obj->render_type);
1422 }
1423 #ifdef NEWDEMO
1424 if (obj->render_type != RT_NONE)
1425 if (Newdemo_state == ND_STATE_RECORDING) {
1426 if (!WasRecorded[obj - Objects]) {
1427 newdemo_record_RenderObject(obj);
1428 WasRecorded[obj - Objects] = 1;
1429 }
1430 }
1431 #endif
1432 //?? Max_linear_depth = mld_save;
1433 // Mark selected objects
1434 #ifdef EDITOR
1435 if ((GetFunctionMode() == EDITOR_MODE) && (obj - Objects == Cur_object_index)) {
1436 if (obj->render_type != RT_POLYOBJ) {
1437 g3Point pnt;
1438 g3_RotatePoint(&pnt, &obj->pos);
1439 g3_DrawBox(GR_RGB(255, 255, 255), &pnt, obj->size);
1440 } else { // polygon model
1441 DrawObjectSelectionBrackets(obj, 1); // draw front brackets
1442 }
1443 }
1444 #endif // ifdef EDITOR
1445 #ifdef EDITOR
1446 if (TSearch_on) {
1447 if (rend_GetPixel(TSearch_x, TSearch_y) != oldcolor) {
1448 TSearch_found_type = TSEARCH_FOUND_OBJECT;
1449 TSearch_seg = obj - Objects;
1450 mprintf(0, "TR:objnum=%d\n", obj - Objects);
1451 }
1452 }
1453 #endif
1454 }
1455 // Sets the polygon render object type to static (one lightval for whole object)
1456 void RenderObject_SetStatic(float r, float g, float b) {
1457 RenderObjectType = RO_STATIC;
1458 RenderObjectStaticRedValue = r;
1459 RenderObjectStaticGreenValue = g;
1460 RenderObjectStaticBlueValue = b;
1461 RenderObjectStaticScalar = 1.0;
1462 }
1463 // Sets the polygon render object type to gouraud (one lightval for each vertex)
1464 void RenderObject_SetGouraud(vector *dir, float r, float g, float b, float scalar) {
1465 RenderObject_LightDirection = *dir;
1466 RenderObjectStaticRedValue = r;
1467 RenderObjectStaticGreenValue = g;
1468 RenderObjectStaticBlueValue = b;
1469 RenderObjectStaticScalar = scalar;
1470 RenderObjectType = RO_GOURAUD;
1471 }
1472 // Sets the object render to draw a polymodel with lightmaps applied
1473 void RenderObject_SetLightmaps(lightmap_object *lmobject) {
1474 ASSERT(lmobject->used);
1475 RenderObjectType = RO_LIGHTMAPS;
1476 RenderObjectLightmapObject = lmobject;
1477 }
1478
1479 ddgr_color Player_colors[] = {
1480 GR_RGB(255, 0, 0), GR_RGB(0, 32, 255), GR_RGB(0, 255, 0), GR_RGB(255, 255, 0), GR_RGB(32, 64, 96),
1481 GR_RGB(255, 0, 255), GR_RGB(255, 128, 0), GR_RGB(128, 128, 0), GR_RGB(0, 128, 0), GR_RGB(0, 32, 128),
1482 GR_RGB(0, 128, 128), GR_RGB(128, 0, 128), GR_RGB(128, 0, 0), GR_RGB(128, 128, 255), GR_RGB(255, 128, 255),
1483 GR_RGB(255, 128, 128), GR_RGB(128, 64, 0), GR_RGB(128, 0, 255), GR_RGB(0, 255, 128), GR_RGB(255, 64, 0),
1484 GR_RGB(128, 255, 0), GR_RGB(255, 0, 128), GR_RGB(64, 64, 128), GR_RGB(128, 64, 64), GR_RGB(255, 192, 128),
1485 GR_RGB(255, 255, 128), GR_RGB(128, 128, 64), GR_RGB(64, 128, 64), GR_RGB(128, 0, 64), GR_RGB(255, 192, 0),
1486 GR_RGB(255, 255, 255), GR_RGB(128, 128, 128)};
1487
1488 bool is_multi_demo = false;
1489
1490 // Actually draws a polygon model based on the light parameters set by the above
1491 // functions
1492 void RenderObject_DrawPolymodel(object *obj, float *normalized_times) {
1493 int model_num;
1494 int use_effect = 0;
1495 vector obj_pos = obj->pos;
1496 polymodel_effect pe = {0};
1497
1498 // Do cloak effect on player
1499 if (UseHardware) {
1500 if (obj->effect_info && (obj->effect_info->type_flags & EF_FADING_OUT)) {
1501 pe.type = PEF_ALPHA;
1502 pe.alpha = .08 + (.92 * (obj->effect_info->fade_time / obj->effect_info->fade_max_time));
1503 use_effect = 1;
1504 }
1505 if (obj->effect_info && (obj->effect_info->type_flags & EF_FADING_IN)) {
1506 pe.type = PEF_ALPHA;
1507 pe.alpha = .08 + (.92 * (1.0 - (obj->effect_info->fade_time / obj->effect_info->fade_max_time)));
1508 use_effect = 1;
1509 }
1510 if (obj->effect_info && (obj->effect_info->type_flags & EF_CLOAKED)) {
1511 pe.type = PEF_ALPHA | PEF_DEFORM;
1512 pe.alpha = .13f;
1513 pe.deform_range = .1f;
1514
1515 use_effect = 1;
1516 }
1517 if (obj->type == OBJ_PLAYER) {
1518 // Draw thrust/afterburner cooler
1519 pe.type |= PEF_GLOW_SCALAR;
1520 pe.glow_length_scalar = (Players[obj->id].thrust_mag);
1521 pe.glow_size_scalar = (Players[obj->id].thrust_mag);
1522
1523 pe.glow_length_scalar += (Players[obj->id].afterburner_mag * 3);
1524 pe.glow_size_scalar += (Players[obj->id].afterburner_mag * .5);
1525 float adjustment = (ps_rand() % 100 - 50);
1526 adjustment /= 50.0;
1527 pe.glow_length_scalar += (.2 * adjustment);
1528
1529 use_effect = 1;
1530 // Make Katmai glows longer
1531 if (Katmai) {
1532 pe.glow_length_scalar *= 1.5;
1533 }
1534 // hack to make multiplayer demos work!
1535 if (is_multi_demo || (Game_mode & GM_MULTI)) {
1536 if (Num_teams > 1) {
1537 int teamnum = PlayerGetTeam(obj->id);
1538
1539 pe.type |= PEF_CUSTOM_COLOR | PEF_CUSTOM_GLOW;
1540 pe.custom_color = Player_colors[teamnum];
1541 pe.glow_r = GR_COLOR_RED(pe.custom_color) / 255.0;
1542 pe.glow_g = GR_COLOR_GREEN(pe.custom_color) / 255.0;
1543 pe.glow_b = GR_COLOR_BLUE(pe.custom_color) / 255.0;
1544
1545 use_effect = 1;
1546 } else {
1547 pe.type |= PEF_CUSTOM_COLOR;
1548 pe.custom_color = Player_colors[obj->id];
1549
1550 use_effect = 1;
1551 }
1552 if (Multi_logo_state && GameTextures[Players[obj->id].custom_texture_handle].bm_handle != 0) {
1553 pe.type |= PEF_CUSTOM_TEXTURE;
1554
1555 pe.custom_texture = Players[obj->id].custom_texture_handle;
1556
1557 use_effect = 1;
1558 }
1559 }
1560 }
1561 // Deform this object if needed
1562 if (obj->effect_info && (obj->effect_info->type_flags & EF_DEFORM)) {
1563 pe.type |= PEF_DEFORM;
1564 pe.deform_range = obj->effect_info->deform_range * obj->effect_info->deform_time;
1565 float val = obj->effect_info->deform_time;
1566 if (val > 1)
1567 val = 1;
1568
1569 pe.type |= PEF_COLOR;
1570 pe.r = 1.0;
1571 pe.g = 1 - (val / 2);
1572 pe.b = 1 - (val / 2);
1573
1574 use_effect = 1;
1575 }
1576 // If the viewer is deformed, warp his view somewhat
1577 if (Viewer_object->effect_info && (Viewer_object->effect_info->type_flags & EF_DEFORM)) {
1578 pe.type |= PEF_DEFORM;
1579 pe.deform_range = Viewer_object->effect_info->deform_range * Viewer_object->effect_info->deform_time;
1580 float val = Viewer_object->effect_info->deform_time;
1581 if (val > 1)
1582 val = 1;
1583
1584 use_effect = 1;
1585 // switch object position a little
1586 float moveval = 10.0 * val * Viewer_object->effect_info->deform_range;
1587 obj_pos.x += (((ps_rand() % 1000) - 500) / 500.0) * moveval;
1588 obj_pos.y += (((ps_rand() % 1000) - 500) / 500.0) * moveval;
1589 obj_pos.z += (((ps_rand() % 1000) - 500) / 500.0) * moveval;
1590 }
1591 // If this is a powerup, fade it out near the end of its life
1592 if (obj->type == OBJ_POWERUP && (obj->flags & OF_USES_LIFELEFT) && obj->lifeleft < 5) {
1593 pe.type |= PEF_ALPHA | PEF_DEFORM;
1594 pe.alpha = obj->lifeleft / 5.0;
1595 pe.deform_range = .2f * (1.0 - (obj->lifeleft / 5.0));
1596
1597 use_effect = 1;
1598 }
1599 // Fog this object if needed
1600 if (!OBJECT_OUTSIDE(obj) && (Rooms[obj->roomnum].flags & RF_FOG) && Room_fog_plane_check != -1) {
1601 pe.type |= PEF_FOGGED_MODEL;
1602 pe.fog_distance = Room_fog_distance;
1603 pe.fog_eye_distance = Room_fog_eye_distance;
1604 pe.fog_plane_check = Room_fog_plane_check;
1605 pe.fog_portal_vert = Room_fog_portal_vert;
1606 pe.fog_plane = Room_fog_plane;
1607 pe.fog_depth = Rooms[obj->roomnum].fog_depth;
1608 pe.fog_r = Rooms[obj->roomnum].fog_r;
1609 pe.fog_g = Rooms[obj->roomnum].fog_g;
1610 pe.fog_b = Rooms[obj->roomnum].fog_b;
1611
1612 use_effect = 1;
1613 }
1614 // Apply specularity from dynamic lights
1615 if (obj->effect_info) {
1616 if ((obj->effect_info->type_flags & EF_SPECULAR)) {
1617 if (obj->type == OBJ_POWERUP)
1618 pe.type |= PEF_SPECULAR_MODEL;
1619 else
1620 pe.type |= PEF_SPECULAR_FACES;
1621
1622 pe.spec_light_pos = obj->effect_info->spec_pos;
1623 pe.spec_r = obj->effect_info->spec_r;
1624 pe.spec_g = obj->effect_info->spec_g;
1625 pe.spec_b = obj->effect_info->spec_b;
1626 pe.spec_scalar = 1.0;
1627 use_effect = 1;
1628 }
1629 }
1630 // Apply specularity from outdoor satellites
1631 if (OBJECT_OUTSIDE(obj) && obj->lighting_render_type == LRT_GOURAUD && Detail_settings.Specular_lighting &&
1632 !(Object_info[obj->id].lighting_info.flags & OLF_NO_SPECULARITY)) {
1633 if (obj->effect_info && !(obj->effect_info->type_flags & EF_SPECULAR)) {
1634 if (obj->type == OBJ_POWERUP)
1635 pe.type |= PEF_SPECULAR_MODEL;
1636 else
1637 pe.type |= PEF_SPECULAR_FACES;
1638
1639 pe.spec_light_pos = Terrain_sky.satellite_vectors[0];
1640 pe.spec_r = 1.0;
1641 pe.spec_g = 1.0;
1642 pe.spec_b = 1.0;
1643 pe.spec_scalar = RenderObjectStaticScalar;
1644 use_effect = 1;
1645 }
1646 }
1647 if (Detail_settings.Bumpmapping_enabled && (obj->type == OBJ_ROBOT || obj->type == OBJ_PLAYER)) {
1648 pe.bump_light_pos = obj->pos;
1649 pe.bump_light_pos.y += 100;
1650 pe.bump_scalar = 1;
1651 pe.type |= PEF_BUMPMAPPED;
1652 use_effect = 1;
1653 }
1654 }
1655 // Pick a lod model to use if eligible
1656 if (obj->lighting_render_type == LRT_STATIC || obj->lighting_render_type == LRT_GOURAUD) {
1657 if (obj->type == OBJ_POWERUP || obj->type == OBJ_ROBOT || obj->type == OBJ_CLUTTER) {
1658 g3Point pnt;
1659 float detail_scalar = 1.0;
1660 g3_RotatePoint(&pnt, &obj->pos);
1661 if (Detail_settings.Object_complexity == 0)
1662 detail_scalar = .6f;
1663 else if (Detail_settings.Object_complexity == 2)
1664 detail_scalar = 1.2f;
1665 if (pnt.p3_z < (Object_info[obj->id].med_lod_distance * detail_scalar))
1666 model_num = obj->rtype.pobj_info.model_num;
1667 else if (pnt.p3_z < (Object_info[obj->id].lo_lod_distance * detail_scalar)) {
1668 if (Object_info[obj->id].med_render_handle != -1)
1669 model_num = Object_info[obj->id].med_render_handle;
1670 else {
1671 model_num = obj->rtype.pobj_info.model_num;
1672 }
1673 } else {
1674 if (Object_info[obj->id].lo_render_handle != -1)
1675 model_num = Object_info[obj->id].lo_render_handle;
1676 else {
1677 model_num = obj->rtype.pobj_info.model_num;
1678 if (Object_info[obj->id].med_render_handle != -1)
1679 model_num = Object_info[obj->id].med_render_handle;
1680 else
1681 model_num = obj->rtype.pobj_info.model_num;
1682 }
1683 }
1684 } else if (obj->type == OBJ_MARKER) {
1685 model_num = Marker_polynum;
1686 } else if (obj->type == OBJ_PLAYER && !(Players[obj->id].flags & (PLAYER_FLAGS_DYING | PLAYER_FLAGS_DEAD))) {
1687 g3Point pnt;
1688 g3_RotatePoint(&pnt, &obj->pos);
1689 int ship_num = Players[obj->id].ship_index;
1690 float detail_scalar = 1.0;
1691 if (Detail_settings.Object_complexity == 0)
1692 detail_scalar = .6f;
1693 else if (Detail_settings.Object_complexity == 2)
1694 detail_scalar = 1.2f;
1695 if (pnt.p3_z < (Ships[ship_num].med_lod_distance * detail_scalar))
1696 model_num = obj->rtype.pobj_info.model_num;
1697 else if (pnt.p3_z < (Ships[ship_num].lo_lod_distance * detail_scalar)) {
1698 if (Ships[ship_num].med_render_handle != -1)
1699 model_num = Ships[ship_num].med_render_handle;
1700 else {
1701 model_num = obj->rtype.pobj_info.model_num;
1702 }
1703 } else {
1704 if (Ships[ship_num].lo_render_handle != -1)
1705 model_num = Ships[ship_num].lo_render_handle;
1706 else {
1707 model_num = obj->rtype.pobj_info.model_num;
1708 if (Ships[ship_num].med_render_handle != -1)
1709 model_num = Ships[ship_num].med_render_handle;
1710 else
1711 model_num = obj->rtype.pobj_info.model_num;
1712 }
1713 }
1714 } else
1715 model_num = obj->rtype.pobj_info.model_num;
1716 } else
1717 model_num = obj->rtype.pobj_info.model_num;
1718 if (obj->type == OBJ_BUILDING && obj->flags & OF_USE_DESTROYED_POLYMODEL) {
1719 if (Object_info[obj->id].lo_render_handle != -1)
1720 model_num = Object_info[obj->id].lo_render_handle;
1721 }
1722 // Set effects
1723 if (use_effect)
1724 SetPolymodelEffect(&pe);
1725 if (RenderObjectType == RO_STATIC) {
1726 // Draw this object with static light
1727 int overlay = 0;
1728 if ((obj->type == OBJ_ROBOT || obj->type == OBJ_PLAYER) && obj->rtype.pobj_info.subobj_flags != 0xFFFFFFFF)
1729 overlay = 1;
1730
1731 DrawPolygonModel(&obj_pos, &obj->orient, model_num, normalized_times, 0, RenderObjectStaticRedValue,
1732 RenderObjectStaticGreenValue, RenderObjectStaticBlueValue, obj->rtype.pobj_info.subobj_flags,
1733 use_effect, overlay);
1734 } else if (RenderObjectType == RO_GOURAUD || NoLightmaps) {
1735 // Draw this object with gouraud static light
1736 int overlay = 0;
1737 if ((obj->type == OBJ_ROBOT || obj->type == OBJ_PLAYER) && obj->rtype.pobj_info.subobj_flags != 0xFFFFFFFF)
1738 overlay = 1;
1739 DrawPolygonModel(&obj_pos, &obj->orient, model_num, normalized_times, 0, &RenderObject_LightDirection,
1740 RenderObjectStaticRedValue, RenderObjectStaticGreenValue, RenderObjectStaticBlueValue,
1741 obj->rtype.pobj_info.subobj_flags, use_effect, overlay);
1742 } else if (RenderObjectType == RO_LIGHTMAPS) {
1743 int overlay = 0;
1744 if ((obj->type == OBJ_ROBOT || obj->type == OBJ_PLAYER) && obj->rtype.pobj_info.subobj_flags != 0xFFFFFFFF)
1745 overlay = 1;
1746 // If this object is a destroyed building then do something different with it
1747 DrawPolygonModel(&obj_pos, &obj->orient, model_num, normalized_times, 0, RenderObjectLightmapObject,
1748 obj->rtype.pobj_info.subobj_flags, use_effect, overlay);
1749 } else
1750 Int3(); // Get Jason
1751 }
1752 // Sets the direction of the lightsource to be used when calculating vertex lighting
1753 // The light source vector should be in the models coordinate space
1754 void RenderObject_SetLightDirection(vector *dir) { RenderObject_LightDirection = *dir; }
1755 // draw an object that has one bitmap & doesn't rotate
1756 void obj_draw_blob(object *obj, int bmnum) {
1757 // int orientation=0;
1758 // grs_bitmap * bm = &GameBitmaps[bmnum];
1759 //
1760 //
1761 // if (obj->type == OBJ_FIREBALL)
1762 // orientation = (obj-Objects) & 7;
1763 //
1764 // orientation = global_orientation;
1765 //
1766 // PIGGY_PAGE_IN( bmi );
1767 //
1768 // if (bm->bm_w > bm->bm_h)
1769 //
1770 // g3_draw_bitmap(&obj->pos,obj->size,fixmuldiv(obj->size,bm->bm_h,bm->bm_w),bm, orientation);
1771 //
1772 // else
1773 //
1774 // g3_draw_bitmap(&obj->pos,fixmuldiv(obj->size,bm->bm_w,bm->bm_h),obj->size,bm, orientation);
1775 }
1776 extern float Far_clip_z;
1777 int Point_visible_last_frame = -1;
1778 // Given a position in 3space and a size, returns whether or not that sized point is
1779 // visible from the current view matrix
1780 int IsPointVisible(vector *pos, float size, float *pointz) {
1781 g3Point pnt;
1782 uint8_t ccode;
1783 static float last_render_fov = -1;
1784 static vector left_normal, right_normal, top_normal, bottom_normal, view_position;
1785 static matrix unscaled_matrix;
1786
1787 g3_RotatePoint(&pnt, pos);
1788 ccode = g3_CodePoint(&pnt);
1789 if (pointz != NULL)
1790 *pointz = pnt.p3_z;
1791 if (ccode) // the center point is off, find out if the whole object is off
1792 {
1793 float dotp;
1794
1795 if (pnt.p3_z < -size)
1796 return 0; // behind plane!
1797 if (pnt.p3_z > Far_clip_z + size)
1798 return 0; // too far away!
1799 if (Render_FOV != last_render_fov) {
1800 last_render_fov = Render_FOV;
1801 int angle_adjust = (Render_FOV / 2) * (65536 / 360);
1802 vector rvec = {1, 0, 0};
1803 vector lvec = {-1, 0, 0};
1804 vector tvec = {0, 1, 0};
1805 vector bvec = {0, -1, 0};
1806 matrix temp_mat;
1807 vm_AnglesToMatrix(&temp_mat, 0, 65536 - angle_adjust, 0);
1808 right_normal = rvec * temp_mat;
1809 vm_AnglesToMatrix(&temp_mat, 0, angle_adjust, 0);
1810 left_normal = lvec * temp_mat;
1811 vm_AnglesToMatrix(&temp_mat, 65536 - angle_adjust, 0, 0);
1812 bottom_normal = bvec * temp_mat;
1813 vm_AnglesToMatrix(&temp_mat, angle_adjust, 0, 0);
1814 top_normal = tvec * temp_mat;
1815 }
1816 // Get unscaled matrix stuff
1817 if (Point_visible_last_frame != FrameCount) {
1818 Point_visible_last_frame = FrameCount;
1819 g3_GetUnscaledMatrix(&unscaled_matrix);
1820 g3_GetViewPosition(&view_position);
1821 }
1822 vector temp_vec = *pos - view_position;
1823 pnt.p3_vec = temp_vec * unscaled_matrix;
1824 if (ccode & CC_OFF_RIGHT) {
1825 dotp = vm_DotProduct(&right_normal, &pnt.p3_vec);
1826 if (dotp > size)
1827 return 0;
1828 }
1829 if (ccode & CC_OFF_LEFT) {
1830 dotp = vm_DotProduct(&left_normal, &pnt.p3_vec);
1831 if (dotp > size)
1832 return 0;
1833 }
1834
1835 if (ccode & CC_OFF_TOP) {
1836 dotp = vm_DotProduct(&top_normal, &pnt.p3_vec);
1837 if (dotp > size)
1838 return 0;
1839 }
1840 if (ccode & CC_OFF_BOT) {
1841 dotp = vm_DotProduct(&bottom_normal, &pnt.p3_vec);
1842 if (dotp > size)
1843 return 0;
1844 }
1845 return 1;
1846 }
1847 // Center point is on, must be visible
1848 return 1;
1849 }
1850
1851 // Do powerup sparkles and stuff
1852 void DrawPowerupSparkles(object *obj) {
1853 extern bool Render_mirror_for_room;
1854 if (!Render_powerup_sparkles)
1855 return;
1856
1857 if (Game_paused)
1858 return;
1859
1860 // we want to render if
1861 // a) we are not rendering in a mirror
1862 // b) we are rendering a mirror but the object is not visible from our position
1863 if (Render_mirror_for_room && !IsPointVisible(&obj->pos, obj->size, NULL))
1864 return;
1865
1866 if (obj->render_type != RT_POLYOBJ)
1867 return;
1868
1869 // check to see if it's time to update
1870 if (Last_powerup_sparkle_time < POWERUP_SPARKLE_INTERVAL)
1871 return;
1872
1873 int num_sparks = ps_rand() & 7;
1874 float obj_size_delta = obj->size * 0.3f;
1875
1876 // Create some sparks
1877 for (int i = 0; i < num_sparks; ++i) {
1878 const int randnum = ps_rand() % 10;
1879
1880 int index;
1881 switch (randnum) {
1882 case 0:
1883 index = HOT_SPARK_INDEX;
1884 break;
1885 case 1:
1886 index = COOL_SPARK_INDEX;
1887 break;
1888 default:
1889 index = GRAY_SPARK_INDEX;
1890 break;
1891 }
1892
1893 vector pos_delta;
1894 pos_delta.x = (ps_rand() % 100) - 50;
1895 pos_delta.y = (ps_rand() % 100) - 80;
1896 pos_delta.z = (ps_rand() % 100) - 50;
1897 vm_NormalizeVector(&pos_delta);
1898 pos_delta = obj->last_pos + (obj_size_delta * pos_delta);
1899
1900 int sparknum = VisEffectCreate(VIS_FIREBALL, index, obj->roomnum, &pos_delta);
1901 if (sparknum >= 0) {
1902 vis_effect *vis = &VisEffects[sparknum];
1903
1904 vis->end_pos = vis->pos;
1905 vis->movement_type = MT_PHYSICS;
1906 vis->mass = 1000.0f;
1907 vis->drag = 0.2f;
1908 vis->phys_flags |= PF_GRAVITY | PF_NO_COLLIDE;
1909
1910 vis->velocity.x = (ps_rand() % 50) - 25;
1911 vis->velocity.y = -10 - (ps_rand() % 20);
1912 vis->velocity.z = (ps_rand() % 50) - 25;
1913 vm_NormalizeVector(&vis->velocity);
1914 vis->velocity *= 3.0f + (ps_rand() % 4);
1915
1916 vis->size = 0.05f + ((ps_rand() % 10) * 0.008f);
1917 vis->flags |= VF_USES_LIFELEFT;
1918
1919 const float lifetime = 0.25f + ((ps_rand() % 10) * 0.05f);
1920 vis->lifeleft = lifetime;
1921 vis->lifetime = lifetime;
1922
1923 light_info *li = ObjGetLightInfo(obj);
1924 if (li) {
1925 vis->lighting_color = GR_RGB16(li->red_light1 * 255.0f, li->green_light1 * 255.0f, li->blue_light1 * 255.0f);
1926 } else {
1927 vis->lighting_color = GR_RGB16(255, 255, 255);
1928 }
1929 }
1930 }
1931 }
1932
1933 #define POWERUP_HALO_ALPHA .3f
1934 // Draws the glowing disk around a powerup
1935 void DrawPowerupGlowDisk(object *obj) {
1936 ASSERT(obj->type == OBJ_POWERUP);
1937 if (!Detail_settings.Powerup_halos)
1938 return;
1939 if (obj->render_type == RT_NONE)
1940 return;
1941 if (Viewer_object->effect_info && Viewer_object->effect_info->type_flags & EF_DEFORM)
1942 return;
1943 light_info *li = ObjGetLightInfo(obj);
1944 int objnum = obj - Objects;
1945 float size_adjust = FixSin((objnum * 5000) + (FrameCount * 600));
1946 size_adjust += 1.0;
1947 size_adjust /= 2; // now in range 0 to 1.0
1948 size_adjust += .5;
1949 vector subvec = obj->pos - Viewer_object->pos;
1950 float mag = vm_GetMagnitudeFast(&subvec);
1951 if (mag < 40)
1952 return;
1953
1954 float alpha_scalar = 1;
1955 if (obj->flags & OF_USES_LIFELEFT) {
1956 if (obj->lifeleft < 5)
1957 alpha_scalar = (obj->lifeleft / 5.0);
1958 }
1959 if (mag < 70) {
1960 alpha_scalar *= ((mag - 40) / 30.0);
1961 }
1962
1963 // Draw lo-res disk
1964 DrawColoredDisk(&obj->pos, li->red_light1, li->green_light1, li->blue_light1, POWERUP_HALO_ALPHA * alpha_scalar, 0.0f,
1965 (obj->size / 2) + size_adjust, 0, 2);
1966 }
1967 // Draws the glowing disk around a player indicating damage
1968 void DrawPlayerDamageDisk(object *obj) {
1969 // if (!(Game_mode & GM_MULTI))
1970 // return; // only in multiplayer
1971
1972 ASSERT(obj->type == OBJ_PLAYER);
1973 if (obj == Viewer_object)
1974 return; // don't do me
1975 float damage_norm = Players[obj->id].damage_magnitude / MAX_DAMAGE_MAG;
1976 if (damage_norm > 1.0)
1977 damage_norm = 1.0;
1978 if (damage_norm < .001)
1979 return;
1980 rend_SetZBias(-obj->size);
1981 int bm_handle;
1982 int objnum = obj - Objects;
1983 float rot_temp = .25; // Higher is faster
1984 int int_game = Gametime / rot_temp;
1985 float diff = Gametime - (int_game * rot_temp);
1986 int rot_angle = diff * 65536;
1987 rot_angle = 0;
1988 bm_handle = Fireballs[SHIP_HIT_INDEX].bm_handle;
1989
1990 rend_SetAlphaType(AT_SATURATE_TEXTURE);
1991 rend_SetZBufferWriteMask(0);
1992
1993 rend_SetAlphaValue(.4 * damage_norm * 255);
1994 rend_SetOverlayType(OT_NONE);
1995 rend_SetLighting(LS_NONE);
1996 g3_DrawRotatedBitmap(&obj->pos, rot_angle, obj->size, (obj->size * bm_h(bm_handle, 0)) / bm_w(bm_handle, 0),
1997 bm_handle);
1998 rend_SetZBufferWriteMask(1);
1999 rend_SetZBias(0);
2000 }
2001 // Draws the red sphere around a player indicating invulnerability
2002 void DrawPlayerInvulSphere(object *obj) {
2003 // if (!(Game_mode & GM_MULTI))
2004 // return; // only in multiplayer
2005
2006 ASSERT(obj->type == OBJ_PLAYER);
2007 if (Viewer_object == obj)
2008 return; // don't do me
2009 if (!(Players[obj->id].flags & PLAYER_FLAGS_INVULNERABLE))
2010 return;
2011 if (Players[obj->id].invul_magnitude < .05)
2012 return;
2013
2014 int bm_handle = Fireballs[INVUL_HIT_INDEX].bm_handle;
2015 // Figure out the position and orientation to draw this
2016 vector hit_pos = obj->pos + (Players[obj->id].invul_vector * obj->size);
2017 vector norm_vec = Players[obj->id].invul_vector;
2018 // Check to see that we're ok with the length of the vector
2019 float mag = vm_GetMagnitudeFast(&norm_vec);
2020 if (mag < 1)
2021 return;
2022 norm_vec /= mag;
2023
2024 // Now draw!
2025 rend_SetAlphaType(AT_SATURATE_TEXTURE);
2026 rend_SetZBufferWriteMask(0);
2027 rend_SetAlphaValue(.6 * Players[obj->id].invul_magnitude * 255);
2028 rend_SetOverlayType(OT_NONE);
2029 rend_SetLighting(LS_NONE);
2030 g3_DrawPlanarRotatedBitmap(&hit_pos, &norm_vec, 0, 3, 3, bm_handle);
2031 rend_SetZBufferWriteMask(1);
2032 }
2033 // Draws a rotating ball around the player
2034 void DrawPlayerRotatingBall(object *obj) {
2035 ASSERT(obj->type == OBJ_PLAYER);
2036 if (Players[obj->id].num_balls < 1)
2037 return;
2038 static int first = 1;
2039 static int bm_handle;
2040 vector worldpos;
2041 rend_SetColorModel(CM_RGB);
2042 rend_SetLighting(LS_GOURAUD);
2043 rend_SetTextureType(TT_LINEAR);
2044 rend_SetAlphaType(AT_SATURATE_TEXTURE);
2045 rend_SetAlphaValue(.3 * 255);
2046 rend_SetZBufferWriteMask(0);
2047 if (first) {
2048 int texhandle = FindTextureName("WhiteGlowingBall");
2049 if (texhandle == -1)
2050 bm_handle = 0;
2051 else
2052 bm_handle = GetTextureBitmap(texhandle, 0);
2053 first = 0;
2054 }
2055 for (int i = 0; i < Players[obj->id].num_balls; i++) {
2056 PlayerGetBallPosition(&worldpos, obj->id, i);
2057 // Get color of balls
2058 ddgr_color color =
2059 GR_RGB(Players[obj->id].ball_r[i] * 255, Players[obj->id].ball_g[i] * 255, Players[obj->id].ball_b[i] * 255);
2060 g3_DrawBitmap(&worldpos, obj->size / 4, ((obj->size / 4) * bm_h(bm_handle, 0)) / bm_w(bm_handle, 0), bm_handle,
2061 color);
2062 }
2063 rend_SetZBufferWriteMask(1);
2064 }
2065 // Draws the 'typing message' icon indicator above an object
2066 void DrawPlayerTypingIndicator(object *obj) {
2067 if (!(Game_mode & GM_MULTI))
2068 return;
2069 int slot = obj->id;
2070 if (slot == Player_num)
2071 return;
2072 if (NetPlayers[slot].sequence != NETSEQ_PLAYING)
2073 return;
2074 uint32_t bit = (0x01 << slot);
2075 if (!(Players_typing & bit))
2076 return;
2077 if (obj->effect_info && obj->effect_info->type_flags & EF_CLOAKED)
2078 return;
2079 static int type_indicator_model = -2;
2080 if (type_indicator_model == -2)
2081 type_indicator_model = FindTextureName("TypingIndicator");
2082 if (type_indicator_model < 0)
2083 return;
2084 int bm_handle = GetTextureBitmap(type_indicator_model, 0);
2085 float IndicatorTan;
2086 float rad = (float)(3.14 * (float)(10) / 180.0);
2087 IndicatorTan = tan(rad);
2088 // See if its in our viewcone
2089 vector subvec = obj->pos - Player_object->pos;
2090 vm_NormalizeVectorFast(&subvec);
2091 if ((vm_DotProduct(&subvec, &Player_object->orient.fvec)) < IndicatorTan)
2092 return;
2093 if ((vm_VectorDistanceQuick(&Viewer_object->pos, &obj->pos) > 800.0f))
2094 return;
2095 // Find out if it is o.k. to draw here.
2096 fvi_query fq;
2097 fvi_info hit_data;
2098 int fate;
2099 fq.p0 = &Player_object->pos;
2100 fq.startroom = Player_object->roomnum;
2101 fq.p1 = &obj->pos;
2102 fq.rad = 0;
2103 fq.thisobjnum = -1;
2104 fq.ignore_obj_list = NULL;
2105 fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS;
2106 fate = fvi_FindIntersection(&fq, &hit_data);
2107 if (fate == HIT_NONE || (fate == HIT_SPHERE_2_POLY_OBJECT && hit_data.hit_object[0] == (obj - Objects))) {
2108 // Draw this indicator on the hud
2109 g3Point pnt;
2110 int bmh, bmw;
2111 g3Point *pntlist[32], points[4];
2112 g3Codes cc;
2113 uint8_t code;
2114
2115 cc.cc_and = 0xFF;
2116 cc.cc_or = 0;
2117
2118 int b_w = std::min(bm_w(bm_handle, 0), 32);
2119 int b_h = std::min(bm_h(bm_handle, 0), 32);
2120 bmw = b_w / 2;
2121 bmh = b_h / 2;
2122
2123 g3_RotatePoint(&pnt, fq.p1);
2124 g3_ProjectPoint(&pnt);
2125
2126 points[0].p3_vec.x = pnt.p3_vec.x - bmw;
2127 points[0].p3_vec.y = pnt.p3_vec.y + bmh + 5;
2128 points[0].p3_vec.z = pnt.p3_vec.z;
2129 points[0].p3_u = 0;
2130 points[0].p3_v = 0;
2131
2132 points[1].p3_vec.x = pnt.p3_vec.x + bmw;
2133 points[1].p3_vec.y = pnt.p3_vec.y + bmh + 5;
2134 points[1].p3_vec.z = pnt.p3_vec.z;
2135 points[1].p3_u = 1;
2136 points[1].p3_v = 0;
2137
2138 points[2].p3_vec.x = pnt.p3_vec.x + bmw;
2139 points[2].p3_vec.y = pnt.p3_vec.y - bmh + 5;
2140 points[2].p3_vec.z = pnt.p3_vec.z;
2141 points[2].p3_u = 1;
2142 points[2].p3_v = 1;
2143
2144 points[3].p3_vec.x = pnt.p3_vec.x - bmw;
2145 points[3].p3_vec.y = pnt.p3_vec.y - bmh + 5;
2146 points[3].p3_vec.z = pnt.p3_vec.z;
2147 points[3].p3_u = 0;
2148 points[3].p3_v = 1;
2149
2150 for (int i = 0; i < 4; i++) {
2151 points[i].p3_flags |= PF_UV;
2152 pntlist[i] = &points[i];
2153 code = g3_CodePoint(pntlist[i]);
2154 g3_ProjectPoint(pntlist[i]);
2155
2156 cc.cc_and &= code;
2157 cc.cc_or |= code;
2158 }
2159 rend_SetAlphaType(AT_CONSTANT_TEXTURE);
2160 rend_SetAlphaValue(200);
2161 rend_SetWrapType(WT_CLAMP);
2162 rend_SetLighting(LS_NONE);
2163 rend_SetOverlayType(OT_NONE);
2164 rend_SetColorModel(CM_MONO);
2165 rend_SetTextureType(TT_LINEAR);
2166 g3_DrawPoly(4, pntlist, bm_handle, 0, &cc);
2167 }
2168 }
2169 // Draws the player name on the hud
2170 void DrawPlayerNameOnHud(object *obj) {
2171 if (!(Game_mode & GM_MULTI))
2172 return;
2173 int slot = obj->id;
2174 int color;
2175 if (slot == Player_num)
2176 return;
2177 if (NetPlayers[slot].sequence != NETSEQ_PLAYING)
2178 return;
2179 if (HudNameTan <= 0)
2180 return;
2181 if (obj->effect_info && obj->effect_info->type_flags & EF_CLOAKED)
2182 return;
2183
2184 // Get color to draw this name in
2185 DLLInfo.me_handle = obj->handle;
2186 CallGameDLL(EVT_CLIENT_GETCOLOREDNAME, &DLLInfo);
2187 color = DLLInfo.iRet;
2188 if (color < 0)
2189 return;
2190
2191 // See if its in our viewcone
2192 vector subvec = obj->pos - Player_object->pos;
2193 vm_NormalizeVectorFast(&subvec);
2194 if ((vm_DotProduct(&subvec, &Player_object->orient.fvec)) < HudNameTan)
2195 return;
2196 // Find out if it is o.k. to draw here.
2197 fvi_query fq;
2198 fvi_info hit_data;
2199 int fate;
2200 fq.p0 = &Player_object->pos;
2201 fq.startroom = Player_object->roomnum;
2202 fq.p1 = &obj->pos;
2203 fq.rad = 0;
2204 fq.thisobjnum = -1;
2205 fq.ignore_obj_list = NULL;
2206 fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS;
2207 fate = fvi_FindIntersection(&fq, &hit_data);
2208 if (fate == HIT_NONE || (fate == HIT_SPHERE_2_POLY_OBJECT && hit_data.hit_object[0] == (obj - Objects))) {
2209 int half = Game_window_w / 2;
2210 // Draw this name on the hud
2211 g3Point pnt;
2212 g3_RotatePoint(&pnt, fq.p1);
2213 g3_ProjectPoint(&pnt);
2214 // put a centered name string in the text buffer.
2215
2216 grtext_SetFont(HUD_FONT);
2217 grtext_SetColor(color);
2218 grtext_CenteredPrintf(pnt.p3_sx - half, pnt.p3_sy, Players[slot].callsign);
2219 grtext_Flush();
2220 }
2221 }
2222 // Creates lightning sparks on a damaged object
2223 void DrawSparkyDamageLightning(object *obj) {
2224 float max_shields = 100;
2225 if (obj->type == OBJ_ROBOT || obj->type == OBJ_CLUTTER || obj->type == OBJ_BUILDING)
2226 max_shields = Object_info[obj->id].hit_points;
2227 if (obj->type == OBJ_PLAYER)
2228 max_shields = INITIAL_SHIELDS;
2229 // If less than 30% shields, make some lightning every now and then
2230 if (max_shields > 0 && (obj->shields / max_shields) < .3 && obj->shields >= 0) {
2231 float shield_norm = (obj->shields / max_shields) / .3;
2232 shield_norm = 1 - shield_norm;
2233 ASSERT(shield_norm >= 0 && shield_norm <= 1);
2234 int shield_modulo = 20 - (12 * shield_norm);
2235 if (shield_modulo < 1)
2236 shield_modulo = 1;
2237 if ((ps_rand() % shield_modulo) == 0) {
2238 poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num];
2239 if (pm->n_models == 0)
2240 return;
2241 int subnum = ps_rand() % pm->n_models;
2242 if (IsNonRenderableSubmodel(pm, subnum))
2243 return;
2244
2245 bsp_info *sm = &pm->submodel[subnum];
2246 if (sm->nverts == 0)
2247 return;
2248 int visnum = VisEffectCreate(VIS_FIREBALL, LIGHTNING_BOLT_INDEX, obj->roomnum, &obj->pos);
2249 if (visnum >= 0) {
2250 vis_effect *vis = &VisEffects[visnum];
2251 vis->lifeleft = 1.0;
2252 vis->lifetime = 1.0;
2253 vis->end_pos = obj->pos;
2254 vis->velocity.x = .15f;
2255 vis->velocity.y = 3;
2256 vis->attach_info.obj_handle = obj->handle;
2257 vis->attach_info.subnum = subnum;
2258 vis->attach_info.vertnum = ps_rand() % sm->nverts;
2259 vis->attach_info.end_vertnum = ps_rand() % sm->nverts;
2260 vis->attach_info.modelnum = obj->rtype.pobj_info.model_num;
2261 vis->flags = VF_USES_LIFELEFT | VF_EXPAND | VF_ATTACHED;
2262 }
2263 }
2264 }
2265 }
2266
2267 // Creates Virus infected lightning on an object
2268 void DrawVirusLightning(object *obj) {
2269 if (!obj->effect_info)
2270 return;
2271 if (!(obj->effect_info->type_flags & EF_VIRUS_INFECTED))
2272 return;
2273
2274 float shield_norm = (float)(ps_rand() % D3_RAND_MAX) / (float)D3_RAND_MAX;
2275 shield_norm = 1 - shield_norm;
2276
2277 ASSERT(shield_norm >= 0 && shield_norm <= 1);
2278 int shield_modulo = 20 - (16 * shield_norm);
2279 if (shield_modulo < 1)
2280 shield_modulo = 1;
2281 if ((ps_rand() % shield_modulo) == 0) {
2282 poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num];
2283 if (pm->n_models == 0)
2284 return;
2285 int subnum = ps_rand() % pm->n_models;
2286 if (IsNonRenderableSubmodel(pm, subnum))
2287 return;
2288
2289 bsp_info *sm = &pm->submodel[subnum];
2290 if (sm->nverts == 0)
2291 return;
2292 int visnum = VisEffectCreate(VIS_FIREBALL, GRAY_LIGHTNING_BOLT_INDEX, obj->roomnum, &obj->pos);
2293 if (visnum >= 0) {
2294 vis_effect *vis = &VisEffects[visnum];
2295 vis->lifeleft = 1.0;
2296 vis->lifetime = 1.0;
2297 vis->end_pos = obj->pos;
2298 vis->velocity.x = .15f;
2299 vis->velocity.y = 3;
2300 vis->attach_info.obj_handle = obj->handle;
2301 vis->attach_info.subnum = subnum;
2302 vis->attach_info.vertnum = ps_rand() % sm->nverts;
2303 vis->attach_info.end_vertnum = ps_rand() % sm->nverts;
2304 vis->attach_info.modelnum = obj->rtype.pobj_info.model_num;
2305 vis->flags = VF_USES_LIFELEFT | VF_EXPAND | VF_ATTACHED;
2306 vis->lighting_color = GR_RGB16(40, 250, 40);
2307 }
2308 }
2309 }
2310
2311 void DrawPlayerSightVector(object *obj) {
2312 if (obj->type != OBJ_PLAYER || obj->id != Player_num)
2313 return;
2314 if (Player_has_camera == 0 || Player_camera_objnum == -1)
2315 return;
2316 // Cast a ray to see where it ends up
2317 fvi_query fq;
2318 fvi_info hit_data;
2319 int fate;
2320 vector end_pos = obj->pos + (obj->orient.fvec * 500);
2321
2322 fq.p0 = &obj->pos;
2323 fq.startroom = obj->roomnum;
2324 fq.p1 = &end_pos;
2325 fq.rad = 0;
2326 fq.thisobjnum = -1;
2327 fq.ignore_obj_list = NULL;
2328 fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS;
2329 fate = fvi_FindIntersection(&fq, &hit_data);
2330 rend_SetAlphaType(AT_VERTEX);
2331 rend_SetTextureType(TT_FLAT);
2332 rend_SetLighting(LS_GOURAUD);
2333 rend_SetColorModel(CM_RGB);
2334 vector vecs[2];
2335 g3Point pnts[2];
2336
2337 vecs[0] = obj->pos;
2338 vecs[1] = hit_data.hit_pnt;
2339 for (int i = 0; i < 2; i++) {
2340 g3_RotatePoint(&pnts[i], &vecs[i]);
2341 pnts[i].p3_flags |= PF_RGBA;
2342 pnts[i].p3_r = 1;
2343 pnts[i].p3_g = 0;
2344 pnts[i].p3_b = 0;
2345 }
2346 pnts[0].p3_a = .1f;
2347 pnts[1].p3_a = .05f;
2348 g3_DrawSpecialLine(&pnts[0], &pnts[1]);
2349 }