| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391 |
- /*
- ** Command & Conquer Generals Zero Hour(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /***********************************************************************************************
- *** 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 ***
- ***********************************************************************************************
- * *
- * Project Name : WW3D *
- * *
- * $Archive:: /Commando/Code/ww3d2/boxrobj.cpp $*
- * *
- * Author:: Greg Hjelstrom *
- * *
- * $Modtime:: 1/19/02 12:57p $*
- * *
- * $Revision:: 35 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * BoxRenderObjClass::BoxRenderObjClass -- Constructor *
- * BoxRenderObjClass::BoxRenderObjClass -- Constructor - init from a definition *
- * BoxRenderObjClass::BoxRenderObjClass -- Copy constructor *
- * BoxRenderObjClass::operator -- assignment operator *
- * BoxRenderObjClass::Get_Num_Polys -- returns number of polygons *
- * BoxRenderObjClass::Get_Name -- returns name *
- * BoxRenderObjClass::Set_Name -- sets the name *
- * BoxRenderObjClass::Set_Color -- Sets the color of the box *
- * BoxRenderObjClass::Init_Box_Render_System -- global initialization needed for boxes to wo *
- * BoxRenderObjClass::Shutdown_Box_Render_System -- cleanup box render system *
- * BoxRenderObjClass::Set_Box_Display_Mask -- Sets global display mask for all boxes *
- * BoxRenderObjClass::Get_Box_Display_Mask -- returns the display mask *
- * BoxRenderObjClass::render_box -- submits the box to the GERD *
- * BoxRenderObjClass::vis_render_box -- submits box to the GERD for VIS *
- * AABoxRenderObjClass::AABoxRenderObjClass -- constructor *
- * AABoxRenderObjClass::AABoxRenderObjClass -- Constructor - init from a definition *
- * AABoxRenderObjClass::AABoxRenderObjClass -- copy constructor *
- * AABoxRenderObjClass::AABoxRenderObjClass -- Constructor from a wwmath aabox *
- * AABoxRenderObjClass::operator -- assignment operator *
- * AABoxRenderObjClass::Clone -- clones the box *
- * AABoxRenderObjClass::Class_ID -- returns the class-id for AABox's *
- * AABoxRenderObjClass::Render -- render this box *
- * AABoxRenderObjClass::Special_Render -- special render this box (vis) *
- * AABoxRenderObjClass::Set_Transform -- set the transform for this box *
- * AABoxRenderObjClass::Set_Position -- Set the position of this box *
- * AABoxRenderObjClass::update_cached_box -- update the world-space version of this box *
- * AABoxRenderObjClass::Cast_Ray -- cast a ray against this box *
- * AABoxRenderObjClass::Cast_AABox -- cast an AABox against this box *
- * AABoxRenderObjClass::Cast_OBBox -- cast an OBBox against this box *
- * AABoxRenderObjClass::Intersect_AABox -- intersect this box with an AABox *
- * AABoxRenderObjClass::Intersect_OBBox -- Intersect this box with an OBBox *
- * AABoxRenderObjClass::Get_Obj_Space_Bounding_Sphere -- return the object-space bounding sp *
- * AABoxRenderObjClass::Get_Obj_Space_Bounding_Box -- returns the obj-space bounding box *
- * OBBoxRenderObjClass::OBBoxRenderObjClass -- Constructor *
- * OBBoxRenderObjClass::OBBoxRenderObjClass -- Constructor - initiallize from a definition *
- * OBBoxRenderObjClass::OBBoxRenderObjClass -- copy constructor *
- * OBBoxRenderObjClass::OBBoxRenderObjClass -- constructor - initialize from a wwmath obbox *
- * OBBoxRenderObjClass::operator -- assignment operator *
- * OBBoxRenderObjClass::Clone -- clone this obbox *
- * OBBoxRenderObjClass::Class_ID -- returns the class ID of OBBoxRenderObjClass *
- * OBBoxRenderObjClass::Render -- render this obbox *
- * OBBoxRenderObjClass::Special_Render -- special render (vis) *
- * OBBoxRenderObjClass::Set_Transform -- set the transform for this box *
- * OBBoxRenderObjClass::Set_Position -- set the position of this box *
- * OBBoxRenderObjClass::update_cached_box -- update the cached world-space box *
- * OBBoxRenderObjClass::Cast_Ray -- cast a ray against this box *
- * OBBoxRenderObjClass::Cast_AABox -- cast a swept aabox against this box *
- * OBBoxRenderObjClass::Cast_OBBox -- cast a swept obbox against this bo *
- * OBBoxRenderObjClass::Intersect_AABox -- test this box for intersection with an AAbox *
- * OBBoxRenderObjClass::Intersect_OBBox -- test this box for intersection with an OBBox *
- * OBBoxRenderObjClass::Get_Obj_Space_Bounding_Sphere -- return the obj-space bounding spher *
- * OBBoxRenderObjClass::Get_Obj_Space_Bounding_Box -- returns the obj-space bounding box *
- * OBBoxRenderObjClass::Get_Box -- returns the cached world-space box *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "boxrobj.h"
- #include "w3d_util.h"
- #include "wwdebug.h"
- #include "vertmaterial.h"
- #include "ww3d.h"
- #include "chunkio.h"
- #include "rinfo.h"
- #include "coltest.h"
- #include "inttest.h"
- #include "dx8wrapper.h"
- #include "dx8indexbuffer.h"
- #include "dx8vertexbuffer.h"
- #include "dx8fvf.h"
- #include "sortingrenderer.h"
- #include "visrasterizer.h"
- #include "meshgeometry.h"
- #define NUM_BOX_VERTS 8
- #define NUM_BOX_FACES 12
- // Face Connectivity
- static TriIndex _BoxFaces[NUM_BOX_FACES] =
- {
- TriIndex( 0,1,2 ), // +z faces
- TriIndex( 0,2,3 ),
- TriIndex( 4,7,6 ), // -z faces
- TriIndex( 4,6,5 ),
- TriIndex( 0,3,7 ), // +x faces
- TriIndex( 0,7,4 ),
- TriIndex( 1,5,6 ), // -x faces
- TriIndex( 1,6,2 ),
- TriIndex( 4,5,1 ), // +y faces
- TriIndex( 4,1,0 ),
- TriIndex( 3,2,6 ), // -y faces
- TriIndex( 3,6,7 )
- };
- // Vertex Positions as a function of the box extents
- static Vector3 _BoxVerts[NUM_BOX_VERTS] =
- {
- Vector3( 1.0f, 1.0f, 1.0f ), // +z ring of 4 verts
- Vector3( -1.0f, 1.0f, 1.0f ),
- Vector3( -1.0f,-1.0f, 1.0f ),
- Vector3( 1.0f,-1.0f, 1.0f ),
- Vector3( 1.0f, 1.0f,-1.0f ), // -z ring of 4 verts;
- Vector3( -1.0f, 1.0f,-1.0f ),
- Vector3( -1.0f,-1.0f,-1.0f ),
- Vector3( 1.0f,-1.0f,-1.0f ),
- };
- // Vertex Normals
- static Vector3 _BoxVertexNormals[NUM_BOX_VERTS] =
- {
- Vector3( WWMATH_OOSQRT3, WWMATH_OOSQRT3, WWMATH_OOSQRT3 ),
- Vector3(-WWMATH_OOSQRT3, WWMATH_OOSQRT3, WWMATH_OOSQRT3 ),
- Vector3(-WWMATH_OOSQRT3,-WWMATH_OOSQRT3, WWMATH_OOSQRT3 ),
- Vector3( WWMATH_OOSQRT3,-WWMATH_OOSQRT3, WWMATH_OOSQRT3 ),
- Vector3( WWMATH_OOSQRT3, WWMATH_OOSQRT3,-WWMATH_OOSQRT3 ),
- Vector3(-WWMATH_OOSQRT3, WWMATH_OOSQRT3,-WWMATH_OOSQRT3 ),
- Vector3(-WWMATH_OOSQRT3,-WWMATH_OOSQRT3,-WWMATH_OOSQRT3 ),
- Vector3( WWMATH_OOSQRT3,-WWMATH_OOSQRT3,-WWMATH_OOSQRT3 ),
- };
- bool BoxRenderObjClass::IsInitted = false;
- int BoxRenderObjClass::DisplayMask = 0;
- static VertexMaterialClass * _BoxMaterial = NULL;
- static ShaderClass _BoxShader;
- /*
- ** BoxRenderObjClass Implementation
- */
- /***********************************************************************************************
- * BoxRenderObjClass::BoxRenderObjClass -- Constructor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- BoxRenderObjClass::BoxRenderObjClass(void)
- {
- memset(Name,0,sizeof(Name));
- Color.Set(1,1,1);
- Opacity = 0.25f;
- ObjSpaceCenter.Set(0,0,0);
- ObjSpaceExtent.Set(1,1,1);
- }
- /***********************************************************************************************
- * BoxRenderObjClass::BoxRenderObjClass -- Constructor - init from a definition *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- BoxRenderObjClass::BoxRenderObjClass(const W3dBoxStruct & def)
- {
- Set_Name(def.Name);
- W3dUtilityClass::Convert_Color(def.Color,&Color);
- W3dUtilityClass::Convert_Vector(def.Center,&ObjSpaceCenter);
- W3dUtilityClass::Convert_Vector(def.Extent,&ObjSpaceExtent);
- int col_bits = (def.Attributes & W3D_BOX_ATTRIBUTE_COLLISION_TYPE_MASK) >> W3D_BOX_ATTRIBUTE_COLLISION_TYPE_SHIFT;
- Set_Collision_Type(col_bits<<1);
- Opacity = 0.25f;
- }
- /***********************************************************************************************
- * BoxRenderObjClass::BoxRenderObjClass -- Copy constructor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- BoxRenderObjClass::BoxRenderObjClass(const BoxRenderObjClass & src)
- {
- *this = src;
- }
- /***********************************************************************************************
- * BoxRenderObjClass::operator -- assignment operator *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- BoxRenderObjClass & BoxRenderObjClass::operator = (const BoxRenderObjClass & that)
- {
- if (this != &that) {
- RenderObjClass::operator = (that);
- Set_Name(that.Get_Name());
- Color.Set(that.Color);
- ObjSpaceCenter.Set(that.ObjSpaceCenter);
- ObjSpaceExtent.Set(that.ObjSpaceExtent);
- }
- return *this;
- }
- /***********************************************************************************************
- * BoxRenderObjClass::Get_Num_Polys -- returns number of polygons *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- int BoxRenderObjClass::Get_Num_Polys(void) const
- {
- return 12;
- }
- /***********************************************************************************************
- * BoxRenderObjClass::Get_Name -- returns name *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- const char * BoxRenderObjClass::Get_Name(void) const
- {
- return Name;
- }
- /***********************************************************************************************
- * BoxRenderObjClass::Set_Name -- sets the name *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void BoxRenderObjClass::Set_Name(const char * name)
- {
- WWASSERT(name != NULL);
- WWASSERT(strlen(name) < 2*W3D_NAME_LEN);
- strcpy(Name,name);
- }
- /***********************************************************************************************
- * BoxRenderObjClass::Set_Color -- Sets the color of the box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void BoxRenderObjClass::Set_Color(const Vector3 & color)
- {
- Color = color;
- }
- /***********************************************************************************************
- * BoxRenderObjClass::Init_Box_Render_System -- global initialization needed for boxes to work *
- * *
- * Allocates materials which all boxes share. Initializes vertex tables, etc *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void BoxRenderObjClass::Init(void)
- {
- WWASSERT(IsInitted == false);
- /*
- ** Set up the materials
- */
- WWASSERT(_BoxMaterial == NULL);
- _BoxMaterial = NEW_REF(VertexMaterialClass,());
- _BoxMaterial->Set_Ambient(0,0,0);
- _BoxMaterial->Set_Diffuse(0,0,0);
- _BoxMaterial->Set_Specular(0,0,0);
- _BoxMaterial->Set_Emissive(1,1,1);
- _BoxMaterial->Set_Opacity(1.0f); // uses vertex alpha...
- _BoxMaterial->Set_Shininess(0.0f);
- _BoxShader = ShaderClass::_PresetAlphaSolidShader; //_PresetAdditiveSolidShader;
- IsInitted = true;
- }
- /***********************************************************************************************
- * BoxRenderObjClass::Shutdown -- cleanup box render system *
- * *
- * Releases resources allocated in Init *
- * NOTE: this is a static function that should only be called by the system *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void BoxRenderObjClass::Shutdown(void)
- {
- WWASSERT(IsInitted == true);
- REF_PTR_RELEASE(_BoxMaterial);
-
- IsInitted = false;
- }
- /***********************************************************************************************
- * BoxRenderObjClass::Set_Box_Display_Mask -- Sets global display mask for all boxes *
- * *
- * Boxes are debug objects and usually used for collision. This mask is 'AND'ed with each *
- * box's collision type to determine whether the box should be rendered. *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void BoxRenderObjClass::Set_Box_Display_Mask(int mask)
- {
- DisplayMask = mask;
- }
- /***********************************************************************************************
- * BoxRenderObjClass::Get_Box_Display_Mask -- returns the display mask *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- int BoxRenderObjClass::Get_Box_Display_Mask(void)
- {
- return DisplayMask;
- }
- /***********************************************************************************************
- * BoxRenderObjClass::render_box -- submits the box to the GERD *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void BoxRenderObjClass::render_box(RenderInfoClass & rinfo,const Vector3 & center,const Vector3 & extent)
- {
- if (!IsInitted) return;
- if (DisplayMask & Get_Collision_Type()) {
- static Vector3 verts[NUM_BOX_VERTS];
- // compute the vertex positions
- for (int ivert=0; ivert<NUM_BOX_VERTS; ivert++) {
- verts[ivert].X = center.X + _BoxVerts[ivert][0] * extent.X;
- verts[ivert].Y = center.Y + _BoxVerts[ivert][1] * extent.Y;
- verts[ivert].Z = center.Z + _BoxVerts[ivert][2] * extent.Z;
- }
- /*
- ** Dump the box vertices into the sorting dynamic vertex buffer.
- */
- DWORD color = DX8Wrapper::Convert_Color(Color,Opacity);
-
- int buffer_type = BUFFER_TYPE_DYNAMIC_DX8;
- DynamicVBAccessClass vbaccess(buffer_type,dynamic_fvf_type,NUM_BOX_VERTS);
- {
- DynamicVBAccessClass::WriteLockClass lock(&vbaccess);
- //unsigned char *vb=(unsigned char *) lock.Get_Vertex_Array();
- VertexFormatXYZNDUV2* vb=lock.Get_Formatted_Vertex_Array();
- for (int i=0; i<NUM_BOX_VERTS; i++) {
- // Locations
- vb->x=verts[i][0];
- vb->y=verts[i][1];
- vb->z=verts[i][2];
-
- // Normals
- vb->nx=_BoxVertexNormals[i][0];
- vb->ny=_BoxVertexNormals[i][1];
- vb->nz=_BoxVertexNormals[i][2];
- // Colors
- vb->diffuse=color;
- vb++;
- }
- }
- /*
- ** Dump the faces into the sorting dynamic index buffer.
- */
- DynamicIBAccessClass ibaccess(buffer_type,NUM_BOX_FACES*3);
- {
- DynamicIBAccessClass::WriteLockClass lock(&ibaccess);
- unsigned short * indices = lock.Get_Index_Array();
- for (int i=0; i<NUM_BOX_FACES; i++) {
- indices[3*i] = _BoxFaces[i][0];
- indices[3*i+1] = _BoxFaces[i][1];
- indices[3*i+2] = _BoxFaces[i][2];
- }
- }
- /*
- ** Apply the shader and material
- */
- DX8Wrapper::Set_Material(_BoxMaterial);
- DX8Wrapper::Set_Shader(_BoxShader);
- DX8Wrapper::Set_Texture(0,NULL);
-
- DX8Wrapper::Set_Index_Buffer(ibaccess,0);
- DX8Wrapper::Set_Vertex_Buffer(vbaccess);
- SphereClass sphere;
- Get_Obj_Space_Bounding_Sphere(sphere);
- DX8Wrapper::Draw_Triangles(buffer_type,0,NUM_BOX_FACES,0,NUM_BOX_VERTS);
- }
- }
- /***********************************************************************************************
- * BoxRenderObjClass::vis_render_box -- submits box to the GERD for VIS *
- * *
- * this renders the box with the specified VIS-ID. *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void BoxRenderObjClass::vis_render_box(SpecialRenderInfoClass & rinfo,const Vector3 & center,const Vector3 & extent)
- {
- if (!IsInitted) return;
-
- static Vector3 verts[NUM_BOX_VERTS];
- // compute the vertex positions
- for (int ivert=0; ivert<NUM_BOX_VERTS; ivert++) {
- verts[ivert].X = center.X + _BoxVerts[ivert][0] * extent.X;
- verts[ivert].Y = center.Y + _BoxVerts[ivert][1] * extent.Y;
- verts[ivert].Z = center.Z + _BoxVerts[ivert][2] * extent.Z;
- }
- // render!
- rinfo.VisRasterizer->Render_Triangles(verts,NUM_BOX_VERTS,_BoxFaces,NUM_BOX_FACES,Get_Bounding_Box());
- }
- /*
- ** AABoxRenderObjClass Implementation
- */
- /***********************************************************************************************
- * AABoxRenderObjClass::AABoxRenderObjClass -- constructor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- AABoxRenderObjClass::AABoxRenderObjClass(void)
- {
- update_cached_box();
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::AABoxRenderObjClass -- Constructor - init from a definition *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- AABoxRenderObjClass::AABoxRenderObjClass(const W3dBoxStruct & def) :
- BoxRenderObjClass(def)
- {
- update_cached_box();
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::AABoxRenderObjClass -- copy constructor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- AABoxRenderObjClass::AABoxRenderObjClass(const AABoxRenderObjClass & src)
- {
- *this = src;
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::AABoxRenderObjClass -- Constructor from a wwmath aabox *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- AABoxRenderObjClass::AABoxRenderObjClass(const AABoxClass & box)
- {
- ObjSpaceCenter.Set(0,0,0);
- ObjSpaceExtent.Set(box.Extent);
- Set_Position(box.Center);
- update_cached_box();
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::operator -- assignment operator *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- AABoxRenderObjClass & AABoxRenderObjClass::operator = (const AABoxRenderObjClass & that)
- {
- if (this != &that) {
- BoxRenderObjClass::operator = (that);
- CachedBox = that.CachedBox;
- }
- return *this;
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::Clone -- clones the box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- RenderObjClass * AABoxRenderObjClass::Clone(void) const
- {
- return W3DNEW AABoxRenderObjClass(*this);
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::Class_ID -- returns the class-id for AABox's *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- int AABoxRenderObjClass::Class_ID(void) const
- {
- return RenderObjClass::CLASSID_AABOX;
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::Render -- render this box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void AABoxRenderObjClass::Render(RenderInfoClass & rinfo)
- {
- Matrix3D temp(1);
- temp.Translate(Transform.Get_Translation());
- DX8Wrapper::Set_Transform(D3DTS_WORLD,temp);
- render_box(rinfo,ObjSpaceCenter,ObjSpaceExtent);
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::Special_Render -- special render this box (vis) *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void AABoxRenderObjClass::Special_Render(SpecialRenderInfoClass & rinfo)
- {
- if (rinfo.RenderType == SpecialRenderInfoClass::RENDER_VIS) {
- WWASSERT(rinfo.VisRasterizer != NULL);
- Matrix3D temp(1);
- temp.Translate(Transform.Get_Translation());
- rinfo.VisRasterizer->Set_Model_Transform(temp);
- vis_render_box(rinfo,ObjSpaceCenter,ObjSpaceExtent);
- }
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::Set_Transform -- set the transform for this box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void AABoxRenderObjClass::Set_Transform(const Matrix3D &m)
- {
- RenderObjClass::Set_Transform(m);
- update_cached_box();
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::Set_Position -- Set the position of this box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void AABoxRenderObjClass::Set_Position(const Vector3 &v)
- {
- RenderObjClass::Set_Position(v);
- update_cached_box();
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::update_cached_box -- update the world-space version of this box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void AABoxRenderObjClass::update_cached_box(void)
- {
- CachedBox.Center = Transform.Get_Translation() + ObjSpaceCenter;
- CachedBox.Extent = ObjSpaceExtent;
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::Cast_Ray -- cast a ray against this box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- bool AABoxRenderObjClass::Cast_Ray(RayCollisionTestClass & raytest)
- {
- if ((Get_Collision_Type() & raytest.CollisionType) == 0) return false;
- if (Is_Animation_Hidden()) return false;
- if (raytest.Result->StartBad) return false;
- if (CollisionMath::Collide(raytest.Ray,CachedBox,raytest.Result)) {
- raytest.CollidedRenderObj = this;
- return true;
- }
- return false;
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::Cast_AABox -- cast an AABox against this box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- bool AABoxRenderObjClass::Cast_AABox(AABoxCollisionTestClass & boxtest)
- {
- if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
- if (boxtest.Result->StartBad) return false;
- if (CollisionMath::Collide(boxtest.Box,boxtest.Move,CachedBox,boxtest.Result)) {
- boxtest.CollidedRenderObj = this;
- return true;
- }
- return false;
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::Cast_OBBox -- cast an OBBox against this box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- bool AABoxRenderObjClass::Cast_OBBox(OBBoxCollisionTestClass & boxtest)
- {
- if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
- if (boxtest.Result->StartBad) return false;
- if (CollisionMath::Collide(boxtest.Box,boxtest.Move,CachedBox,Vector3(0,0,0),boxtest.Result)) {
- boxtest.CollidedRenderObj = this;
- return true;
- }
- return false;
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::Intersect_AABox -- intersect this box with an AABox *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- bool AABoxRenderObjClass::Intersect_AABox(AABoxIntersectionTestClass & boxtest)
- {
- if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
- return CollisionMath::Intersection_Test(CachedBox,boxtest.Box);
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::Intersect_OBBox -- Intersect this box with an OBBox *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- bool AABoxRenderObjClass::Intersect_OBBox(OBBoxIntersectionTestClass & boxtest)
- {
- if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
- return CollisionMath::Intersection_Test(CachedBox,boxtest.Box);
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::Get_Obj_Space_Bounding_Sphere -- return the object-space bounding sphe *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void AABoxRenderObjClass::Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const
- {
- sphere.Init(ObjSpaceCenter,ObjSpaceExtent.Length());
- }
- /***********************************************************************************************
- * AABoxRenderObjClass::Get_Obj_Space_Bounding_Box -- returns the obj-space bounding box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void AABoxRenderObjClass::Get_Obj_Space_Bounding_Box(AABoxClass & box) const
- {
- box.Init(ObjSpaceCenter,ObjSpaceExtent);
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::OBBoxRenderObjClass -- Constructor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- OBBoxRenderObjClass::OBBoxRenderObjClass(void)
- {
- update_cached_box();
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::OBBoxRenderObjClass -- Constructor - initiallize from a definition *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- OBBoxRenderObjClass::OBBoxRenderObjClass(const W3dBoxStruct & def) :
- BoxRenderObjClass(def)
- {
- update_cached_box();
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::OBBoxRenderObjClass -- copy constructor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- OBBoxRenderObjClass::OBBoxRenderObjClass(const OBBoxRenderObjClass & that)
- {
- *this = that;
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::OBBoxRenderObjClass -- constructor - initialize from a wwmath obbox *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- OBBoxRenderObjClass::OBBoxRenderObjClass(const OBBoxClass & box)
- {
- ObjSpaceCenter.Set(Vector3(0,0,0));
- ObjSpaceExtent.Set(box.Extent);
- Set_Transform(Matrix3D(box.Basis,box.Center));
- update_cached_box(); // cached box should == box!
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::operator -- assignment operator *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- OBBoxRenderObjClass & OBBoxRenderObjClass::operator = (const OBBoxRenderObjClass & that)
- {
- if (this != &that) {
- BoxRenderObjClass::operator = (that);
- CachedBox = that.CachedBox;
- }
- return *this;
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::Clone -- clone this obbox *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- RenderObjClass * OBBoxRenderObjClass::Clone(void) const
- {
- return W3DNEW OBBoxRenderObjClass(*this);
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::Class_ID -- returns the class ID of OBBoxRenderObjClass *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- int OBBoxRenderObjClass::Class_ID(void) const
- {
- return RenderObjClass::CLASSID_OBBOX;
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::Render -- render this obbox *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void OBBoxRenderObjClass::Render(RenderInfoClass & rinfo)
- {
- DX8Wrapper::Set_Transform(D3DTS_WORLD,Transform);
- render_box(rinfo,ObjSpaceCenter,ObjSpaceExtent);
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::Special_Render -- special render (vis) *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void OBBoxRenderObjClass::Special_Render(SpecialRenderInfoClass & rinfo)
- {
- if (rinfo.RenderType == SpecialRenderInfoClass::RENDER_VIS) {
- WWASSERT(rinfo.VisRasterizer != NULL);
- rinfo.VisRasterizer->Set_Model_Transform(Transform);
- vis_render_box(rinfo,ObjSpaceCenter,ObjSpaceExtent);
- }
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::Set_Transform -- set the transform for this box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void OBBoxRenderObjClass::Set_Transform(const Matrix3D &m)
- {
- RenderObjClass::Set_Transform(m);
- update_cached_box();
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::Set_Position -- set the position of this box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void OBBoxRenderObjClass::Set_Position(const Vector3 &v)
- {
- RenderObjClass::Set_Position(v);
- update_cached_box();
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::update_cached_box -- update the cached world-space box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void OBBoxRenderObjClass::update_cached_box(void)
- {
- Matrix3D::Transform_Vector(Transform,ObjSpaceCenter,&CachedBox.Center);
- CachedBox.Extent.Set(ObjSpaceExtent);
- CachedBox.Basis.Set(Transform);
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::Cast_Ray -- cast a ray against this box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- bool OBBoxRenderObjClass::Cast_Ray(RayCollisionTestClass & raytest)
- {
- if ((Get_Collision_Type() & raytest.CollisionType) == 0) return false;
- if (Is_Animation_Hidden()) return false;
- if (raytest.Result->StartBad) return false;
- if (CollisionMath::Collide(raytest.Ray,CachedBox,raytest.Result)) {
- raytest.CollidedRenderObj = this;
- return true;
- }
- return false;
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::Cast_AABox -- cast a swept aabox against this box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- bool OBBoxRenderObjClass::Cast_AABox(AABoxCollisionTestClass & boxtest)
- {
- if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
- if (boxtest.Result->StartBad) return false;
- if (CollisionMath::Collide(boxtest.Box,boxtest.Move,CachedBox,Vector3(0,0,0),boxtest.Result)) {
- boxtest.CollidedRenderObj = this;
- return true;
- }
- return false;
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::Cast_OBBox -- cast a swept obbox against this bo *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- bool OBBoxRenderObjClass::Cast_OBBox(OBBoxCollisionTestClass & boxtest)
- {
- if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
- if (boxtest.Result->StartBad) return false;
- if (CollisionMath::Collide(boxtest.Box,boxtest.Move,CachedBox,Vector3(0,0,0),boxtest.Result)) {
- boxtest.CollidedRenderObj = this;
- return true;
- }
- return false;
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::Intersect_AABox -- test this box for intersection with an AAbox *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- bool OBBoxRenderObjClass::Intersect_AABox(AABoxIntersectionTestClass & boxtest)
- {
- if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
- return CollisionMath::Intersection_Test(CachedBox,boxtest.Box);
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::Intersect_OBBox -- test this box for intersection with an OBBox *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- bool OBBoxRenderObjClass::Intersect_OBBox(OBBoxIntersectionTestClass & boxtest)
- {
- if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
- return CollisionMath::Intersection_Test(CachedBox,boxtest.Box);
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::Get_Obj_Space_Bounding_Sphere -- return the obj-space bounding sphere *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void OBBoxRenderObjClass::Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const
- {
- sphere.Init(ObjSpaceCenter,ObjSpaceExtent.Length());
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::Get_Obj_Space_Bounding_Box -- returns the obj-space bounding box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- void OBBoxRenderObjClass::Get_Obj_Space_Bounding_Box(AABoxClass & box) const
- {
- box.Init(ObjSpaceCenter,ObjSpaceExtent);
- }
- /***********************************************************************************************
- * OBBoxRenderObjClass::Get_Box -- returns the cached world-space box *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/19/00 gth : Created. *
- *=============================================================================================*/
- OBBoxClass & OBBoxRenderObjClass::Get_Box(void)
- {
- Validate_Transform();
- update_cached_box();
- return CachedBox;
- }
- /*
- ** BoxLoaderClass Implementation
- */
- PrototypeClass * BoxLoaderClass::Load_W3D(ChunkLoadClass & cload)
- {
- W3dBoxStruct box;
- cload.Read(&box,sizeof(box));
- return W3DNEW BoxPrototypeClass(box);
- }
- /*
- ** BoxPrototypeClass Implementation
- */
- BoxPrototypeClass::BoxPrototypeClass(W3dBoxStruct box)
- {
- Definition = box;
- }
- const char * BoxPrototypeClass::Get_Name(void) const
- {
- return Definition.Name;
- }
- int BoxPrototypeClass::Get_Class_ID(void) const
- {
- if (Definition.Attributes & W3D_BOX_ATTRIBUTE_ORIENTED) {
- return RenderObjClass::CLASSID_OBBOX;
- } else {
- return RenderObjClass::CLASSID_AABOX;
- }
- }
-
- RenderObjClass * BoxPrototypeClass::Create(void)
- {
- if (Definition.Attributes & W3D_BOX_ATTRIBUTE_ORIENTED) {
- return NEW_REF( OBBoxRenderObjClass, (Definition) );
- } else {
- return NEW_REF( AABoxRenderObjClass, (Definition) );
- }
- }
- /*
- ** Global instance of the box loader
- */
- BoxLoaderClass _BoxLoader;
|