boxrobj.cpp 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  1. /*
  2. ** Command & Conquer Generals(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. *** 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 ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WW3D *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/boxrobj.cpp $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 7/05/01 4:11p $*
  29. * *
  30. * $Revision:: 27 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * BoxRenderObjClass::BoxRenderObjClass -- Constructor *
  35. * BoxRenderObjClass::BoxRenderObjClass -- Constructor - init from a definition *
  36. * BoxRenderObjClass::BoxRenderObjClass -- Copy constructor *
  37. * BoxRenderObjClass::operator -- assignment operator *
  38. * BoxRenderObjClass::Get_Num_Polys -- returns number of polygons *
  39. * BoxRenderObjClass::Get_Name -- returns name *
  40. * BoxRenderObjClass::Set_Name -- sets the name *
  41. * BoxRenderObjClass::Set_Color -- Sets the color of the box *
  42. * BoxRenderObjClass::Init_Box_Render_System -- global initialization needed for boxes to wo *
  43. * BoxRenderObjClass::Shutdown_Box_Render_System -- cleanup box render system *
  44. * BoxRenderObjClass::Set_Box_Display_Mask -- Sets global display mask for all boxes *
  45. * BoxRenderObjClass::Get_Box_Display_Mask -- returns the display mask *
  46. * BoxRenderObjClass::render_box -- submits the box to the GERD *
  47. * BoxRenderObjClass::vis_render_box -- submits box to the GERD for VIS *
  48. * AABoxRenderObjClass::AABoxRenderObjClass -- constructor *
  49. * AABoxRenderObjClass::AABoxRenderObjClass -- Constructor - init from a definition *
  50. * AABoxRenderObjClass::AABoxRenderObjClass -- copy constructor *
  51. * AABoxRenderObjClass::AABoxRenderObjClass -- Constructor from a wwmath aabox *
  52. * AABoxRenderObjClass::operator -- assignment operator *
  53. * AABoxRenderObjClass::Clone -- clones the box *
  54. * AABoxRenderObjClass::Class_ID -- returns the class-id for AABox's *
  55. * AABoxRenderObjClass::Render -- render this box *
  56. * AABoxRenderObjClass::Special_Render -- special render this box (vis) *
  57. * AABoxRenderObjClass::Set_Transform -- set the transform for this box *
  58. * AABoxRenderObjClass::Set_Position -- Set the position of this box *
  59. * AABoxRenderObjClass::update_cached_box -- update the world-space version of this box *
  60. * AABoxRenderObjClass::Cast_Ray -- cast a ray against this box *
  61. * AABoxRenderObjClass::Cast_AABox -- cast an AABox against this box *
  62. * AABoxRenderObjClass::Cast_OBBox -- cast an OBBox against this box *
  63. * AABoxRenderObjClass::Intersect_AABox -- intersect this box with an AABox *
  64. * AABoxRenderObjClass::Intersect_OBBox -- Intersect this box with an OBBox *
  65. * AABoxRenderObjClass::Get_Obj_Space_Bounding_Sphere -- return the object-space bounding sp *
  66. * AABoxRenderObjClass::Get_Obj_Space_Bounding_Box -- returns the obj-space bounding box *
  67. * OBBoxRenderObjClass::OBBoxRenderObjClass -- Constructor *
  68. * OBBoxRenderObjClass::OBBoxRenderObjClass -- Constructor - initiallize from a definition *
  69. * OBBoxRenderObjClass::OBBoxRenderObjClass -- copy constructor *
  70. * OBBoxRenderObjClass::OBBoxRenderObjClass -- constructor - initialize from a wwmath obbox *
  71. * OBBoxRenderObjClass::operator -- assignment operator *
  72. * OBBoxRenderObjClass::Clone -- clone this obbox *
  73. * OBBoxRenderObjClass::Class_ID -- returns the class ID of OBBoxRenderObjClass *
  74. * OBBoxRenderObjClass::Render -- render this obbox *
  75. * OBBoxRenderObjClass::Special_Render -- special render (vis) *
  76. * OBBoxRenderObjClass::Set_Transform -- set the transform for this box *
  77. * OBBoxRenderObjClass::Set_Position -- set the position of this box *
  78. * OBBoxRenderObjClass::update_cached_box -- update the cached world-space box *
  79. * OBBoxRenderObjClass::Cast_Ray -- cast a ray against this box *
  80. * OBBoxRenderObjClass::Cast_AABox -- cast a swept aabox against this box *
  81. * OBBoxRenderObjClass::Cast_OBBox -- cast a swept obbox against this bo *
  82. * OBBoxRenderObjClass::Intersect_AABox -- test this box for intersection with an AAbox *
  83. * OBBoxRenderObjClass::Intersect_OBBox -- test this box for intersection with an OBBox *
  84. * OBBoxRenderObjClass::Get_Obj_Space_Bounding_Sphere -- return the obj-space bounding spher *
  85. * OBBoxRenderObjClass::Get_Obj_Space_Bounding_Box -- returns the obj-space bounding box *
  86. * OBBoxRenderObjClass::Get_Box -- returns the cached world-space box *
  87. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  88. #include "boxrobj.h"
  89. #include "w3d_util.h"
  90. #include "wwdebug.h"
  91. #include "vertmaterial.h"
  92. #include "ww3d.h"
  93. #include "chunkio.h"
  94. #include "rinfo.h"
  95. #include "coltest.h"
  96. #include "inttest.h"
  97. #include "dx8wrapper.h"
  98. #include "dx8indexbuffer.h"
  99. #include "dx8vertexbuffer.h"
  100. #include "dx8fvf.h"
  101. #include "sortingrenderer.h"
  102. #include "visrasterizer.h"
  103. #define NUM_BOX_VERTS 8
  104. #define NUM_BOX_FACES 12
  105. // Face Connectivity
  106. static Vector3i _BoxFaces[NUM_BOX_FACES] =
  107. {
  108. Vector3i( 0,1,2 ), // +z faces
  109. Vector3i( 0,2,3 ),
  110. Vector3i( 4,7,6 ), // -z faces
  111. Vector3i( 4,6,5 ),
  112. Vector3i( 0,3,7 ), // +x faces
  113. Vector3i( 0,7,4 ),
  114. Vector3i( 1,5,6 ), // -x faces
  115. Vector3i( 1,6,2 ),
  116. Vector3i( 4,5,1 ), // +y faces
  117. Vector3i( 4,1,0 ),
  118. Vector3i( 3,2,6 ), // -y faces
  119. Vector3i( 3,6,7 )
  120. };
  121. // Vertex Positions as a function of the box extents
  122. static Vector3 _BoxVerts[NUM_BOX_VERTS] =
  123. {
  124. Vector3( 1.0f, 1.0f, 1.0f ), // +z ring of 4 verts
  125. Vector3( -1.0f, 1.0f, 1.0f ),
  126. Vector3( -1.0f,-1.0f, 1.0f ),
  127. Vector3( 1.0f,-1.0f, 1.0f ),
  128. Vector3( 1.0f, 1.0f,-1.0f ), // -z ring of 4 verts;
  129. Vector3( -1.0f, 1.0f,-1.0f ),
  130. Vector3( -1.0f,-1.0f,-1.0f ),
  131. Vector3( 1.0f,-1.0f,-1.0f ),
  132. };
  133. // Vertex Normals
  134. static Vector3 _BoxVertexNormals[NUM_BOX_VERTS] =
  135. {
  136. Vector3( WWMATH_OOSQRT3, WWMATH_OOSQRT3, WWMATH_OOSQRT3 ),
  137. Vector3(-WWMATH_OOSQRT3, WWMATH_OOSQRT3, WWMATH_OOSQRT3 ),
  138. Vector3(-WWMATH_OOSQRT3,-WWMATH_OOSQRT3, WWMATH_OOSQRT3 ),
  139. Vector3( WWMATH_OOSQRT3,-WWMATH_OOSQRT3, WWMATH_OOSQRT3 ),
  140. Vector3( WWMATH_OOSQRT3, WWMATH_OOSQRT3,-WWMATH_OOSQRT3 ),
  141. Vector3(-WWMATH_OOSQRT3, WWMATH_OOSQRT3,-WWMATH_OOSQRT3 ),
  142. Vector3(-WWMATH_OOSQRT3,-WWMATH_OOSQRT3,-WWMATH_OOSQRT3 ),
  143. Vector3( WWMATH_OOSQRT3,-WWMATH_OOSQRT3,-WWMATH_OOSQRT3 ),
  144. };
  145. bool BoxRenderObjClass::IsInitted = false;
  146. int BoxRenderObjClass::DisplayMask = 0;
  147. static VertexMaterialClass * _BoxMaterial = NULL;
  148. static ShaderClass _BoxShader;
  149. /*
  150. ** BoxRenderObjClass Implementation
  151. */
  152. /***********************************************************************************************
  153. * BoxRenderObjClass::BoxRenderObjClass -- Constructor *
  154. * *
  155. * INPUT: *
  156. * *
  157. * OUTPUT: *
  158. * *
  159. * WARNINGS: *
  160. * *
  161. * HISTORY: *
  162. * 1/19/00 gth : Created. *
  163. *=============================================================================================*/
  164. BoxRenderObjClass::BoxRenderObjClass(void)
  165. {
  166. memset(Name,0,sizeof(Name));
  167. Color.Set(1,1,1);
  168. ObjSpaceCenter.Set(0,0,0);
  169. ObjSpaceExtent.Set(1,1,1);
  170. }
  171. /***********************************************************************************************
  172. * BoxRenderObjClass::BoxRenderObjClass -- Constructor - init from a definition *
  173. * *
  174. * INPUT: *
  175. * *
  176. * OUTPUT: *
  177. * *
  178. * WARNINGS: *
  179. * *
  180. * HISTORY: *
  181. * 1/19/00 gth : Created. *
  182. *=============================================================================================*/
  183. BoxRenderObjClass::BoxRenderObjClass(const W3dBoxStruct & def)
  184. {
  185. Set_Name(def.Name);
  186. W3dUtilityClass::Convert_Color(def.Color,&Color);
  187. W3dUtilityClass::Convert_Vector(def.Center,&ObjSpaceCenter);
  188. W3dUtilityClass::Convert_Vector(def.Extent,&ObjSpaceExtent);
  189. int col_bits = (def.Attributes & W3D_BOX_ATTRIBUTE_COLLISION_TYPE_MASK) >> W3D_BOX_ATTRIBUTE_COLLISION_TYPE_SHIFT;
  190. Set_Collision_Type(col_bits<<1);
  191. }
  192. /***********************************************************************************************
  193. * BoxRenderObjClass::BoxRenderObjClass -- Copy constructor *
  194. * *
  195. * INPUT: *
  196. * *
  197. * OUTPUT: *
  198. * *
  199. * WARNINGS: *
  200. * *
  201. * HISTORY: *
  202. * 1/19/00 gth : Created. *
  203. *=============================================================================================*/
  204. BoxRenderObjClass::BoxRenderObjClass(const BoxRenderObjClass & src)
  205. {
  206. *this = src;
  207. }
  208. /***********************************************************************************************
  209. * BoxRenderObjClass::operator -- assignment operator *
  210. * *
  211. * INPUT: *
  212. * *
  213. * OUTPUT: *
  214. * *
  215. * WARNINGS: *
  216. * *
  217. * HISTORY: *
  218. * 1/19/00 gth : Created. *
  219. *=============================================================================================*/
  220. BoxRenderObjClass & BoxRenderObjClass::operator = (const BoxRenderObjClass & that)
  221. {
  222. if (this != &that) {
  223. RenderObjClass::operator = (that);
  224. Set_Name(that.Get_Name());
  225. Color.Set(that.Color);
  226. ObjSpaceCenter.Set(that.ObjSpaceCenter);
  227. ObjSpaceExtent.Set(that.ObjSpaceExtent);
  228. }
  229. return *this;
  230. }
  231. /***********************************************************************************************
  232. * BoxRenderObjClass::Get_Num_Polys -- returns number of polygons *
  233. * *
  234. * INPUT: *
  235. * *
  236. * OUTPUT: *
  237. * *
  238. * WARNINGS: *
  239. * *
  240. * HISTORY: *
  241. * 1/19/00 gth : Created. *
  242. *=============================================================================================*/
  243. int BoxRenderObjClass::Get_Num_Polys(void) const
  244. {
  245. return 12;
  246. }
  247. /***********************************************************************************************
  248. * BoxRenderObjClass::Get_Name -- returns name *
  249. * *
  250. * INPUT: *
  251. * *
  252. * OUTPUT: *
  253. * *
  254. * WARNINGS: *
  255. * *
  256. * HISTORY: *
  257. * 1/19/00 gth : Created. *
  258. *=============================================================================================*/
  259. const char * BoxRenderObjClass::Get_Name(void) const
  260. {
  261. return Name;
  262. }
  263. /***********************************************************************************************
  264. * BoxRenderObjClass::Set_Name -- sets the name *
  265. * *
  266. * INPUT: *
  267. * *
  268. * OUTPUT: *
  269. * *
  270. * WARNINGS: *
  271. * *
  272. * HISTORY: *
  273. * 1/19/00 gth : Created. *
  274. *=============================================================================================*/
  275. void BoxRenderObjClass::Set_Name(const char * name)
  276. {
  277. WWASSERT(name != NULL);
  278. WWASSERT(strlen(name) < 2*W3D_NAME_LEN);
  279. strcpy(Name,name);
  280. }
  281. /***********************************************************************************************
  282. * BoxRenderObjClass::Set_Color -- Sets the color of the box *
  283. * *
  284. * INPUT: *
  285. * *
  286. * OUTPUT: *
  287. * *
  288. * WARNINGS: *
  289. * *
  290. * HISTORY: *
  291. * 1/19/00 gth : Created. *
  292. *=============================================================================================*/
  293. void BoxRenderObjClass::Set_Color(const Vector3 & color)
  294. {
  295. Color = color;
  296. }
  297. /***********************************************************************************************
  298. * BoxRenderObjClass::Init_Box_Render_System -- global initialization needed for boxes to work *
  299. * *
  300. * Allocates materials which all boxes share. Initializes vertex tables, etc *
  301. * *
  302. * INPUT: *
  303. * *
  304. * OUTPUT: *
  305. * *
  306. * WARNINGS: *
  307. * *
  308. * HISTORY: *
  309. * 1/19/00 gth : Created. *
  310. *=============================================================================================*/
  311. void BoxRenderObjClass::Init(void)
  312. {
  313. WWASSERT(IsInitted == false);
  314. /*
  315. ** Set up the materials
  316. */
  317. WWASSERT(_BoxMaterial == NULL);
  318. _BoxMaterial = NEW_REF(VertexMaterialClass,());
  319. _BoxMaterial->Set_Ambient(0,0,0);
  320. _BoxMaterial->Set_Diffuse(0,0,0);
  321. _BoxMaterial->Set_Specular(0,0,0);
  322. _BoxMaterial->Set_Emissive(1,1,1);
  323. _BoxMaterial->Set_Opacity(1.0f); // uses vertex alpha...
  324. _BoxMaterial->Set_Shininess(0.0f);
  325. _BoxShader = ShaderClass::_PresetAlphaSolidShader;
  326. IsInitted = true;
  327. }
  328. /***********************************************************************************************
  329. * BoxRenderObjClass::Shutdown -- cleanup box render system *
  330. * *
  331. * Releases resources allocated in Init *
  332. * NOTE: this is a static function that should only be called by the system *
  333. * *
  334. * INPUT: *
  335. * *
  336. * OUTPUT: *
  337. * *
  338. * WARNINGS: *
  339. * *
  340. * HISTORY: *
  341. * 1/19/00 gth : Created. *
  342. *=============================================================================================*/
  343. void BoxRenderObjClass::Shutdown(void)
  344. {
  345. WWASSERT(IsInitted == true);
  346. REF_PTR_RELEASE(_BoxMaterial);
  347. IsInitted = false;
  348. }
  349. /***********************************************************************************************
  350. * BoxRenderObjClass::Set_Box_Display_Mask -- Sets global display mask for all boxes *
  351. * *
  352. * Boxes are debug objects and usually used for collision. This mask is 'AND'ed with each *
  353. * box's collision type to determine whether the box should be rendered. *
  354. * *
  355. * INPUT: *
  356. * *
  357. * OUTPUT: *
  358. * *
  359. * WARNINGS: *
  360. * *
  361. * HISTORY: *
  362. * 1/19/00 gth : Created. *
  363. *=============================================================================================*/
  364. void BoxRenderObjClass::Set_Box_Display_Mask(int mask)
  365. {
  366. DisplayMask = mask;
  367. }
  368. /***********************************************************************************************
  369. * BoxRenderObjClass::Get_Box_Display_Mask -- returns the display mask *
  370. * *
  371. * INPUT: *
  372. * *
  373. * OUTPUT: *
  374. * *
  375. * WARNINGS: *
  376. * *
  377. * HISTORY: *
  378. * 1/19/00 gth : Created. *
  379. *=============================================================================================*/
  380. int BoxRenderObjClass::Get_Box_Display_Mask(void)
  381. {
  382. return DisplayMask;
  383. }
  384. /***********************************************************************************************
  385. * BoxRenderObjClass::render_box -- submits the box to the GERD *
  386. * *
  387. * INPUT: *
  388. * *
  389. * OUTPUT: *
  390. * *
  391. * WARNINGS: *
  392. * *
  393. * HISTORY: *
  394. * 1/19/00 gth : Created. *
  395. *=============================================================================================*/
  396. void BoxRenderObjClass::render_box(RenderInfoClass & rinfo,const Vector3 & center,const Vector3 & extent)
  397. {
  398. if (!IsInitted) return;
  399. if (DisplayMask & Get_Collision_Type()) {
  400. static Vector3 verts[NUM_BOX_VERTS];
  401. // compute the vertex positions
  402. for (int ivert=0; ivert<NUM_BOX_VERTS; ivert++) {
  403. verts[ivert].X = center.X + _BoxVerts[ivert][0] * extent.X;
  404. verts[ivert].Y = center.Y + _BoxVerts[ivert][1] * extent.Y;
  405. verts[ivert].Z = center.Z + _BoxVerts[ivert][2] * extent.Z;
  406. }
  407. /*
  408. ** Dump the box vertices into the sorting dynamic vertex buffer.
  409. */
  410. DWORD color = DX8Wrapper::Convert_Color(Color,0.25f);
  411. int buffer_type = BUFFER_TYPE_DYNAMIC_SORTING;
  412. DynamicVBAccessClass vbaccess(buffer_type,dynamic_fvf_type,NUM_BOX_VERTS);
  413. {
  414. DynamicVBAccessClass::WriteLockClass lock(&vbaccess);
  415. //unsigned char *vb=(unsigned char *) lock.Get_Vertex_Array();
  416. VertexFormatXYZNDUV2* vb=lock.Get_Formatted_Vertex_Array();
  417. for (int i=0; i<NUM_BOX_VERTS; i++) {
  418. // Locations
  419. vb->x=verts[i][0];
  420. vb->y=verts[i][1];
  421. vb->z=verts[i][2];
  422. // Normals
  423. vb->nx=_BoxVertexNormals[i][0];
  424. vb->ny=_BoxVertexNormals[i][1];
  425. vb->nz=_BoxVertexNormals[i][2];
  426. // Colors
  427. vb->diffuse=color;
  428. vb++;
  429. }
  430. }
  431. /*
  432. ** Dump the faces into the sorting dynamic index buffer.
  433. */
  434. DynamicIBAccessClass ibaccess(buffer_type,NUM_BOX_FACES*3);
  435. {
  436. DynamicIBAccessClass::WriteLockClass lock(&ibaccess);
  437. unsigned short * indices = lock.Get_Index_Array();
  438. for (int i=0; i<NUM_BOX_FACES; i++) {
  439. indices[3*i] = _BoxFaces[i][0];
  440. indices[3*i+1] = _BoxFaces[i][1];
  441. indices[3*i+2] = _BoxFaces[i][2];
  442. }
  443. }
  444. /*
  445. ** Apply the shader and material
  446. */
  447. DX8Wrapper::Set_Material(_BoxMaterial);
  448. DX8Wrapper::Set_Shader(_BoxShader);
  449. DX8Wrapper::Set_Texture(0,NULL);
  450. DX8Wrapper::Set_Index_Buffer(ibaccess,0);
  451. DX8Wrapper::Set_Vertex_Buffer(vbaccess);
  452. SphereClass sphere;
  453. Get_Obj_Space_Bounding_Sphere(sphere);
  454. DX8Wrapper::Draw_Triangles(buffer_type,0,NUM_BOX_FACES,0,NUM_BOX_VERTS);
  455. }
  456. }
  457. /***********************************************************************************************
  458. * BoxRenderObjClass::vis_render_box -- submits box to the GERD for VIS *
  459. * *
  460. * this renders the box with the specified VIS-ID. *
  461. * *
  462. * INPUT: *
  463. * *
  464. * OUTPUT: *
  465. * *
  466. * WARNINGS: *
  467. * *
  468. * HISTORY: *
  469. * 1/19/00 gth : Created. *
  470. *=============================================================================================*/
  471. void BoxRenderObjClass::vis_render_box(SpecialRenderInfoClass & rinfo,const Vector3 & center,const Vector3 & extent)
  472. {
  473. if (!IsInitted) return;
  474. static Vector3 verts[NUM_BOX_VERTS];
  475. // compute the vertex positions
  476. for (int ivert=0; ivert<NUM_BOX_VERTS; ivert++) {
  477. verts[ivert].X = center.X + _BoxVerts[ivert][0] * extent.X;
  478. verts[ivert].Y = center.Y + _BoxVerts[ivert][1] * extent.Y;
  479. verts[ivert].Z = center.Z + _BoxVerts[ivert][2] * extent.Z;
  480. }
  481. // render!
  482. rinfo.VisRasterizer->Render_Triangles(verts,NUM_BOX_VERTS,_BoxFaces,NUM_BOX_FACES,Get_Bounding_Box());
  483. }
  484. /*
  485. ** AABoxRenderObjClass Implementation
  486. */
  487. /***********************************************************************************************
  488. * AABoxRenderObjClass::AABoxRenderObjClass -- constructor *
  489. * *
  490. * INPUT: *
  491. * *
  492. * OUTPUT: *
  493. * *
  494. * WARNINGS: *
  495. * *
  496. * HISTORY: *
  497. * 1/19/00 gth : Created. *
  498. *=============================================================================================*/
  499. AABoxRenderObjClass::AABoxRenderObjClass(void)
  500. {
  501. update_cached_box();
  502. }
  503. /***********************************************************************************************
  504. * AABoxRenderObjClass::AABoxRenderObjClass -- Constructor - init from a definition *
  505. * *
  506. * INPUT: *
  507. * *
  508. * OUTPUT: *
  509. * *
  510. * WARNINGS: *
  511. * *
  512. * HISTORY: *
  513. * 1/19/00 gth : Created. *
  514. *=============================================================================================*/
  515. AABoxRenderObjClass::AABoxRenderObjClass(const W3dBoxStruct & def) :
  516. BoxRenderObjClass(def)
  517. {
  518. update_cached_box();
  519. }
  520. /***********************************************************************************************
  521. * AABoxRenderObjClass::AABoxRenderObjClass -- copy constructor *
  522. * *
  523. * INPUT: *
  524. * *
  525. * OUTPUT: *
  526. * *
  527. * WARNINGS: *
  528. * *
  529. * HISTORY: *
  530. * 1/19/00 gth : Created. *
  531. *=============================================================================================*/
  532. AABoxRenderObjClass::AABoxRenderObjClass(const AABoxRenderObjClass & src)
  533. {
  534. *this = src;
  535. }
  536. /***********************************************************************************************
  537. * AABoxRenderObjClass::AABoxRenderObjClass -- Constructor from a wwmath aabox *
  538. * *
  539. * INPUT: *
  540. * *
  541. * OUTPUT: *
  542. * *
  543. * WARNINGS: *
  544. * *
  545. * HISTORY: *
  546. * 1/19/00 gth : Created. *
  547. *=============================================================================================*/
  548. AABoxRenderObjClass::AABoxRenderObjClass(const AABoxClass & box)
  549. {
  550. ObjSpaceCenter.Set(0,0,0);
  551. ObjSpaceExtent.Set(box.Extent);
  552. Set_Position(box.Center);
  553. update_cached_box();
  554. }
  555. /***********************************************************************************************
  556. * AABoxRenderObjClass::operator -- assignment operator *
  557. * *
  558. * INPUT: *
  559. * *
  560. * OUTPUT: *
  561. * *
  562. * WARNINGS: *
  563. * *
  564. * HISTORY: *
  565. * 1/19/00 gth : Created. *
  566. *=============================================================================================*/
  567. AABoxRenderObjClass & AABoxRenderObjClass::operator = (const AABoxRenderObjClass & that)
  568. {
  569. if (this != &that) {
  570. BoxRenderObjClass::operator = (that);
  571. CachedBox = that.CachedBox;
  572. }
  573. return *this;
  574. }
  575. /***********************************************************************************************
  576. * AABoxRenderObjClass::Clone -- clones the box *
  577. * *
  578. * INPUT: *
  579. * *
  580. * OUTPUT: *
  581. * *
  582. * WARNINGS: *
  583. * *
  584. * HISTORY: *
  585. * 1/19/00 gth : Created. *
  586. *=============================================================================================*/
  587. RenderObjClass * AABoxRenderObjClass::Clone(void) const
  588. {
  589. return W3DNEW AABoxRenderObjClass(*this);
  590. }
  591. /***********************************************************************************************
  592. * AABoxRenderObjClass::Class_ID -- returns the class-id for AABox's *
  593. * *
  594. * INPUT: *
  595. * *
  596. * OUTPUT: *
  597. * *
  598. * WARNINGS: *
  599. * *
  600. * HISTORY: *
  601. * 1/19/00 gth : Created. *
  602. *=============================================================================================*/
  603. int AABoxRenderObjClass::Class_ID(void) const
  604. {
  605. return RenderObjClass::CLASSID_AABOX;
  606. }
  607. /***********************************************************************************************
  608. * AABoxRenderObjClass::Render -- render this box *
  609. * *
  610. * INPUT: *
  611. * *
  612. * OUTPUT: *
  613. * *
  614. * WARNINGS: *
  615. * *
  616. * HISTORY: *
  617. * 1/19/00 gth : Created. *
  618. *=============================================================================================*/
  619. void AABoxRenderObjClass::Render(RenderInfoClass & rinfo)
  620. {
  621. Matrix3D temp(1);
  622. temp.Translate(Transform.Get_Translation());
  623. DX8Wrapper::Set_Transform(D3DTS_WORLD,temp);
  624. render_box(rinfo,ObjSpaceCenter,ObjSpaceExtent);
  625. }
  626. /***********************************************************************************************
  627. * AABoxRenderObjClass::Special_Render -- special render this box (vis) *
  628. * *
  629. * INPUT: *
  630. * *
  631. * OUTPUT: *
  632. * *
  633. * WARNINGS: *
  634. * *
  635. * HISTORY: *
  636. * 1/19/00 gth : Created. *
  637. *=============================================================================================*/
  638. void AABoxRenderObjClass::Special_Render(SpecialRenderInfoClass & rinfo)
  639. {
  640. if (rinfo.RenderType == SpecialRenderInfoClass::RENDER_VIS) {
  641. WWASSERT(rinfo.VisRasterizer != NULL);
  642. Matrix3D temp(1);
  643. temp.Translate(Transform.Get_Translation());
  644. rinfo.VisRasterizer->Set_Model_Transform(temp);
  645. vis_render_box(rinfo,ObjSpaceCenter,ObjSpaceExtent);
  646. }
  647. }
  648. /***********************************************************************************************
  649. * AABoxRenderObjClass::Set_Transform -- set the transform for this box *
  650. * *
  651. * INPUT: *
  652. * *
  653. * OUTPUT: *
  654. * *
  655. * WARNINGS: *
  656. * *
  657. * HISTORY: *
  658. * 1/19/00 gth : Created. *
  659. *=============================================================================================*/
  660. void AABoxRenderObjClass::Set_Transform(const Matrix3D &m)
  661. {
  662. RenderObjClass::Set_Transform(m);
  663. update_cached_box();
  664. }
  665. /***********************************************************************************************
  666. * AABoxRenderObjClass::Set_Position -- Set the position of this box *
  667. * *
  668. * INPUT: *
  669. * *
  670. * OUTPUT: *
  671. * *
  672. * WARNINGS: *
  673. * *
  674. * HISTORY: *
  675. * 1/19/00 gth : Created. *
  676. *=============================================================================================*/
  677. void AABoxRenderObjClass::Set_Position(const Vector3 &v)
  678. {
  679. RenderObjClass::Set_Position(v);
  680. update_cached_box();
  681. }
  682. /***********************************************************************************************
  683. * AABoxRenderObjClass::update_cached_box -- update the world-space version of this box *
  684. * *
  685. * INPUT: *
  686. * *
  687. * OUTPUT: *
  688. * *
  689. * WARNINGS: *
  690. * *
  691. * HISTORY: *
  692. * 1/19/00 gth : Created. *
  693. *=============================================================================================*/
  694. void AABoxRenderObjClass::update_cached_box(void)
  695. {
  696. CachedBox.Center = Transform.Get_Translation() + ObjSpaceCenter;
  697. CachedBox.Extent = ObjSpaceExtent;
  698. }
  699. /***********************************************************************************************
  700. * AABoxRenderObjClass::Cast_Ray -- cast a ray against this box *
  701. * *
  702. * INPUT: *
  703. * *
  704. * OUTPUT: *
  705. * *
  706. * WARNINGS: *
  707. * *
  708. * HISTORY: *
  709. * 1/19/00 gth : Created. *
  710. *=============================================================================================*/
  711. bool AABoxRenderObjClass::Cast_Ray(RayCollisionTestClass & raytest)
  712. {
  713. if ((Get_Collision_Type() & raytest.CollisionType) == 0) return false;
  714. if (CollisionMath::Collide(raytest.Ray,CachedBox,raytest.Result)) {
  715. raytest.CollidedRenderObj = this;
  716. return true;
  717. }
  718. return false;
  719. }
  720. /***********************************************************************************************
  721. * AABoxRenderObjClass::Cast_AABox -- cast an AABox against this box *
  722. * *
  723. * INPUT: *
  724. * *
  725. * OUTPUT: *
  726. * *
  727. * WARNINGS: *
  728. * *
  729. * HISTORY: *
  730. * 1/19/00 gth : Created. *
  731. *=============================================================================================*/
  732. bool AABoxRenderObjClass::Cast_AABox(AABoxCollisionTestClass & boxtest)
  733. {
  734. if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
  735. if (CollisionMath::Collide(boxtest.Box,boxtest.Move,CachedBox,boxtest.Result)) {
  736. boxtest.CollidedRenderObj = this;
  737. return true;
  738. }
  739. return false;
  740. }
  741. /***********************************************************************************************
  742. * AABoxRenderObjClass::Cast_OBBox -- cast an OBBox against this box *
  743. * *
  744. * INPUT: *
  745. * *
  746. * OUTPUT: *
  747. * *
  748. * WARNINGS: *
  749. * *
  750. * HISTORY: *
  751. * 1/19/00 gth : Created. *
  752. *=============================================================================================*/
  753. bool AABoxRenderObjClass::Cast_OBBox(OBBoxCollisionTestClass & boxtest)
  754. {
  755. if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
  756. if (CollisionMath::Collide(boxtest.Box,boxtest.Move,CachedBox,Vector3(0,0,0),boxtest.Result)) {
  757. boxtest.CollidedRenderObj = this;
  758. return true;
  759. }
  760. return false;
  761. }
  762. /***********************************************************************************************
  763. * AABoxRenderObjClass::Intersect_AABox -- intersect this box with an AABox *
  764. * *
  765. * INPUT: *
  766. * *
  767. * OUTPUT: *
  768. * *
  769. * WARNINGS: *
  770. * *
  771. * HISTORY: *
  772. * 1/19/00 gth : Created. *
  773. *=============================================================================================*/
  774. bool AABoxRenderObjClass::Intersect_AABox(AABoxIntersectionTestClass & boxtest)
  775. {
  776. if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
  777. return CollisionMath::Intersection_Test(CachedBox,boxtest.Box);
  778. }
  779. /***********************************************************************************************
  780. * AABoxRenderObjClass::Intersect_OBBox -- Intersect this box with an OBBox *
  781. * *
  782. * INPUT: *
  783. * *
  784. * OUTPUT: *
  785. * *
  786. * WARNINGS: *
  787. * *
  788. * HISTORY: *
  789. * 1/19/00 gth : Created. *
  790. *=============================================================================================*/
  791. bool AABoxRenderObjClass::Intersect_OBBox(OBBoxIntersectionTestClass & boxtest)
  792. {
  793. if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
  794. return CollisionMath::Intersection_Test(CachedBox,boxtest.Box);
  795. }
  796. /***********************************************************************************************
  797. * AABoxRenderObjClass::Get_Obj_Space_Bounding_Sphere -- return the object-space bounding sphe *
  798. * *
  799. * INPUT: *
  800. * *
  801. * OUTPUT: *
  802. * *
  803. * WARNINGS: *
  804. * *
  805. * HISTORY: *
  806. * 1/19/00 gth : Created. *
  807. *=============================================================================================*/
  808. void AABoxRenderObjClass::Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const
  809. {
  810. sphere.Init(ObjSpaceCenter,ObjSpaceExtent.Length());
  811. }
  812. /***********************************************************************************************
  813. * AABoxRenderObjClass::Get_Obj_Space_Bounding_Box -- returns the obj-space bounding box *
  814. * *
  815. * INPUT: *
  816. * *
  817. * OUTPUT: *
  818. * *
  819. * WARNINGS: *
  820. * *
  821. * HISTORY: *
  822. * 1/19/00 gth : Created. *
  823. *=============================================================================================*/
  824. void AABoxRenderObjClass::Get_Obj_Space_Bounding_Box(AABoxClass & box) const
  825. {
  826. box.Init(ObjSpaceCenter,ObjSpaceExtent);
  827. }
  828. /***********************************************************************************************
  829. * OBBoxRenderObjClass::OBBoxRenderObjClass -- Constructor *
  830. * *
  831. * INPUT: *
  832. * *
  833. * OUTPUT: *
  834. * *
  835. * WARNINGS: *
  836. * *
  837. * HISTORY: *
  838. * 1/19/00 gth : Created. *
  839. *=============================================================================================*/
  840. OBBoxRenderObjClass::OBBoxRenderObjClass(void)
  841. {
  842. update_cached_box();
  843. }
  844. /***********************************************************************************************
  845. * OBBoxRenderObjClass::OBBoxRenderObjClass -- Constructor - initiallize from a definition *
  846. * *
  847. * INPUT: *
  848. * *
  849. * OUTPUT: *
  850. * *
  851. * WARNINGS: *
  852. * *
  853. * HISTORY: *
  854. * 1/19/00 gth : Created. *
  855. *=============================================================================================*/
  856. OBBoxRenderObjClass::OBBoxRenderObjClass(const W3dBoxStruct & def) :
  857. BoxRenderObjClass(def)
  858. {
  859. update_cached_box();
  860. }
  861. /***********************************************************************************************
  862. * OBBoxRenderObjClass::OBBoxRenderObjClass -- copy constructor *
  863. * *
  864. * INPUT: *
  865. * *
  866. * OUTPUT: *
  867. * *
  868. * WARNINGS: *
  869. * *
  870. * HISTORY: *
  871. * 1/19/00 gth : Created. *
  872. *=============================================================================================*/
  873. OBBoxRenderObjClass::OBBoxRenderObjClass(const OBBoxRenderObjClass & that)
  874. {
  875. *this = that;
  876. }
  877. /***********************************************************************************************
  878. * OBBoxRenderObjClass::OBBoxRenderObjClass -- constructor - initialize from a wwmath obbox *
  879. * *
  880. * INPUT: *
  881. * *
  882. * OUTPUT: *
  883. * *
  884. * WARNINGS: *
  885. * *
  886. * HISTORY: *
  887. * 1/19/00 gth : Created. *
  888. *=============================================================================================*/
  889. OBBoxRenderObjClass::OBBoxRenderObjClass(const OBBoxClass & box)
  890. {
  891. ObjSpaceCenter.Set(Vector3(0,0,0));
  892. ObjSpaceExtent.Set(box.Extent);
  893. Set_Transform(Matrix3D(box.Basis,box.Center));
  894. update_cached_box(); // cached box should == box!
  895. }
  896. /***********************************************************************************************
  897. * OBBoxRenderObjClass::operator -- assignment operator *
  898. * *
  899. * INPUT: *
  900. * *
  901. * OUTPUT: *
  902. * *
  903. * WARNINGS: *
  904. * *
  905. * HISTORY: *
  906. * 1/19/00 gth : Created. *
  907. *=============================================================================================*/
  908. OBBoxRenderObjClass & OBBoxRenderObjClass::operator = (const OBBoxRenderObjClass & that)
  909. {
  910. if (this != &that) {
  911. BoxRenderObjClass::operator = (that);
  912. CachedBox = that.CachedBox;
  913. }
  914. return *this;
  915. }
  916. /***********************************************************************************************
  917. * OBBoxRenderObjClass::Clone -- clone this obbox *
  918. * *
  919. * INPUT: *
  920. * *
  921. * OUTPUT: *
  922. * *
  923. * WARNINGS: *
  924. * *
  925. * HISTORY: *
  926. * 1/19/00 gth : Created. *
  927. *=============================================================================================*/
  928. RenderObjClass * OBBoxRenderObjClass::Clone(void) const
  929. {
  930. return W3DNEW OBBoxRenderObjClass(*this);
  931. }
  932. /***********************************************************************************************
  933. * OBBoxRenderObjClass::Class_ID -- returns the class ID of OBBoxRenderObjClass *
  934. * *
  935. * INPUT: *
  936. * *
  937. * OUTPUT: *
  938. * *
  939. * WARNINGS: *
  940. * *
  941. * HISTORY: *
  942. * 1/19/00 gth : Created. *
  943. *=============================================================================================*/
  944. int OBBoxRenderObjClass::Class_ID(void) const
  945. {
  946. return RenderObjClass::CLASSID_OBBOX;
  947. }
  948. /***********************************************************************************************
  949. * OBBoxRenderObjClass::Render -- render this obbox *
  950. * *
  951. * INPUT: *
  952. * *
  953. * OUTPUT: *
  954. * *
  955. * WARNINGS: *
  956. * *
  957. * HISTORY: *
  958. * 1/19/00 gth : Created. *
  959. *=============================================================================================*/
  960. void OBBoxRenderObjClass::Render(RenderInfoClass & rinfo)
  961. {
  962. Matrix3D tm(Transform);
  963. DX8Wrapper::Set_Transform(D3DTS_WORLD,tm);
  964. render_box(rinfo,ObjSpaceCenter,ObjSpaceExtent);
  965. }
  966. /***********************************************************************************************
  967. * OBBoxRenderObjClass::Special_Render -- special render (vis) *
  968. * *
  969. * INPUT: *
  970. * *
  971. * OUTPUT: *
  972. * *
  973. * WARNINGS: *
  974. * *
  975. * HISTORY: *
  976. * 1/19/00 gth : Created. *
  977. *=============================================================================================*/
  978. void OBBoxRenderObjClass::Special_Render(SpecialRenderInfoClass & rinfo)
  979. {
  980. if (rinfo.RenderType == SpecialRenderInfoClass::RENDER_VIS) {
  981. WWASSERT(rinfo.VisRasterizer != NULL);
  982. rinfo.VisRasterizer->Set_Model_Transform(Transform);
  983. vis_render_box(rinfo,ObjSpaceCenter,ObjSpaceExtent);
  984. }
  985. }
  986. /***********************************************************************************************
  987. * OBBoxRenderObjClass::Set_Transform -- set the transform for this box *
  988. * *
  989. * INPUT: *
  990. * *
  991. * OUTPUT: *
  992. * *
  993. * WARNINGS: *
  994. * *
  995. * HISTORY: *
  996. * 1/19/00 gth : Created. *
  997. *=============================================================================================*/
  998. void OBBoxRenderObjClass::Set_Transform(const Matrix3D &m)
  999. {
  1000. RenderObjClass::Set_Transform(m);
  1001. update_cached_box();
  1002. }
  1003. /***********************************************************************************************
  1004. * OBBoxRenderObjClass::Set_Position -- set the position of this box *
  1005. * *
  1006. * INPUT: *
  1007. * *
  1008. * OUTPUT: *
  1009. * *
  1010. * WARNINGS: *
  1011. * *
  1012. * HISTORY: *
  1013. * 1/19/00 gth : Created. *
  1014. *=============================================================================================*/
  1015. void OBBoxRenderObjClass::Set_Position(const Vector3 &v)
  1016. {
  1017. RenderObjClass::Set_Position(v);
  1018. update_cached_box();
  1019. }
  1020. /***********************************************************************************************
  1021. * OBBoxRenderObjClass::update_cached_box -- update the cached world-space box *
  1022. * *
  1023. * INPUT: *
  1024. * *
  1025. * OUTPUT: *
  1026. * *
  1027. * WARNINGS: *
  1028. * *
  1029. * HISTORY: *
  1030. * 1/19/00 gth : Created. *
  1031. *=============================================================================================*/
  1032. void OBBoxRenderObjClass::update_cached_box(void)
  1033. {
  1034. Matrix3D::Transform_Vector(Transform,ObjSpaceCenter,&CachedBox.Center);
  1035. CachedBox.Extent.Set(ObjSpaceExtent);
  1036. CachedBox.Basis.Set(Transform);
  1037. }
  1038. /***********************************************************************************************
  1039. * OBBoxRenderObjClass::Cast_Ray -- cast a ray against this box *
  1040. * *
  1041. * INPUT: *
  1042. * *
  1043. * OUTPUT: *
  1044. * *
  1045. * WARNINGS: *
  1046. * *
  1047. * HISTORY: *
  1048. * 1/19/00 gth : Created. *
  1049. *=============================================================================================*/
  1050. bool OBBoxRenderObjClass::Cast_Ray(RayCollisionTestClass & raytest)
  1051. {
  1052. if ((Get_Collision_Type() & raytest.CollisionType) == 0) return false;
  1053. if (CollisionMath::Collide(raytest.Ray,CachedBox,raytest.Result)) {
  1054. raytest.CollidedRenderObj = this;
  1055. return true;
  1056. }
  1057. return false;
  1058. }
  1059. /***********************************************************************************************
  1060. * OBBoxRenderObjClass::Cast_AABox -- cast a swept aabox against this box *
  1061. * *
  1062. * INPUT: *
  1063. * *
  1064. * OUTPUT: *
  1065. * *
  1066. * WARNINGS: *
  1067. * *
  1068. * HISTORY: *
  1069. * 1/19/00 gth : Created. *
  1070. *=============================================================================================*/
  1071. bool OBBoxRenderObjClass::Cast_AABox(AABoxCollisionTestClass & boxtest)
  1072. {
  1073. if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
  1074. if (CollisionMath::Collide(boxtest.Box,boxtest.Move,CachedBox,Vector3(0,0,0),boxtest.Result)) {
  1075. boxtest.CollidedRenderObj = this;
  1076. return true;
  1077. }
  1078. return false;
  1079. }
  1080. /***********************************************************************************************
  1081. * OBBoxRenderObjClass::Cast_OBBox -- cast a swept obbox against this bo *
  1082. * *
  1083. * INPUT: *
  1084. * *
  1085. * OUTPUT: *
  1086. * *
  1087. * WARNINGS: *
  1088. * *
  1089. * HISTORY: *
  1090. * 1/19/00 gth : Created. *
  1091. *=============================================================================================*/
  1092. bool OBBoxRenderObjClass::Cast_OBBox(OBBoxCollisionTestClass & boxtest)
  1093. {
  1094. if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
  1095. if (CollisionMath::Collide(boxtest.Box,boxtest.Move,CachedBox,Vector3(0,0,0),boxtest.Result)) {
  1096. boxtest.CollidedRenderObj = this;
  1097. return true;
  1098. }
  1099. return false;
  1100. }
  1101. /***********************************************************************************************
  1102. * OBBoxRenderObjClass::Intersect_AABox -- test this box for intersection with an AAbox *
  1103. * *
  1104. * INPUT: *
  1105. * *
  1106. * OUTPUT: *
  1107. * *
  1108. * WARNINGS: *
  1109. * *
  1110. * HISTORY: *
  1111. * 1/19/00 gth : Created. *
  1112. *=============================================================================================*/
  1113. bool OBBoxRenderObjClass::Intersect_AABox(AABoxIntersectionTestClass & boxtest)
  1114. {
  1115. if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
  1116. return CollisionMath::Intersection_Test(CachedBox,boxtest.Box);
  1117. }
  1118. /***********************************************************************************************
  1119. * OBBoxRenderObjClass::Intersect_OBBox -- test this box for intersection with an OBBox *
  1120. * *
  1121. * INPUT: *
  1122. * *
  1123. * OUTPUT: *
  1124. * *
  1125. * WARNINGS: *
  1126. * *
  1127. * HISTORY: *
  1128. * 1/19/00 gth : Created. *
  1129. *=============================================================================================*/
  1130. bool OBBoxRenderObjClass::Intersect_OBBox(OBBoxIntersectionTestClass & boxtest)
  1131. {
  1132. if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
  1133. return CollisionMath::Intersection_Test(CachedBox,boxtest.Box);
  1134. }
  1135. /***********************************************************************************************
  1136. * OBBoxRenderObjClass::Get_Obj_Space_Bounding_Sphere -- return the obj-space bounding sphere *
  1137. * *
  1138. * INPUT: *
  1139. * *
  1140. * OUTPUT: *
  1141. * *
  1142. * WARNINGS: *
  1143. * *
  1144. * HISTORY: *
  1145. * 1/19/00 gth : Created. *
  1146. *=============================================================================================*/
  1147. void OBBoxRenderObjClass::Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const
  1148. {
  1149. sphere.Init(ObjSpaceCenter,ObjSpaceExtent.Length());
  1150. }
  1151. /***********************************************************************************************
  1152. * OBBoxRenderObjClass::Get_Obj_Space_Bounding_Box -- returns the obj-space bounding box *
  1153. * *
  1154. * INPUT: *
  1155. * *
  1156. * OUTPUT: *
  1157. * *
  1158. * WARNINGS: *
  1159. * *
  1160. * HISTORY: *
  1161. * 1/19/00 gth : Created. *
  1162. *=============================================================================================*/
  1163. void OBBoxRenderObjClass::Get_Obj_Space_Bounding_Box(AABoxClass & box) const
  1164. {
  1165. box.Init(ObjSpaceCenter,ObjSpaceExtent);
  1166. }
  1167. /***********************************************************************************************
  1168. * OBBoxRenderObjClass::Get_Box -- returns the cached world-space box *
  1169. * *
  1170. * INPUT: *
  1171. * *
  1172. * OUTPUT: *
  1173. * *
  1174. * WARNINGS: *
  1175. * *
  1176. * HISTORY: *
  1177. * 1/19/00 gth : Created. *
  1178. *=============================================================================================*/
  1179. OBBoxClass & OBBoxRenderObjClass::Get_Box(void)
  1180. {
  1181. Validate_Transform();
  1182. update_cached_box();
  1183. return CachedBox;
  1184. }
  1185. /*
  1186. ** BoxLoaderClass Implementation
  1187. */
  1188. PrototypeClass * BoxLoaderClass::Load_W3D(ChunkLoadClass & cload)
  1189. {
  1190. W3dBoxStruct box;
  1191. cload.Read(&box,sizeof(box));
  1192. return W3DNEW BoxPrototypeClass(box);
  1193. }
  1194. /*
  1195. ** BoxPrototypeClass Implementation
  1196. */
  1197. BoxPrototypeClass::BoxPrototypeClass(W3dBoxStruct box)
  1198. {
  1199. Definition = box;
  1200. }
  1201. const char * BoxPrototypeClass::Get_Name(void) const
  1202. {
  1203. return Definition.Name;
  1204. }
  1205. int BoxPrototypeClass::Get_Class_ID(void) const
  1206. {
  1207. if (Definition.Attributes & W3D_BOX_ATTRIBUTE_ORIENTED) {
  1208. return RenderObjClass::CLASSID_OBBOX;
  1209. } else {
  1210. return RenderObjClass::CLASSID_AABOX;
  1211. }
  1212. }
  1213. RenderObjClass * BoxPrototypeClass::Create(void)
  1214. {
  1215. if (Definition.Attributes & W3D_BOX_ATTRIBUTE_ORIENTED) {
  1216. return NEW_REF( OBBoxRenderObjClass, (Definition) );
  1217. } else {
  1218. return NEW_REF( AABoxRenderObjClass, (Definition) );
  1219. }
  1220. }
  1221. /*
  1222. ** Global instance of the box loader
  1223. */
  1224. BoxLoaderClass _BoxLoader;