boxrobj.cpp 83 KB

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