Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
boxrobj.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WW3D *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/boxrobj.cpp $*
26 * *
27 * Author:: Greg Hjelstrom *
28 * *
29 * $Modtime:: 1/19/02 12:57p $*
30 * *
31 * $Revision:: 35 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * BoxRenderObjClass::BoxRenderObjClass -- Constructor *
36 * BoxRenderObjClass::BoxRenderObjClass -- Constructor - init from a definition *
37 * BoxRenderObjClass::BoxRenderObjClass -- Copy constructor *
38 * BoxRenderObjClass::operator -- assignment operator *
39 * BoxRenderObjClass::Get_Num_Polys -- returns number of polygons *
40 * BoxRenderObjClass::Get_Name -- returns name *
41 * BoxRenderObjClass::Set_Name -- sets the name *
42 * BoxRenderObjClass::Set_Color -- Sets the color of the box *
43 * BoxRenderObjClass::Init_Box_Render_System -- global initialization needed for boxes to wo *
44 * BoxRenderObjClass::Shutdown_Box_Render_System -- cleanup box render system *
45 * BoxRenderObjClass::Set_Box_Display_Mask -- Sets global display mask for all boxes *
46 * BoxRenderObjClass::Get_Box_Display_Mask -- returns the display mask *
47 * BoxRenderObjClass::render_box -- submits the box to the GERD *
48 * BoxRenderObjClass::vis_render_box -- submits box to the GERD for VIS *
49 * AABoxRenderObjClass::AABoxRenderObjClass -- constructor *
50 * AABoxRenderObjClass::AABoxRenderObjClass -- Constructor - init from a definition *
51 * AABoxRenderObjClass::AABoxRenderObjClass -- copy constructor *
52 * AABoxRenderObjClass::AABoxRenderObjClass -- Constructor from a wwmath aabox *
53 * AABoxRenderObjClass::operator -- assignment operator *
54 * AABoxRenderObjClass::Clone -- clones the box *
55 * AABoxRenderObjClass::Class_ID -- returns the class-id for AABox's *
56 * AABoxRenderObjClass::Render -- render this box *
57 * AABoxRenderObjClass::Special_Render -- special render this box (vis) *
58 * AABoxRenderObjClass::Set_Transform -- set the transform for this box *
59 * AABoxRenderObjClass::Set_Position -- Set the position of this box *
60 * AABoxRenderObjClass::update_cached_box -- update the world-space version of this box *
61 * AABoxRenderObjClass::Cast_Ray -- cast a ray against this box *
62 * AABoxRenderObjClass::Cast_AABox -- cast an AABox against this box *
63 * AABoxRenderObjClass::Cast_OBBox -- cast an OBBox against this box *
64 * AABoxRenderObjClass::Intersect_AABox -- intersect this box with an AABox *
65 * AABoxRenderObjClass::Intersect_OBBox -- Intersect this box with an OBBox *
66 * AABoxRenderObjClass::Get_Obj_Space_Bounding_Sphere -- return the object-space bounding sp *
67 * AABoxRenderObjClass::Get_Obj_Space_Bounding_Box -- returns the obj-space bounding box *
68 * OBBoxRenderObjClass::OBBoxRenderObjClass -- Constructor *
69 * OBBoxRenderObjClass::OBBoxRenderObjClass -- Constructor - initiallize from a definition *
70 * OBBoxRenderObjClass::OBBoxRenderObjClass -- copy constructor *
71 * OBBoxRenderObjClass::OBBoxRenderObjClass -- constructor - initialize from a wwmath obbox *
72 * OBBoxRenderObjClass::operator -- assignment operator *
73 * OBBoxRenderObjClass::Clone -- clone this obbox *
74 * OBBoxRenderObjClass::Class_ID -- returns the class ID of OBBoxRenderObjClass *
75 * OBBoxRenderObjClass::Render -- render this obbox *
76 * OBBoxRenderObjClass::Special_Render -- special render (vis) *
77 * OBBoxRenderObjClass::Set_Transform -- set the transform for this box *
78 * OBBoxRenderObjClass::Set_Position -- set the position of this box *
79 * OBBoxRenderObjClass::update_cached_box -- update the cached world-space box *
80 * OBBoxRenderObjClass::Cast_Ray -- cast a ray against this box *
81 * OBBoxRenderObjClass::Cast_AABox -- cast a swept aabox against this box *
82 * OBBoxRenderObjClass::Cast_OBBox -- cast a swept obbox against this bo *
83 * OBBoxRenderObjClass::Intersect_AABox -- test this box for intersection with an AAbox *
84 * OBBoxRenderObjClass::Intersect_OBBox -- test this box for intersection with an OBBox *
85 * OBBoxRenderObjClass::Get_Obj_Space_Bounding_Sphere -- return the obj-space bounding spher *
86 * OBBoxRenderObjClass::Get_Obj_Space_Bounding_Box -- returns the obj-space bounding box *
87 * OBBoxRenderObjClass::Get_Box -- returns the cached world-space box *
88 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
89
90
91#include "boxrobj.h"
92#include "w3d_util.h"
93#include "wwdebug.h"
94#include "vertmaterial.h"
95#include "ww3d.h"
96#include "chunkio.h"
97#include "rinfo.h"
98#include "coltest.h"
99#include "inttest.h"
100#include "dx8wrapper.h"
101#include "dx8indexbuffer.h"
102#include "dx8vertexbuffer.h"
103#include "dx8fvf.h"
104#include "sortingrenderer.h"
105#include "visrasterizer.h"
106#include "meshgeometry.h"
107
108
109#define NUM_BOX_VERTS 8
110#define NUM_BOX_FACES 12
111
112// Face Connectivity
113static TriIndex _BoxFaces[NUM_BOX_FACES] =
114{
115 TriIndex( 0,1,2 ), // +z faces
116 TriIndex( 0,2,3 ),
117 TriIndex( 4,7,6 ), // -z faces
118 TriIndex( 4,6,5 ),
119 TriIndex( 0,3,7 ), // +x faces
120 TriIndex( 0,7,4 ),
121 TriIndex( 1,5,6 ), // -x faces
122 TriIndex( 1,6,2 ),
123 TriIndex( 4,5,1 ), // +y faces
124 TriIndex( 4,1,0 ),
125 TriIndex( 3,2,6 ), // -y faces
126 TriIndex( 3,6,7 )
127};
128
129// Vertex Positions as a function of the box extents
130static Vector3 _BoxVerts[NUM_BOX_VERTS] =
131{
132 Vector3( 1.0f, 1.0f, 1.0f ), // +z ring of 4 verts
133 Vector3( -1.0f, 1.0f, 1.0f ),
134 Vector3( -1.0f,-1.0f, 1.0f ),
135 Vector3( 1.0f,-1.0f, 1.0f ),
136
137 Vector3( 1.0f, 1.0f,-1.0f ), // -z ring of 4 verts;
138 Vector3( -1.0f, 1.0f,-1.0f ),
139 Vector3( -1.0f,-1.0f,-1.0f ),
140 Vector3( 1.0f,-1.0f,-1.0f ),
141};
142
143// Vertex Normals
144static Vector3 _BoxVertexNormals[NUM_BOX_VERTS] =
145{
150
155};
156
157
158
161static VertexMaterialClass * _BoxMaterial = NULL;
162static ShaderClass _BoxShader;
163
164
165/*
166** BoxRenderObjClass Implementation
167*/
168
169
170/***********************************************************************************************
171 * BoxRenderObjClass::BoxRenderObjClass -- Constructor *
172 * *
173 * INPUT: *
174 * *
175 * OUTPUT: *
176 * *
177 * WARNINGS: *
178 * *
179 * HISTORY: *
180 * 1/19/00 gth : Created. *
181 *=============================================================================================*/
183{
184 memset(Name,0,sizeof(Name));
185 Color.Set(1,1,1);
186 Opacity = 0.25f;
187 ObjSpaceCenter.Set(0,0,0);
188 ObjSpaceExtent.Set(1,1,1);
189}
190
191
192/***********************************************************************************************
193 * BoxRenderObjClass::BoxRenderObjClass -- Constructor - init from a definition *
194 * *
195 * INPUT: *
196 * *
197 * OUTPUT: *
198 * *
199 * WARNINGS: *
200 * *
201 * HISTORY: *
202 * 1/19/00 gth : Created. *
203 *=============================================================================================*/
214
215
216/***********************************************************************************************
217 * BoxRenderObjClass::BoxRenderObjClass -- Copy constructor *
218 * *
219 * INPUT: *
220 * *
221 * OUTPUT: *
222 * *
223 * WARNINGS: *
224 * *
225 * HISTORY: *
226 * 1/19/00 gth : Created. *
227 *=============================================================================================*/
229{
230 *this = src;
231}
232
233
234/***********************************************************************************************
235 * BoxRenderObjClass::operator -- assignment operator *
236 * *
237 * INPUT: *
238 * *
239 * OUTPUT: *
240 * *
241 * WARNINGS: *
242 * *
243 * HISTORY: *
244 * 1/19/00 gth : Created. *
245 *=============================================================================================*/
247{
248 if (this != &that) {
250 Set_Name(that.Get_Name());
251 Color.Set(that.Color);
254 }
255 return *this;
256}
257
258
259/***********************************************************************************************
260 * BoxRenderObjClass::Get_Num_Polys -- returns number of polygons *
261 * *
262 * INPUT: *
263 * *
264 * OUTPUT: *
265 * *
266 * WARNINGS: *
267 * *
268 * HISTORY: *
269 * 1/19/00 gth : Created. *
270 *=============================================================================================*/
272{
273 return 12;
274}
275
276
277/***********************************************************************************************
278 * BoxRenderObjClass::Get_Name -- returns name *
279 * *
280 * INPUT: *
281 * *
282 * OUTPUT: *
283 * *
284 * WARNINGS: *
285 * *
286 * HISTORY: *
287 * 1/19/00 gth : Created. *
288 *=============================================================================================*/
289const char * BoxRenderObjClass::Get_Name(void) const
290{
291 return Name;
292}
293
294
295/***********************************************************************************************
296 * BoxRenderObjClass::Set_Name -- sets the name *
297 * *
298 * INPUT: *
299 * *
300 * OUTPUT: *
301 * *
302 * WARNINGS: *
303 * *
304 * HISTORY: *
305 * 1/19/00 gth : Created. *
306 *=============================================================================================*/
307void BoxRenderObjClass::Set_Name(const char * name)
308{
309 WWASSERT(name != NULL);
310 WWASSERT(strlen(name) < 2*W3D_NAME_LEN);
311 strcpy(Name,name);
312}
313
314
315/***********************************************************************************************
316 * BoxRenderObjClass::Set_Color -- Sets the color of the box *
317 * *
318 * INPUT: *
319 * *
320 * OUTPUT: *
321 * *
322 * WARNINGS: *
323 * *
324 * HISTORY: *
325 * 1/19/00 gth : Created. *
326 *=============================================================================================*/
328{
329 Color = color;
330}
331
332
333/***********************************************************************************************
334 * BoxRenderObjClass::Init_Box_Render_System -- global initialization needed for boxes to work *
335 * *
336 * Allocates materials which all boxes share. Initializes vertex tables, etc *
337 * *
338 * INPUT: *
339 * *
340 * OUTPUT: *
341 * *
342 * WARNINGS: *
343 * *
344 * HISTORY: *
345 * 1/19/00 gth : Created. *
346 *=============================================================================================*/
348{
349 WWASSERT(IsInitted == false);
350
351 /*
352 ** Set up the materials
353 */
354 WWASSERT(_BoxMaterial == NULL);
355 _BoxMaterial = NEW_REF(VertexMaterialClass,());
356 _BoxMaterial->Set_Ambient(0,0,0);
357 _BoxMaterial->Set_Diffuse(0,0,0);
358 _BoxMaterial->Set_Specular(0,0,0);
359 _BoxMaterial->Set_Emissive(1,1,1);
360 _BoxMaterial->Set_Opacity(1.0f); // uses vertex alpha...
361 _BoxMaterial->Set_Shininess(0.0f);
362
363 _BoxShader = ShaderClass::_PresetAlphaSolidShader; //_PresetAdditiveSolidShader;
364
365 IsInitted = true;
366}
367
368
369/***********************************************************************************************
370 * BoxRenderObjClass::Shutdown -- cleanup box render system *
371 * *
372 * Releases resources allocated in Init *
373 * NOTE: this is a static function that should only be called by the system *
374 * *
375 * INPUT: *
376 * *
377 * OUTPUT: *
378 * *
379 * WARNINGS: *
380 * *
381 * HISTORY: *
382 * 1/19/00 gth : Created. *
383 *=============================================================================================*/
385{
386 WWASSERT(IsInitted == true);
387 REF_PTR_RELEASE(_BoxMaterial);
388
389 IsInitted = false;
390}
391
392
393/***********************************************************************************************
394 * BoxRenderObjClass::Set_Box_Display_Mask -- Sets global display mask for all boxes *
395 * *
396 * Boxes are debug objects and usually used for collision. This mask is 'AND'ed with each *
397 * box's collision type to determine whether the box should be rendered. *
398 * *
399 * INPUT: *
400 * *
401 * OUTPUT: *
402 * *
403 * WARNINGS: *
404 * *
405 * HISTORY: *
406 * 1/19/00 gth : Created. *
407 *=============================================================================================*/
409{
410 DisplayMask = mask;
411}
412
413
414/***********************************************************************************************
415 * BoxRenderObjClass::Get_Box_Display_Mask -- returns the display mask *
416 * *
417 * INPUT: *
418 * *
419 * OUTPUT: *
420 * *
421 * WARNINGS: *
422 * *
423 * HISTORY: *
424 * 1/19/00 gth : Created. *
425 *=============================================================================================*/
430
431
432/***********************************************************************************************
433 * BoxRenderObjClass::render_box -- submits the box to the GERD *
434 * *
435 * INPUT: *
436 * *
437 * OUTPUT: *
438 * *
439 * WARNINGS: *
440 * *
441 * HISTORY: *
442 * 1/19/00 gth : Created. *
443 *=============================================================================================*/
444void BoxRenderObjClass::render_box(RenderInfoClass & rinfo,const Vector3 & center,const Vector3 & extent)
445{
446 if (!IsInitted) return;
448
449 static Vector3 verts[NUM_BOX_VERTS];
450
451 // compute the vertex positions
452 for (int ivert=0; ivert<NUM_BOX_VERTS; ivert++) {
453 verts[ivert].X = center.X + _BoxVerts[ivert][0] * extent.X;
454 verts[ivert].Y = center.Y + _BoxVerts[ivert][1] * extent.Y;
455 verts[ivert].Z = center.Z + _BoxVerts[ivert][2] * extent.Z;
456 }
457
458 /*
459 ** Dump the box vertices into the sorting dynamic vertex buffer.
460 */
462
463 int buffer_type = BUFFER_TYPE_DYNAMIC_DX8;
464
466 {
468 //unsigned char *vb=(unsigned char *) lock.Get_Vertex_Array();
470
471 for (int i=0; i<NUM_BOX_VERTS; i++) {
472
473 // Locations
474 vb->x=verts[i][0];
475 vb->y=verts[i][1];
476 vb->z=verts[i][2];
477
478 // Normals
479 vb->nx=_BoxVertexNormals[i][0];
480 vb->ny=_BoxVertexNormals[i][1];
481 vb->nz=_BoxVertexNormals[i][2];
482
483 // Colors
484 vb->diffuse=color;
485
486 vb++;
487 }
488 }
489
490 /*
491 ** Dump the faces into the sorting dynamic index buffer.
492 */
493 DynamicIBAccessClass ibaccess(buffer_type,NUM_BOX_FACES*3);
494 {
496 unsigned short * indices = lock.Get_Index_Array();
497 for (int i=0; i<NUM_BOX_FACES; i++) {
498 indices[3*i] = _BoxFaces[i][0];
499 indices[3*i+1] = _BoxFaces[i][1];
500 indices[3*i+2] = _BoxFaces[i][2];
501 }
502 }
503
504 /*
505 ** Apply the shader and material
506 */
507 DX8Wrapper::Set_Material(_BoxMaterial);
508 DX8Wrapper::Set_Shader(_BoxShader);
510
513
514 SphereClass sphere;
516
518 }
519}
520
521
522/***********************************************************************************************
523 * BoxRenderObjClass::vis_render_box -- submits box to the GERD for VIS *
524 * *
525 * this renders the box with the specified VIS-ID. *
526 * *
527 * INPUT: *
528 * *
529 * OUTPUT: *
530 * *
531 * WARNINGS: *
532 * *
533 * HISTORY: *
534 * 1/19/00 gth : Created. *
535 *=============================================================================================*/
537{
538 if (!IsInitted) return;
539
540 static Vector3 verts[NUM_BOX_VERTS];
541
542 // compute the vertex positions
543 for (int ivert=0; ivert<NUM_BOX_VERTS; ivert++) {
544 verts[ivert].X = center.X + _BoxVerts[ivert][0] * extent.X;
545 verts[ivert].Y = center.Y + _BoxVerts[ivert][1] * extent.Y;
546 verts[ivert].Z = center.Z + _BoxVerts[ivert][2] * extent.Z;
547 }
548
549 // render!
551}
552
553/*
554** AABoxRenderObjClass Implementation
555*/
556
557/***********************************************************************************************
558 * AABoxRenderObjClass::AABoxRenderObjClass -- constructor *
559 * *
560 * INPUT: *
561 * *
562 * OUTPUT: *
563 * *
564 * WARNINGS: *
565 * *
566 * HISTORY: *
567 * 1/19/00 gth : Created. *
568 *=============================================================================================*/
573
574
575/***********************************************************************************************
576 * AABoxRenderObjClass::AABoxRenderObjClass -- Constructor - init from a definition *
577 * *
578 * INPUT: *
579 * *
580 * OUTPUT: *
581 * *
582 * WARNINGS: *
583 * *
584 * HISTORY: *
585 * 1/19/00 gth : Created. *
586 *=============================================================================================*/
592
593
594/***********************************************************************************************
595 * AABoxRenderObjClass::AABoxRenderObjClass -- copy constructor *
596 * *
597 * INPUT: *
598 * *
599 * OUTPUT: *
600 * *
601 * WARNINGS: *
602 * *
603 * HISTORY: *
604 * 1/19/00 gth : Created. *
605 *=============================================================================================*/
607{
608 *this = src;
609}
610
611
612/***********************************************************************************************
613 * AABoxRenderObjClass::AABoxRenderObjClass -- Constructor from a wwmath aabox *
614 * *
615 * INPUT: *
616 * *
617 * OUTPUT: *
618 * *
619 * WARNINGS: *
620 * *
621 * HISTORY: *
622 * 1/19/00 gth : Created. *
623 *=============================================================================================*/
631
632
633/***********************************************************************************************
634 * AABoxRenderObjClass::operator -- assignment operator *
635 * *
636 * INPUT: *
637 * *
638 * OUTPUT: *
639 * *
640 * WARNINGS: *
641 * *
642 * HISTORY: *
643 * 1/19/00 gth : Created. *
644 *=============================================================================================*/
646{
647 if (this != &that) {
649 CachedBox = that.CachedBox;
650 }
651 return *this;
652}
653
654
655/***********************************************************************************************
656 * AABoxRenderObjClass::Clone -- clones the box *
657 * *
658 * INPUT: *
659 * *
660 * OUTPUT: *
661 * *
662 * WARNINGS: *
663 * *
664 * HISTORY: *
665 * 1/19/00 gth : Created. *
666 *=============================================================================================*/
668{
669 return W3DNEW AABoxRenderObjClass(*this);
670}
671
672
673/***********************************************************************************************
674 * AABoxRenderObjClass::Class_ID -- returns the class-id for AABox's *
675 * *
676 * INPUT: *
677 * *
678 * OUTPUT: *
679 * *
680 * WARNINGS: *
681 * *
682 * HISTORY: *
683 * 1/19/00 gth : Created. *
684 *=============================================================================================*/
689
690
691/***********************************************************************************************
692 * AABoxRenderObjClass::Render -- render this box *
693 * *
694 * INPUT: *
695 * *
696 * OUTPUT: *
697 * *
698 * WARNINGS: *
699 * *
700 * HISTORY: *
701 * 1/19/00 gth : Created. *
702 *=============================================================================================*/
704{
705 Matrix3D temp(1);
706 temp.Translate(Transform.Get_Translation());
707 DX8Wrapper::Set_Transform(D3DTS_WORLD,temp);
709}
710
711
712/***********************************************************************************************
713 * AABoxRenderObjClass::Special_Render -- special render this box (vis) *
714 * *
715 * INPUT: *
716 * *
717 * OUTPUT: *
718 * *
719 * WARNINGS: *
720 * *
721 * HISTORY: *
722 * 1/19/00 gth : Created. *
723 *=============================================================================================*/
734
735
736/***********************************************************************************************
737 * AABoxRenderObjClass::Set_Transform -- set the transform for this box *
738 * *
739 * INPUT: *
740 * *
741 * OUTPUT: *
742 * *
743 * WARNINGS: *
744 * *
745 * HISTORY: *
746 * 1/19/00 gth : Created. *
747 *=============================================================================================*/
753
754
755/***********************************************************************************************
756 * AABoxRenderObjClass::Set_Position -- Set the position of this box *
757 * *
758 * INPUT: *
759 * *
760 * OUTPUT: *
761 * *
762 * WARNINGS: *
763 * *
764 * HISTORY: *
765 * 1/19/00 gth : Created. *
766 *=============================================================================================*/
772
773
774/***********************************************************************************************
775 * AABoxRenderObjClass::update_cached_box -- update the world-space version of this box *
776 * *
777 * INPUT: *
778 * *
779 * OUTPUT: *
780 * *
781 * WARNINGS: *
782 * *
783 * HISTORY: *
784 * 1/19/00 gth : Created. *
785 *=============================================================================================*/
787{
788 CachedBox.Center = Transform.Get_Translation() + ObjSpaceCenter;
789 CachedBox.Extent = ObjSpaceExtent;
790}
791
792
793/***********************************************************************************************
794 * AABoxRenderObjClass::Cast_Ray -- cast a ray against this box *
795 * *
796 * INPUT: *
797 * *
798 * OUTPUT: *
799 * *
800 * WARNINGS: *
801 * *
802 * HISTORY: *
803 * 1/19/00 gth : Created. *
804 *=============================================================================================*/
806{
807 if ((Get_Collision_Type() & raytest.CollisionType) == 0) return false;
808 if (Is_Animation_Hidden()) return false;
809 if (raytest.Result->StartBad) return false;
810
811 if (CollisionMath::Collide(raytest.Ray,CachedBox,raytest.Result)) {
812 raytest.CollidedRenderObj = this;
813 return true;
814 }
815 return false;
816}
817
818
819/***********************************************************************************************
820 * AABoxRenderObjClass::Cast_AABox -- cast an AABox against this box *
821 * *
822 * INPUT: *
823 * *
824 * OUTPUT: *
825 * *
826 * WARNINGS: *
827 * *
828 * HISTORY: *
829 * 1/19/00 gth : Created. *
830 *=============================================================================================*/
832{
833 if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
834 if (boxtest.Result->StartBad) return false;
835
836 if (CollisionMath::Collide(boxtest.Box,boxtest.Move,CachedBox,boxtest.Result)) {
837 boxtest.CollidedRenderObj = this;
838 return true;
839 }
840 return false;
841}
842
843
844/***********************************************************************************************
845 * AABoxRenderObjClass::Cast_OBBox -- cast an OBBox against this box *
846 * *
847 * INPUT: *
848 * *
849 * OUTPUT: *
850 * *
851 * WARNINGS: *
852 * *
853 * HISTORY: *
854 * 1/19/00 gth : Created. *
855 *=============================================================================================*/
857{
858 if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
859 if (boxtest.Result->StartBad) return false;
860
861 if (CollisionMath::Collide(boxtest.Box,boxtest.Move,CachedBox,Vector3(0,0,0),boxtest.Result)) {
862 boxtest.CollidedRenderObj = this;
863 return true;
864 }
865 return false;
866}
867
868
869/***********************************************************************************************
870 * AABoxRenderObjClass::Intersect_AABox -- intersect this box with an AABox *
871 * *
872 * INPUT: *
873 * *
874 * OUTPUT: *
875 * *
876 * WARNINGS: *
877 * *
878 * HISTORY: *
879 * 1/19/00 gth : Created. *
880 *=============================================================================================*/
882{
883 if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
885}
886
887
888/***********************************************************************************************
889 * AABoxRenderObjClass::Intersect_OBBox -- Intersect this box with an OBBox *
890 * *
891 * INPUT: *
892 * *
893 * OUTPUT: *
894 * *
895 * WARNINGS: *
896 * *
897 * HISTORY: *
898 * 1/19/00 gth : Created. *
899 *=============================================================================================*/
901{
902 if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
904}
905
906
907/***********************************************************************************************
908 * AABoxRenderObjClass::Get_Obj_Space_Bounding_Sphere -- return the object-space bounding sphe *
909 * *
910 * INPUT: *
911 * *
912 * OUTPUT: *
913 * *
914 * WARNINGS: *
915 * *
916 * HISTORY: *
917 * 1/19/00 gth : Created. *
918 *=============================================================================================*/
923
924
925/***********************************************************************************************
926 * AABoxRenderObjClass::Get_Obj_Space_Bounding_Box -- returns the obj-space bounding box *
927 * *
928 * INPUT: *
929 * *
930 * OUTPUT: *
931 * *
932 * WARNINGS: *
933 * *
934 * HISTORY: *
935 * 1/19/00 gth : Created. *
936 *=============================================================================================*/
941
942
943/***********************************************************************************************
944 * OBBoxRenderObjClass::OBBoxRenderObjClass -- Constructor *
945 * *
946 * INPUT: *
947 * *
948 * OUTPUT: *
949 * *
950 * WARNINGS: *
951 * *
952 * HISTORY: *
953 * 1/19/00 gth : Created. *
954 *=============================================================================================*/
959
960
961/***********************************************************************************************
962 * OBBoxRenderObjClass::OBBoxRenderObjClass -- Constructor - initiallize from a definition *
963 * *
964 * INPUT: *
965 * *
966 * OUTPUT: *
967 * *
968 * WARNINGS: *
969 * *
970 * HISTORY: *
971 * 1/19/00 gth : Created. *
972 *=============================================================================================*/
978
979
980/***********************************************************************************************
981 * OBBoxRenderObjClass::OBBoxRenderObjClass -- copy constructor *
982 * *
983 * INPUT: *
984 * *
985 * OUTPUT: *
986 * *
987 * WARNINGS: *
988 * *
989 * HISTORY: *
990 * 1/19/00 gth : Created. *
991 *=============================================================================================*/
993{
994 *this = that;
995}
996
997
998/***********************************************************************************************
999 * OBBoxRenderObjClass::OBBoxRenderObjClass -- constructor - initialize from a wwmath obbox *
1000 * *
1001 * INPUT: *
1002 * *
1003 * OUTPUT: *
1004 * *
1005 * WARNINGS: *
1006 * *
1007 * HISTORY: *
1008 * 1/19/00 gth : Created. *
1009 *=============================================================================================*/
1011{
1012 ObjSpaceCenter.Set(Vector3(0,0,0));
1013 ObjSpaceExtent.Set(box.Extent);
1015 update_cached_box(); // cached box should == box!
1016}
1017
1018
1019/***********************************************************************************************
1020 * OBBoxRenderObjClass::operator -- assignment operator *
1021 * *
1022 * INPUT: *
1023 * *
1024 * OUTPUT: *
1025 * *
1026 * WARNINGS: *
1027 * *
1028 * HISTORY: *
1029 * 1/19/00 gth : Created. *
1030 *=============================================================================================*/
1032{
1033 if (this != &that) {
1035 CachedBox = that.CachedBox;
1036 }
1037 return *this;
1038}
1039
1040
1041/***********************************************************************************************
1042 * OBBoxRenderObjClass::Clone -- clone this obbox *
1043 * *
1044 * INPUT: *
1045 * *
1046 * OUTPUT: *
1047 * *
1048 * WARNINGS: *
1049 * *
1050 * HISTORY: *
1051 * 1/19/00 gth : Created. *
1052 *=============================================================================================*/
1054{
1055 return W3DNEW OBBoxRenderObjClass(*this);
1056}
1057
1058
1059/***********************************************************************************************
1060 * OBBoxRenderObjClass::Class_ID -- returns the class ID of OBBoxRenderObjClass *
1061 * *
1062 * INPUT: *
1063 * *
1064 * OUTPUT: *
1065 * *
1066 * WARNINGS: *
1067 * *
1068 * HISTORY: *
1069 * 1/19/00 gth : Created. *
1070 *=============================================================================================*/
1072{
1074}
1075
1076
1077/***********************************************************************************************
1078 * OBBoxRenderObjClass::Render -- render this obbox *
1079 * *
1080 * INPUT: *
1081 * *
1082 * OUTPUT: *
1083 * *
1084 * WARNINGS: *
1085 * *
1086 * HISTORY: *
1087 * 1/19/00 gth : Created. *
1088 *=============================================================================================*/
1094
1095
1096/***********************************************************************************************
1097 * OBBoxRenderObjClass::Special_Render -- special render (vis) *
1098 * *
1099 * INPUT: *
1100 * *
1101 * OUTPUT: *
1102 * *
1103 * WARNINGS: *
1104 * *
1105 * HISTORY: *
1106 * 1/19/00 gth : Created. *
1107 *=============================================================================================*/
1116
1117
1118/***********************************************************************************************
1119 * OBBoxRenderObjClass::Set_Transform -- set the transform for this box *
1120 * *
1121 * INPUT: *
1122 * *
1123 * OUTPUT: *
1124 * *
1125 * WARNINGS: *
1126 * *
1127 * HISTORY: *
1128 * 1/19/00 gth : Created. *
1129 *=============================================================================================*/
1135
1136
1137/***********************************************************************************************
1138 * OBBoxRenderObjClass::Set_Position -- set the position of this box *
1139 * *
1140 * INPUT: *
1141 * *
1142 * OUTPUT: *
1143 * *
1144 * WARNINGS: *
1145 * *
1146 * HISTORY: *
1147 * 1/19/00 gth : Created. *
1148 *=============================================================================================*/
1154
1155
1156/***********************************************************************************************
1157 * OBBoxRenderObjClass::update_cached_box -- update the cached world-space box *
1158 * *
1159 * INPUT: *
1160 * *
1161 * OUTPUT: *
1162 * *
1163 * WARNINGS: *
1164 * *
1165 * HISTORY: *
1166 * 1/19/00 gth : Created. *
1167 *=============================================================================================*/
1174
1175
1176/***********************************************************************************************
1177 * OBBoxRenderObjClass::Cast_Ray -- cast a ray against this box *
1178 * *
1179 * INPUT: *
1180 * *
1181 * OUTPUT: *
1182 * *
1183 * WARNINGS: *
1184 * *
1185 * HISTORY: *
1186 * 1/19/00 gth : Created. *
1187 *=============================================================================================*/
1189{
1190 if ((Get_Collision_Type() & raytest.CollisionType) == 0) return false;
1191 if (Is_Animation_Hidden()) return false;
1192 if (raytest.Result->StartBad) return false;
1193
1194 if (CollisionMath::Collide(raytest.Ray,CachedBox,raytest.Result)) {
1195 raytest.CollidedRenderObj = this;
1196 return true;
1197 }
1198 return false;
1199}
1200
1201
1202/***********************************************************************************************
1203 * OBBoxRenderObjClass::Cast_AABox -- cast a swept aabox against this box *
1204 * *
1205 * INPUT: *
1206 * *
1207 * OUTPUT: *
1208 * *
1209 * WARNINGS: *
1210 * *
1211 * HISTORY: *
1212 * 1/19/00 gth : Created. *
1213 *=============================================================================================*/
1215{
1216 if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
1217 if (boxtest.Result->StartBad) return false;
1218
1219 if (CollisionMath::Collide(boxtest.Box,boxtest.Move,CachedBox,Vector3(0,0,0),boxtest.Result)) {
1220 boxtest.CollidedRenderObj = this;
1221 return true;
1222 }
1223 return false;
1224}
1225
1226
1227/***********************************************************************************************
1228 * OBBoxRenderObjClass::Cast_OBBox -- cast a swept obbox against this bo *
1229 * *
1230 * INPUT: *
1231 * *
1232 * OUTPUT: *
1233 * *
1234 * WARNINGS: *
1235 * *
1236 * HISTORY: *
1237 * 1/19/00 gth : Created. *
1238 *=============================================================================================*/
1240{
1241 if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
1242 if (boxtest.Result->StartBad) return false;
1243
1244 if (CollisionMath::Collide(boxtest.Box,boxtest.Move,CachedBox,Vector3(0,0,0),boxtest.Result)) {
1245 boxtest.CollidedRenderObj = this;
1246 return true;
1247 }
1248 return false;
1249}
1250
1251
1252/***********************************************************************************************
1253 * OBBoxRenderObjClass::Intersect_AABox -- test this box for intersection with an AAbox *
1254 * *
1255 * INPUT: *
1256 * *
1257 * OUTPUT: *
1258 * *
1259 * WARNINGS: *
1260 * *
1261 * HISTORY: *
1262 * 1/19/00 gth : Created. *
1263 *=============================================================================================*/
1265{
1266 if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
1268}
1269
1270
1271/***********************************************************************************************
1272 * OBBoxRenderObjClass::Intersect_OBBox -- test this box for intersection with an OBBox *
1273 * *
1274 * INPUT: *
1275 * *
1276 * OUTPUT: *
1277 * *
1278 * WARNINGS: *
1279 * *
1280 * HISTORY: *
1281 * 1/19/00 gth : Created. *
1282 *=============================================================================================*/
1284{
1285 if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
1287}
1288
1289
1290/***********************************************************************************************
1291 * OBBoxRenderObjClass::Get_Obj_Space_Bounding_Sphere -- return the obj-space bounding sphere *
1292 * *
1293 * INPUT: *
1294 * *
1295 * OUTPUT: *
1296 * *
1297 * WARNINGS: *
1298 * *
1299 * HISTORY: *
1300 * 1/19/00 gth : Created. *
1301 *=============================================================================================*/
1306
1307
1308/***********************************************************************************************
1309 * OBBoxRenderObjClass::Get_Obj_Space_Bounding_Box -- returns the obj-space bounding box *
1310 * *
1311 * INPUT: *
1312 * *
1313 * OUTPUT: *
1314 * *
1315 * WARNINGS: *
1316 * *
1317 * HISTORY: *
1318 * 1/19/00 gth : Created. *
1319 *=============================================================================================*/
1324
1325
1326/***********************************************************************************************
1327 * OBBoxRenderObjClass::Get_Box -- returns the cached world-space box *
1328 * *
1329 * INPUT: *
1330 * *
1331 * OUTPUT: *
1332 * *
1333 * WARNINGS: *
1334 * *
1335 * HISTORY: *
1336 * 1/19/00 gth : Created. *
1337 *=============================================================================================*/
1344
1345/*
1346** BoxLoaderClass Implementation
1347*/
1349{
1350 W3dBoxStruct box;
1351 cload.Read(&box,sizeof(box));
1352 return W3DNEW BoxPrototypeClass(box);
1353}
1354
1355/*
1356** BoxPrototypeClass Implementation
1357*/
1359{
1360 Definition = box;
1361}
1362
1363const char * BoxPrototypeClass::Get_Name(void) const
1364{
1365 return Definition.Name;
1366}
1367
1369{
1370 if (Definition.Attributes & W3D_BOX_ATTRIBUTE_ORIENTED) {
1372 } else {
1374 }
1375}
1376
1378{
1379 if (Definition.Attributes & W3D_BOX_ATTRIBUTE_ORIENTED) {
1380 return NEW_REF( OBBoxRenderObjClass, (Definition) );
1381 } else {
1382 return NEW_REF( AABoxRenderObjClass, (Definition) );
1383 }
1384}
1385
1386/*
1387** Global instance of the box loader
1388*/
1390
1391
#define NULL
Definition BaseType.h:92
#define WWASSERT
#define W3D_BOX_ATTRIBUTE_COLLISION_TYPE_SHIFT
Definition w3d_file.h:2090
#define W3D_NAME_LEN
Definition w3d_file.h:319
#define W3D_BOX_ATTRIBUTE_ORIENTED
Definition w3d_file.h:2087
#define W3D_BOX_ATTRIBUTE_COLLISION_TYPE_MASK
Definition w3d_file.h:2089
#define W3DNEW
Definition always.h:109
unsigned long DWORD
Definition bittype.h:57
#define WWMATH_OOSQRT3
Definition wwmath.h:62
#define NUM_BOX_VERTS
Definition boxrobj.cpp:109
BoxLoaderClass _BoxLoader
Definition boxrobj.cpp:1389
#define NUM_BOX_FACES
Definition boxrobj.cpp:110
WWINLINE void Init(const Vector3 &center, const Vector3 &extent)
Definition aabox.h:101
Vector3 Center
Definition aabox.h:123
Vector3 Extent
Definition aabox.h:124
virtual void Get_Obj_Space_Bounding_Sphere(SphereClass &sphere) const
Definition boxrobj.cpp:919
virtual bool Intersect_AABox(AABoxIntersectionTestClass &boxtest)
Definition boxrobj.cpp:881
virtual void Special_Render(SpecialRenderInfoClass &rinfo)
Definition boxrobj.cpp:724
virtual void update_cached_box(void)
Definition boxrobj.cpp:786
virtual void Set_Position(const Vector3 &v)
Definition boxrobj.cpp:767
virtual bool Intersect_OBBox(OBBoxIntersectionTestClass &boxtest)
Definition boxrobj.cpp:900
virtual RenderObjClass * Clone(void) const
Definition boxrobj.cpp:667
virtual void Get_Obj_Space_Bounding_Box(AABoxClass &box) const
Definition boxrobj.cpp:937
AABoxRenderObjClass & operator=(const AABoxRenderObjClass &)
Definition boxrobj.cpp:645
AABoxClass CachedBox
Definition boxrobj.h:174
virtual bool Cast_Ray(RayCollisionTestClass &raytest)
Definition boxrobj.cpp:805
virtual void Set_Transform(const Matrix3D &m)
Definition boxrobj.cpp:748
virtual void Render(RenderInfoClass &rinfo)
Definition boxrobj.cpp:703
virtual bool Cast_OBBox(OBBoxCollisionTestClass &boxtest)
Definition boxrobj.cpp:856
virtual int Class_ID(void) const
Definition boxrobj.cpp:685
virtual bool Cast_AABox(AABoxCollisionTestClass &boxtest)
Definition boxrobj.cpp:831
virtual PrototypeClass * Load_W3D(ChunkLoadClass &cload)
Definition boxrobj.cpp:1348
virtual const char * Get_Name(void) const
Definition boxrobj.cpp:1363
BoxPrototypeClass(W3dBoxStruct box)
Definition boxrobj.cpp:1358
virtual RenderObjClass * Create(void)
Definition boxrobj.cpp:1377
virtual int Get_Class_ID(void) const
Definition boxrobj.cpp:1368
char Name[2 *W3D_NAME_LEN]
Definition boxrobj.h:109
void Set_Color(const Vector3 &color)
Definition boxrobj.cpp:327
static void Init(void)
Definition boxrobj.cpp:347
virtual int Get_Num_Polys(void) const
Definition boxrobj.cpp:271
static bool IsInitted
Definition boxrobj.h:115
BoxRenderObjClass(void)
Definition boxrobj.cpp:182
Vector3 ObjSpaceExtent
Definition boxrobj.h:112
static int Get_Box_Display_Mask(void)
Definition boxrobj.cpp:426
virtual void Set_Name(const char *name)
Definition boxrobj.cpp:307
static void Shutdown(void)
Definition boxrobj.cpp:384
void render_box(RenderInfoClass &rinfo, const Vector3 &center, const Vector3 &extent)
Definition boxrobj.cpp:444
BoxRenderObjClass & operator=(const BoxRenderObjClass &)
Definition boxrobj.cpp:246
void vis_render_box(SpecialRenderInfoClass &rinfo, const Vector3 &center, const Vector3 &extent)
Definition boxrobj.cpp:536
static void Set_Box_Display_Mask(int mask)
Definition boxrobj.cpp:408
Vector3 ObjSpaceCenter
Definition boxrobj.h:111
virtual const char * Get_Name(void) const
Definition boxrobj.cpp:289
static int DisplayMask
Definition boxrobj.h:116
uint32 Read(void *buf, uint32 nbytes)
Definition chunkio.cpp:692
static bool Collide(const LineSegClass &line, const AAPlaneClass &plane, CastResultStruct *result)
static bool Intersection_Test(const AABoxClass &box, const TriClass &tri)
CastResultStruct * Result
Definition coltest.h:98
RenderObjClass * CollidedRenderObj
Definition coltest.h:100
static void Set_Vertex_Buffer(const VertexBufferClass *vb, unsigned stream=0)
static void Set_Texture(unsigned stage, TextureBaseClass *texture)
static void Set_Index_Buffer(const IndexBufferClass *ib, unsigned short index_base_offset)
static Vector4 Convert_Color(unsigned color)
Definition dx8wrapper.h:958
static void Draw_Triangles(unsigned buffer_type, unsigned short start_index, unsigned short polygon_count, unsigned short min_vertex_index, unsigned short vertex_count)
static void Set_Material(const VertexMaterialClass *material)
static void Set_Shader(const ShaderClass &shader)
static void Set_Transform(D3DTRANSFORMSTATETYPE transform, const Matrix4x4 &m)
VertexFormatXYZNDUV2 * Get_Formatted_Vertex_Array()
void Translate(float x, float y, float z)
Definition matrix3d.h:670
static WWINLINE void Transform_Vector(const Matrix3D &tm, const Vector3 &in, Vector3 *out)
Definition matrix3d.h:1742
Vector3 Extent
Definition obbox.h:114
Matrix3x3 Basis
Definition obbox.h:112
Vector3 Center
Definition obbox.h:113
virtual bool Cast_AABox(AABoxCollisionTestClass &boxtest)
Definition boxrobj.cpp:1214
OBBoxClass & Get_Box(void)
Definition boxrobj.cpp:1338
virtual void Set_Transform(const Matrix3D &m)
Definition boxrobj.cpp:1130
OBBoxClass CachedBox
Definition boxrobj.h:225
virtual void Get_Obj_Space_Bounding_Sphere(SphereClass &sphere) const
Definition boxrobj.cpp:1302
virtual void Render(RenderInfoClass &rinfo)
Definition boxrobj.cpp:1089
virtual void Special_Render(SpecialRenderInfoClass &rinfo)
Definition boxrobj.cpp:1108
virtual void Set_Position(const Vector3 &v)
Definition boxrobj.cpp:1149
virtual bool Intersect_OBBox(OBBoxIntersectionTestClass &boxtest)
Definition boxrobj.cpp:1283
virtual bool Intersect_AABox(AABoxIntersectionTestClass &boxtest)
Definition boxrobj.cpp:1264
virtual int Class_ID(void) const
Definition boxrobj.cpp:1071
OBBoxRenderObjClass & operator=(const OBBoxRenderObjClass &)
Definition boxrobj.cpp:1031
virtual void update_cached_box(void)
Definition boxrobj.cpp:1168
virtual RenderObjClass * Clone(void) const
Definition boxrobj.cpp:1053
virtual bool Cast_Ray(RayCollisionTestClass &raytest)
Definition boxrobj.cpp:1188
virtual bool Cast_OBBox(OBBoxCollisionTestClass &boxtest)
Definition boxrobj.cpp:1239
virtual void Get_Obj_Space_Bounding_Box(AABoxClass &box) const
Definition boxrobj.cpp:1320
LineSegClass Ray
Definition coltest.h:139
virtual int Is_Animation_Hidden(void) const
Definition rendobj.h:473
virtual void Set_Transform(const Matrix3D &m)
Definition rendobj.cpp:423
virtual void Get_Obj_Space_Bounding_Sphere(SphereClass &sphere) const
Definition rendobj.cpp:932
RenderObjClass(void)
Definition rendobj.cpp:170
virtual void Set_Position(const Vector3 &v)
Definition rendobj.cpp:444
virtual void Set_Collision_Type(int type)
Definition rendobj.h:485
virtual const AABoxClass & Get_Bounding_Box(void) const
Definition rendobj.h:575
RenderObjClass & operator=(const RenderObjClass &)
Definition rendobj.cpp:232
virtual void Validate_Transform(void) const
Definition rendobj.cpp:464
Matrix3D Transform
Definition rendobj.h:549
virtual int Get_Collision_Type(void) const
Definition rendobj.h:484
static ShaderClass _PresetAlphaSolidShader
Definition shader.h:417
VisRasterizerClass * VisRasterizer
Definition rinfo.h:153
void Init(const Vector3 &pos, float radius)
Definition sphere.h:248
float X
Definition vector3.h:90
float Z
Definition vector3.h:92
float Y
Definition vector3.h:91
void Set_Model_Transform(const Matrix3D &model)
bool Render_Triangles(const Vector3 *verts, int vcount, const TriIndex *tris, int tcount, const AABoxClass &bounds)
static void Convert_Vector(const W3dVectorStruct &v, Vector3 *set)
Definition w3d_util.cpp:45
static void Convert_Color(const W3dRGBStruct &rgb, Vector3 *set)
Definition w3d_util.cpp:75
const unsigned dynamic_fvf_type
@ BUFFER_TYPE_DYNAMIC_DX8
Definition dx8wrapper.h:90
Vector3i16 TriIndex
#define REF_PTR_RELEASE(x)
Definition refcount.h:80
#define NEW_REF(C, P)
Definition refcount.h:62
W3dVectorStruct Extent
Definition w3d_file.h:2104
uint32 Attributes
Definition w3d_file.h:2100
W3dVectorStruct Center
Definition w3d_file.h:2103
char Name[2 *W3D_NAME_LEN]
Definition w3d_file.h:2101
W3dRGBStruct Color
Definition w3d_file.h:2102