Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
composite.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/composite.cpp $*
26 * *
27 * Author:: Greg Hjelstrom *
28 * *
29 * $Modtime:: 11/27/01 12:45a $*
30 * *
31 * $Revision:: 6 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * CompositeRenderObjClass::CompositeRenderObjClass -- Constructor *
36 * CompositeRenderObjClass::CompositeRenderObjClass -- copy constructor *
37 * CompositeRenderObjClass::~CompositeRenderObjClass -- Destructor *
38 * CompositeRenderObjClass::operator -- assignment operator *
39 * CompositeRenderObjClass::Restart -- Recursively call Restart on all sub-objects *
40 * CompositeRenderObjClass::Get_Name -- returns the name of this render object *
41 * CompositeRenderObjClass::Set_Name -- sets the name of this render object *
42 * CompositeRenderObjClass::Set_Base_Model_Name -- sets the "base-model-name" *
43 * CompositeRenderObjClass::Get_Num_Polys -- returns the number of polys *
44 * CompositeRenderObjClass::Notify_Added -- notify all sub-objects that they were added *
45 * CompositeRenderObjClass::Notify_Removed -- notifies all subobjs they were removed from th *
46 * CompositeRenderObjClass::Cast_Ray -- cast a ray against this object *
47 * CompositeRenderObjClass::Cast_AABox -- cast a swept AABox against this object *
48 * CompositeRenderObjClass::Cast_OBBox -- cast a swept OBBox against this object *
49 * CompositeRenderObjClass::Intersect_AABox -- intersect this object with an AABox *
50 * CompositeRenderObjClass::Intersect_OBBox -- intersect this object with an OBBox *
51 * CompositeRenderObjClass::Create_Decal -- create a decal on this object *
52 * CompositeRenderObjClass::Delete_Decal -- remove a logical decal from this object *
53 * CompositeRenderObjClass::Update_Obj_Space_Bounding_Volumes -- updates the object-space BV *
54 * CompositeRenderObjClass::Set_User_Data -- set the userdata pointer *
55 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
56
57
58#include "composite.h"
59#include "wwdebug.h"
60#include <stdlib.h>
61#include <string.h>
62
63
64/***********************************************************************************************
65 * CompositeRenderObjClass::CompositeRenderObjClass -- Constructor *
66 * *
67 * INPUT: *
68 * *
69 * OUTPUT: *
70 * *
71 * WARNINGS: *
72 * *
73 * HISTORY: *
74 *=============================================================================================*/
78
79
80/***********************************************************************************************
81 * CompositeRenderObjClass::CompositeRenderObjClass -- copy constructor *
82 * *
83 * INPUT: *
84 * *
85 * OUTPUT: *
86 * *
87 * WARNINGS: *
88 * *
89 * HISTORY: *
90 * 1/26/00 gth : Created. *
91 *=============================================================================================*/
97
98
99/***********************************************************************************************
100 * CompositeRenderObjClass::~CompositeRenderObjClass -- Destructor *
101 * *
102 * INPUT: *
103 * *
104 * OUTPUT: *
105 * *
106 * WARNINGS: *
107 * *
108 * HISTORY: *
109 * 1/26/00 gth : Created. *
110 *=============================================================================================*/
114
115
116/***********************************************************************************************
117 * CompositeRenderObjClass::operator -- assignment operator *
118 * *
119 * INPUT: *
120 * *
121 * OUTPUT: *
122 * *
123 * WARNINGS: *
124 * *
125 * HISTORY: *
126 * 1/26/00 gth : Created. *
127 *=============================================================================================*/
134
135
136/***********************************************************************************************
137 * CompositeRenderObjClass::Restart -- Recursively call Restart on all sub-objects *
138 * *
139 * INPUT: *
140 * *
141 * OUTPUT: *
142 * *
143 * WARNINGS: *
144 * *
145 * HISTORY: *
146 * 5/30/2001 gth : Created. *
147 *=============================================================================================*/
149{
150 for (int ni = 0; ni < Get_Num_Sub_Objects(); ni++) {
151 RenderObjClass * robj = Get_Sub_Object(ni);
152 WWASSERT(robj);
153 robj->Restart();
154 robj->Release_Ref();
155 }
156}
157
158/***********************************************************************************************
159 * CompositeRenderObjClass::Get_Name -- returns the name of this render object *
160 * *
161 * INPUT: *
162 * *
163 * OUTPUT: *
164 * *
165 * WARNINGS: *
166 * *
167 * HISTORY: *
168 * 1/26/00 gth : Created. *
169 *=============================================================================================*/
170const char * CompositeRenderObjClass::Get_Name(void) const
171{
172 return Name;
173}
174
175
176/***********************************************************************************************
177 * CompositeRenderObjClass::Set_Name -- sets the name of this render object *
178 * *
179 * INPUT: *
180 * *
181 * OUTPUT: *
182 * *
183 * WARNINGS: *
184 * *
185 * HISTORY: *
186 * 1/26/00 gth : Created. *
187 *=============================================================================================*/
188void CompositeRenderObjClass::Set_Name(const char * name)
189{
190 Name=name;
191}
192
193
194/***********************************************************************************************
195 * CompositeRenderObjClass::Set_Base_Model_Name -- sets the "base-model-name" *
196 * *
197 * The base-model-name was needed by the aggregate code. Ask Patrick Smith about it :-) *
198 * *
199 * INPUT: *
200 * *
201 * OUTPUT: *
202 * *
203 * WARNINGS: *
204 * *
205 * HISTORY: *
206 * 1/26/00 gth : Created. *
207 *=============================================================================================*/
209{
210 // NULL is a legal value for BaseModelName. Unfortunately,
211 // StringClass::operator= does not modify the string when
212 // assigning NULL, so we explicitly handle that case here.
213 if (name != 0) {
214 BaseModelName = name;
215 } else {
216 BaseModelName = "";
217 }
218}
219
220
221/***********************************************************************************************
222 * CompositeRenderObjClass::Get_Num_Polys -- returns the number of polys *
223 * *
224 * INPUT: *
225 * *
226 * OUTPUT: *
227 * *
228 * WARNINGS: *
229 * *
230 * HISTORY: *
231 * 1/26/00 gth : Created. *
232 *=============================================================================================*/
234{
235 int count = 0;
236 for (int ni = 0; ni < Get_Num_Sub_Objects(); ni++) {
237 RenderObjClass * robj = Get_Sub_Object(ni);
238 WWASSERT(robj);
239 count += robj->Get_Num_Polys();
240 robj->Release_Ref();
241 }
242 return count;
243}
244
245
246/***********************************************************************************************
247 * CompositeRenderObjClass::Notify_Added -- notify all sub-objects that they were added *
248 * *
249 * INPUT: *
250 * *
251 * OUTPUT: *
252 * *
253 * WARNINGS: *
254 * *
255 * HISTORY: *
256 * 1/26/00 gth : Created. *
257 *=============================================================================================*/
259{
261 for (int ni = 0; ni < Get_Num_Sub_Objects(); ni++) {
262 RenderObjClass * robj = Get_Sub_Object(ni);
263 WWASSERT(robj);
264 robj->Notify_Added(scene);
265 robj->Release_Ref();
266 }
267}
268
269
270/***********************************************************************************************
271 * CompositeRenderObjClass::Notify_Removed -- notifies all subobjs they were removed from the *
272 * *
273 * INPUT: *
274 * *
275 * OUTPUT: *
276 * *
277 * WARNINGS: *
278 * *
279 * HISTORY: *
280 * 1/26/00 gth : Created. *
281 *=============================================================================================*/
283{
284 for (int ni = 0; ni < Get_Num_Sub_Objects(); ni++) {
285 RenderObjClass * robj = Get_Sub_Object(ni);
286 WWASSERT(robj);
287 robj->Notify_Removed(scene);
288 robj->Release_Ref();
289 }
291}
292
293
294/***********************************************************************************************
295 * CompositeRenderObjClass::Cast_Ray -- cast a ray against this object *
296 * *
297 * INPUT: *
298 * *
299 * OUTPUT: *
300 * *
301 * WARNINGS: *
302 * *
303 * HISTORY: *
304 * 1/26/00 gth : Created. *
305 *=============================================================================================*/
307{
308 bool res = false;
309 for (int i=0; i<Get_Num_Sub_Objects(); i++) {
310 RenderObjClass * robj = Get_Sub_Object(i);
311 WWASSERT(robj);
312 res |= robj->Cast_Ray(raytest);
313 robj->Release_Ref();
314 }
315 return res;
316}
317
318
319/***********************************************************************************************
320 * CompositeRenderObjClass::Cast_AABox -- cast a swept AABox against this object *
321 * *
322 * INPUT: *
323 * *
324 * OUTPUT: *
325 * *
326 * WARNINGS: *
327 * *
328 * HISTORY: *
329 * 1/26/00 gth : Created. *
330 *=============================================================================================*/
332{
333 bool res = false;
334 for (int i=0; i<Get_Num_Sub_Objects(); i++) {
335 RenderObjClass * robj = Get_Sub_Object(i);
336 WWASSERT(robj);
337 res |= robj->Cast_AABox(boxtest);
338 robj->Release_Ref();
339 }
340 return res;
341}
342
343
344/***********************************************************************************************
345 * CompositeRenderObjClass::Cast_OBBox -- cast a swept OBBox against this object *
346 * *
347 * INPUT: *
348 * *
349 * OUTPUT: *
350 * *
351 * WARNINGS: *
352 * *
353 * HISTORY: *
354 * 1/26/00 gth : Created. *
355 *=============================================================================================*/
357{
358 bool res = false;
359 for (int i=0; i<Get_Num_Sub_Objects(); i++) {
360 RenderObjClass * robj = Get_Sub_Object(i);
361 WWASSERT(robj);
362 res |= robj->Cast_OBBox(boxtest);
363 robj->Release_Ref();
364 }
365 return res;
366}
367
368
369/***********************************************************************************************
370 * CompositeRenderObjClass::Intersect_AABox -- intersect this object with an AABox *
371 * *
372 * INPUT: *
373 * *
374 * OUTPUT: *
375 * *
376 * WARNINGS: *
377 * *
378 * HISTORY: *
379 * 1/26/00 gth : Created. *
380 *=============================================================================================*/
382{
383 bool res = false;
384 for (int i=0; i<Get_Num_Sub_Objects(); i++) {
385 RenderObjClass * robj = Get_Sub_Object(i);
386 WWASSERT(robj);
387 res |= robj->Intersect_AABox(boxtest);
388 robj->Release_Ref();
389 }
390 return res;
391}
392
393
394/***********************************************************************************************
395 * CompositeRenderObjClass::Intersect_OBBox -- intersect this object with an OBBox *
396 * *
397 * INPUT: *
398 * *
399 * OUTPUT: *
400 * *
401 * WARNINGS: *
402 * *
403 * HISTORY: *
404 * 1/26/00 gth : Created. *
405 *=============================================================================================*/
407{
408 bool res = false;
409 for (int i=0; i<Get_Num_Sub_Objects(); i++) {
410 RenderObjClass * robj = Get_Sub_Object(i);
411 WWASSERT(robj);
412 res |= robj->Intersect_OBBox(boxtest);
413 robj->Release_Ref();
414 }
415 return res;
416}
417
418
419/***********************************************************************************************
420 * CompositeRenderObjClass::Create_Decal -- create a decal on this object *
421 * *
422 * INPUT: *
423 * *
424 * OUTPUT: *
425 * *
426 * WARNINGS: *
427 * *
428 * HISTORY: *
429 * 1/26/00 gth : Created. *
430 *=============================================================================================*/
432{
433 for (int i=0; i<Get_Num_Sub_Objects(); i++) {
434 RenderObjClass * robj = Get_Sub_Object(i);
435 WWASSERT(robj);
436 robj->Create_Decal(generator);
437 robj->Release_Ref();
438 }
439}
440
441
442/***********************************************************************************************
443 * CompositeRenderObjClass::Delete_Decal -- remove a logical decal from this object *
444 * *
445 * This internally removes all decals with the given ID. The ID comes from the generator *
446 * which was used to create the decals. *
447 * *
448 * INPUT: *
449 * *
450 * OUTPUT: *
451 * *
452 * WARNINGS: *
453 * *
454 * HISTORY: *
455 * 1/26/00 gth : Created. *
456 *=============================================================================================*/
458{
459 for (int i=0; i<Get_Num_Sub_Objects(); i++) {
460 RenderObjClass * robj = Get_Sub_Object(i);
461 WWASSERT(robj);
462 robj->Delete_Decal(decal_id);
463 robj->Release_Ref();
464 }
465}
466
467
468/***********************************************************************************************
469 * CompositeRenderObjClass::Update_Obj_Space_Bounding_Volumes -- updates the object-space BVs *
470 * *
471 * INPUT: *
472 * *
473 * OUTPUT: *
474 * *
475 * WARNINGS: *
476 * *
477 * HISTORY: *
478 * 1/26/00 gth : Created. *
479 *=============================================================================================*/
481{
482 int i;
483 RenderObjClass * robj = NULL;
484
485 // if we don't have any sub objects, just set default bounds
486 if (Get_Num_Sub_Objects() <= 0) {
487 ObjSphere.Init(Vector3(0,0,0),0);
488 ObjBox.Center.Set(0,0,0);
489 ObjBox.Extent.Set(0,0,0);
490 return;
491 }
492
493
494 AABoxClass obj_aabox;
496 SphereClass sphere;
497
498 // loop through all sub-objects, combining their object-space bounding spheres and boxes.
499 robj = Get_Sub_Object(0);
500 WWASSERT(robj);
502 robj->Get_Obj_Space_Bounding_Box(obj_aabox);
503 robj->Release_Ref();
504 box.Init(obj_aabox);
505
506 for (i=1; i<Get_Num_Sub_Objects(); i++) {
507
508 robj = Get_Sub_Object(i);
509 WWASSERT(robj);
510
511 robj->Get_Obj_Space_Bounding_Sphere(sphere);
512 robj->Get_Obj_Space_Bounding_Box(obj_aabox);
513
514 ObjSphere.Add_Sphere(sphere);
515 box.Add_Box(obj_aabox);
516
517 robj->Release_Ref();
518 }
519
520 ObjBox.Init(box);
521
523
524 // Now update the object space bounding volumes of this object's container:
525 RenderObjClass *container = Get_Container();
526 if (container) container->Update_Obj_Space_Bounding_Volumes();
527}
528
529/***********************************************************************************************
530 * CompositeRenderObjClass::Set_User_Data -- set the userdata *
531 * *
532 * INPUT: *
533 * *
534 * OUTPUT: *
535 * *
536 * WARNINGS: *
537 * *
538 * HISTORY: *
539 * 1/26/00 gth : Created. *
540 *=============================================================================================*/
542{
544 if (recursive) {
545 for (int i=0; i<Get_Num_Sub_Objects(); i++) {
546 RenderObjClass * robj = Get_Sub_Object(i);
547 WWASSERT(robj);
548 robj->Set_User_Data(value,recursive);
549 robj->Release_Ref();
550 }
551 }
552}
553
555{
556 if (BaseModelName.Is_Empty()) {
557 return NULL;
558 }
559
560 return BaseModelName;
561}
#define NULL
Definition BaseType.h:92
void const char * value
#define WWASSERT
unsigned long uint32
Definition bittype.h:46
virtual void Set_User_Data(void *value, bool recursive=false)
virtual void Notify_Removed(SceneClass *scene)
virtual ~CompositeRenderObjClass(void)
virtual void Notify_Added(SceneClass *scene)
CompositeRenderObjClass & operator=(const CompositeRenderObjClass &that)
virtual void Create_Decal(DecalGeneratorClass *generator)
virtual int Get_Num_Polys(void) const
virtual const char * Get_Name(void) const
virtual void Delete_Decal(uint32 decal_id)
virtual void Set_Name(const char *name)
virtual bool Cast_AABox(AABoxCollisionTestClass &boxtest)
virtual bool Intersect_AABox(AABoxIntersectionTestClass &boxtest)
virtual void Restart(void)
virtual bool Cast_Ray(RayCollisionTestClass &raytest)
virtual bool Cast_OBBox(OBBoxCollisionTestClass &boxtest)
StringClass BaseModelName
Definition composite.h:92
SphereClass ObjSphere
Definition composite.h:93
virtual const char * Get_Base_Model_Name(void) const
virtual bool Intersect_OBBox(OBBoxIntersectionTestClass &boxtest)
virtual void Set_Base_Model_Name(const char *name)
virtual void Update_Obj_Space_Bounding_Volumes(void)
void Add_Box(const MinMaxAABoxClass &box)
Definition aabox.h:586
WWINLINE void Init(Vector3 *points, int num)
Definition aabox.h:523
WWINLINE void Release_Ref(void) const
Definition refcount.h:146
virtual void Create_Decal(DecalGeneratorClass *generator)
Definition rendobj.h:438
virtual void Set_User_Data(void *value, bool recursive=false)
Definition rendobj.h:445
virtual void Get_Obj_Space_Bounding_Sphere(SphereClass &sphere) const
Definition rendobj.cpp:932
RenderObjClass(void)
Definition rendobj.cpp:170
virtual void Update_Obj_Space_Bounding_Volumes(void)
Definition rendobj.h:394
virtual void Notify_Added(SceneClass *scene)
Definition rendobj.cpp:862
virtual void Delete_Decal(uint32 decal_id)
Definition rendobj.h:439
virtual void Get_Obj_Space_Bounding_Box(AABoxClass &box) const
Definition rendobj.cpp:952
void Invalidate_Cached_Bounding_Volumes(void) const
Definition rendobj.h:523
virtual bool Intersect_OBBox(OBBoxIntersectionTestClass &boxtest)
Definition rendobj.h:381
virtual void Notify_Removed(SceneClass *scene)
Definition rendobj.cpp:884
virtual void Restart(void)
Definition rendobj.h:271
virtual int Get_Num_Sub_Objects(void) const
Definition rendobj.h:309
virtual bool Cast_AABox(AABoxCollisionTestClass &boxtest)
Definition rendobj.h:377
virtual bool Cast_Ray(RayCollisionTestClass &raytest)
Definition rendobj.h:376
friend class SceneClass
Definition rendobj.h:563
virtual bool Cast_OBBox(OBBoxCollisionTestClass &boxtest)
Definition rendobj.h:378
RenderObjClass * Get_Container(void) const
Definition rendobj.h:291
virtual RenderObjClass * Get_Sub_Object(int index) const
Definition rendobj.h:310
virtual int Get_Num_Polys(void) const
Definition rendobj.h:254
virtual bool Intersect_AABox(AABoxIntersectionTestClass &boxtest)
Definition rendobj.h:380