| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165 |
- /*
- ** Command & Conquer Generals(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/distlod.cpp $*
- * *
- * Author:: Greg Hjelstrom *
- * *
- * $Modtime:: 2/06/01 3:21p $*
- * *
- * $Revision:: 3 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * DistLODDefClass -- default constructor for DistLODDefClass *
- * DistLODDefClass::DistLODDefClass -- manual constructor for DistLODDefClass *
- * DistLODDefClass::~DistLODDefClass -- destructor for DistLODDefClass *
- * DistLODDefClass::Free -- releases all memory in use by this object *
- * DistLODDefClass::Load -- initialize this object from a W3D file *
- * DistLODDefClass::read_header -- read the header from a W3D file *
- * DistLODDefClass::read_node -- read a model node description from a W3D file *
- * DistLODClass::DistLODClass -- constructor *
- * DistLODClass::DistLODClass -- copy constructor *
- * DistLODClass::~DistLODClass -- destructor *
- * DistLODClass::Free -- releases memory in use *
- * DistLODClass::Get_Name -- returns the name of this LOD object *
- * DistLODClass::Get_Num_Polys -- returns the number of polys in this model *
- * DistLODClass::Render -- Render this LOD. *
- * DistLODClass::Special_Render -- custom render function *
- * DistLODCLass::Get_Num_Sub_Objects -- returns the number of subobjects (levels of detail) *
- * DistLODClass::Get_Sub_Object -- returns pointer to the specified sub-object (LOD) *
- * DistLODCLass::Set_Transform -- sets the transform for this model *
- * DistLODClass::Set_Position -- set the position of this object *
- * DistLODClass::Set_Animation -- set the animation state of this model *
- * DistLODClass::Set_Animation -- set the animation state of this model *
- * DistLODClass::Set_Animation -- set the animation state to a blend of two anims *
- * DistLODClass::Set_Animation -- set the animation state to a combination of anims *
- * DistLODClass::Get_Num_Bones -- returns the number of bones *
- * DistLODClass::Get_Bone_Name -- returns the name of the specified bone *
- * DistLODClass::Get_Bone_Index -- returns the index of the given bone (if found) *
- * DistLODClass::Get_Bone_Transform -- returns the transform of the given bone *
- * DistLODClass::Get_Bone_Transform -- returns the transform of the given bone *
- * DistLODClass::Capture_Bone -- take control of a bone *
- * DistLODClass::Release_Bone -- release control of a bone *
- * DistLODClass::Is_Bone_Captured -- check whether the given bone is captured *
- * DistLODClass::Control_Bone -- set the transform for a captured bone *
- * DistLODClass::Cast_Ray -- cast a ray against this model *
- * DistLODClass::Cast_AABox -- perform an AABox cast against this model *
- * DistLODClass::Cast_OBBox -- perform an OBBox cast against this model *
- * DistLODCLass::Get_Num_Snap_Points -- returns number of snap points in this model *
- * DistLODClass::Get_Snap_Point -- returns the i'th snap point *
- * DistLODCLass::Scale -- scale this model; passes on to each LOD *
- * DistLODClass::Scale -- scale this model; passes on to each LOD *
- * DistLODClass::Update_LOD -- adjusts the current LOD based on the distance *
- * DistLODClass::Increment_Lod -- moves to a higher detail LOD *
- * DistLODClass::Decrement_Lod -- moves to a lower detail LOD *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "distlod.h"
- #include "nstrdup.h"
- #include "ww3d.h"
- #include "assetmgr.h"
- #include "camera.h"
- #include "w3derr.h"
- #include "wwdebug.h"
- #include "chunkio.h"
- #include "hlod.h"
- #include "rinfo.h"
- #include "coltest.h"
- #include "inttest.h"
- /*
- ** Loader Instance
- */
- DistLODLoaderClass _DistLODLoader;
- RenderObjClass * DistLODPrototypeClass::Create(void)
- {
- DistLODClass * dist = NEW_REF( DistLODClass , ( *Definition ) );
- // Have to pull each LOD out of the DistLOD, create a copy of the name
- // and destroy the DistLOD so that the models are "containerless". Also
- // invert the order of the models in the DistLOD
- char * name = nstrdup(dist->Get_Name());
- WWASSERT(name != NULL);
- int count = dist->Get_Num_Sub_Objects();
- RenderObjClass ** robj = W3DNEWARRAY RenderObjClass * [count];
- for (int i=0; i<count; i++) {
-
- robj[count - 1 - i] = dist->Get_Sub_Object(i);
- WWASSERT(robj[count - 1 - i] != NULL);
- }
- dist->Release_Ref();
-
- WWDEBUG_SAY(("OBSOLETE Dist-LOD model found! Please re-export %s!\r\n",name));
- HLodClass * hlod = NEW_REF(HLodClass , (name,robj,count));
- // Now, release the temporary refs and memory for the name
- for (i=0; i<count; i++) {
- robj[i]->Release_Ref();
- }
- free(name);
- return hlod;
- }
- /*
- ** The Prototype Loader
- */
- PrototypeClass *DistLODLoaderClass::Load_W3D( ChunkLoadClass &cload )
- {
- DistLODDefClass * pCDistLODClass = W3DNEW DistLODDefClass;
- if (pCDistLODClass == NULL)
- {
- return NULL;
- }
- if (pCDistLODClass->Load_W3D(cload) != WW3D_ERROR_OK)
- {
- // load failed, delete the model and return an error
- delete pCDistLODClass;
- return NULL;
- } else {
-
- // ok, accept this model!
- DistLODPrototypeClass *pCLODProto = W3DNEW DistLODPrototypeClass (pCDistLODClass);
- return pCLODProto;
- }
- }
- /***********************************************************************************************
- * DistLODDefClass -- default constructor for DistLODDefClass *
- * *
- * DistLODDefClass is a "blueprint" for constructing a DistLODClass *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- *=============================================================================================*/
- DistLODDefClass::DistLODDefClass(void) :
- Name(NULL),
- LodCount(0),
- Lods(NULL)
- {
- }
- /***********************************************************************************************
- * DistLODDefClass::DistLODDefClass -- manual constructor for DistLODDefClass *
- * *
- * This constructor allows you to create a DistLODDef Manually (and then use it to create *
- * the desired DistLODClass). The array of DistLODModelDefStructs which you pass in will *
- * only be read from so you are responsible for the memory used by them. *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/15/98 GTH : Created. *
- *=============================================================================================*/
- DistLODDefClass::DistLODDefClass(const char * name,int lodcount,DistLODNodeDefStruct * modeldefs) :
- Name(NULL),
- LodCount(0),
- Lods(NULL)
- {
- assert(name != NULL);
- Name = nstrdup(name);
- LodCount = lodcount;
- Lods = W3DNEWARRAY DistLODNodeDefStruct[LodCount];
- for (int i=0; i<LodCount; i++) {
- Lods[i].Name = nstrdup(modeldefs[i].Name);
- Lods[i].ResDownDist = modeldefs[i].ResDownDist;
- Lods[i].ResUpDist = modeldefs[i].ResUpDist;
- }
- }
- /***********************************************************************************************
- * DistLODDefClass::~DistLODDefClass -- destructor for DistLODDefClass *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/15/98 GTH : Created. *
- *=============================================================================================*/
- DistLODDefClass::~DistLODDefClass(void)
- {
- Free();
- }
- /***********************************************************************************************
- * DistLODDefClass::Free -- releases all memory in use by this object *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/15/98 GTH : Created. *
- *=============================================================================================*/
- void DistLODDefClass::Free(void)
- {
- if (Name != NULL) {
- delete[] Name;
- Name = NULL;
- }
- if (Lods != NULL) {
- for (int i=0; i<LodCount; i++) {
- if (Lods[i].Name != NULL) {
- delete[] Lods[i].Name;
- }
- }
- delete[] Lods;
- Lods = NULL;
- }
- LodCount = 0;
- }
- /***********************************************************************************************
- * DistLODDefClass::Load -- initialize this object from a W3D file *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/15/98 GTH : Created. *
- *=============================================================================================*/
- WW3DErrorType DistLODDefClass::Load_W3D(ChunkLoadClass & cload)
- {
- /*
- ** First make sure we release any memory in use
- */
- Free();
- if (read_header(cload) == false) {
- return WW3D_ERROR_LOAD_FAILED;
- }
- /*
- ** Loop through all the LODs and read the info from its chunk
- */
- for (int iLOD = 0; iLOD < LodCount; iLOD ++) {
- /*
- ** Open the next chunk, it should be a LOD struct
- */
- if (!cload.Open_Chunk()) return WW3D_ERROR_LOAD_FAILED;
- if (cload.Cur_Chunk_ID() != W3D_CHUNK_LOD) {
- // ERROR: Expected LOD struct!
- return WW3D_ERROR_LOAD_FAILED;
- }
- /*
- ** Read the data from the chunk into the LOD struct
- */
- W3dLODStruct lodStruct;
- if (cload.Read(&lodStruct,sizeof(W3dLODStruct)) != sizeof(W3dLODStruct)) {
- return WW3D_ERROR_LOAD_FAILED;
- }
- // Add the information from the chunk into the LOD array
- Lods[iLOD].Name = nstrdup (lodStruct.RenderObjName);
- Lods[iLOD].ResUpDist = lodStruct.LODMin;
- Lods[iLOD].ResDownDist = lodStruct.LODMax;
- // Close-out the chunk
- cload.Close_Chunk();
- }
- return WW3D_ERROR_OK;
- }
- /***********************************************************************************************
- * DistLODDefClass::read_header -- read the header from a W3D file *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/15/98 GTH : Created. *
- *=============================================================================================*/
- bool DistLODDefClass::read_header(ChunkLoadClass & cload)
- {
- /*
- ** Open the first chunk, it should be the LOD header
- */
- if (!cload.Open_Chunk()) return false;
- if (cload.Cur_Chunk_ID() != W3D_CHUNK_LODMODEL_HEADER) {
- // ERROR: Expected LOD Header!
- return false;
- }
- W3dLODModelHeaderStruct lodHeader;
- if (cload.Read(&lodHeader,sizeof(W3dLODModelHeaderStruct)) != sizeof(W3dLODModelHeaderStruct)) {
- return false;
- }
- cload.Close_Chunk();
- // Copy the name into our internal variable
- Name = ::nstrdup (lodHeader.Name);
- LodCount = lodHeader.NumLODs;
- Lods = W3DNEWARRAY DistLODNodeDefStruct[LodCount];
- return true;
- }
- /***********************************************************************************************
- * DistLODDefClass::read_node -- read a model node description from a W3D file *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/15/98 GTH : Created. *
- *=============================================================================================*/
- bool DistLODDefClass::read_node(ChunkLoadClass & cload,DistLODNodeDefStruct * node)
- {
- return true;
- }
- /***********************************************************************************************
- * DistLODClass::DistLODClass -- constructor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- DistLODClass::DistLODClass(const DistLODDefClass & def)
- {
- Set_Name(def.Get_Name());
- LodCount = def.LodCount;
- CurLod = 0;
- Lods = W3DNEWARRAY LODNodeClass[LodCount];
- for (int i=0; i<LodCount; i++) {
- // create a render object
- Lods[i].Model = WW3DAssetManager::Get_Instance()->Create_Render_Obj(def.Lods[i].Name);
- assert(Lods[i].Model != NULL);
- Lods[i].Model->Set_Container(this);
- // copy the distances
- Lods[i].ResUpDist = def.Lods[i].ResUpDist;
- Lods[i].ResDownDist = def.Lods[i].ResDownDist;
- }
- Update_Sub_Object_Bits();
- Update_Obj_Space_Bounding_Volumes();
- }
- /***********************************************************************************************
- * DistLODClass::DistLODClass -- copy constructor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- DistLODClass::DistLODClass(const DistLODClass & that) :
- CompositeRenderObjClass( that )
- {
- LodCount = that.LodCount;
- CurLod = VpPushLod = that.CurLod;
- Lods = W3DNEWARRAY LODNodeClass[LodCount];
- for (int i=0; i<LodCount; i++) {
- // create a render object
- Lods[i].Model = that.Lods[i].Model->Clone();
- assert(Lods[i].Model != NULL);
- Lods[i].Model->Set_Container(this);
- // copy the distances
- Lods[i].ResUpDist = that.Lods[i].ResUpDist;
- Lods[i].ResDownDist = that.Lods[i].ResDownDist;
- }
- Update_Obj_Space_Bounding_Volumes();
- }
- /***********************************************************************************************
- * DistLODClass::~DistLODClass -- destructor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- DistLODClass::~DistLODClass(void)
- {
- Free();
- }
- /***********************************************************************************************
- * DistLODClass::Free -- releases memory in use *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Free(void)
- {
- if (Lods != NULL) {
- for (int i=0; i<LodCount; i++) {
- if (Lods[i].Model != NULL) {
- Lods[i].Model->Set_Container(NULL);
- Lods[i].Model->Release_Ref();
- Lods[i].Model = NULL;
- }
- }
- delete[] Lods;
- Lods = NULL;
- }
- CurLod = 0;
- LodCount = 0;
- }
- /***********************************************************************************************
- * DistLODClass::Get_Num_Polys -- returns the number of polys in this model *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * returns the number of polys in the *current* lod. *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- int DistLODClass::Get_Num_Polys(void) const
- {
- return Lods[CurLod].Model->Get_Num_Polys();
- }
- /***********************************************************************************************
- * DistLODClass::Render -- Render this LOD. *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Render(RenderInfoClass & rinfo)
- {
- if (Is_Not_Hidden_At_All() == false) {
- return;
- }
- Update_Lod(rinfo.Camera);
- Lods[CurLod].Model->Render(rinfo);
- }
- /***********************************************************************************************
- * DistLODClass::Special_Render -- custom render function *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Special_Render(SpecialRenderInfoClass & rinfo)
- {
- Update_Lod(rinfo.Camera);
- Lods[CurLod].Model->Special_Render(rinfo);
- }
- /***********************************************************************************************
- * DistLODCLass::Get_Num_Sub_Objects -- returns the number of subobjects (levels of detail) *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/1/99 GTH : Created. *
- *=============================================================================================*/
- int DistLODClass::Get_Num_Sub_Objects(void) const
- {
- return LodCount;
- }
- /***********************************************************************************************
- * DistLODClass::Get_Sub_Object -- returns pointer to the specified sub-object (LOD) *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/1/99 GTH : Created. *
- *=============================================================================================*/
- RenderObjClass * DistLODClass::Get_Sub_Object(int index) const
- {
- assert(index >= 0);
- assert(index < LodCount);
-
- if (Lods[index].Model == NULL) {
- return NULL;
- } else {
- Lods[index].Model->Add_Ref();
- return Lods[index].Model;
- }
- }
- int DistLODClass::Add_Sub_Object_To_Bone(RenderObjClass * subobj,int bone_index)
- {
- // NOTE: this is broken code, a render object cannot have two containers...
- if (subobj->Class_ID() == CLASSID_DISTLOD) {
- // Add each lod of the sub object to a cooresponding model of mine
- DistLODClass * sub_lod_obj = (DistLODClass *)subobj;
- for (int i=0; i< LodCount; i++) {
- Lods[i].Model->Add_Sub_Object_To_Bone( sub_lod_obj->Lods[ MIN( i, sub_lod_obj->LodCount-1 ) ].Model, bone_index);
- }
- } else {
- Lods[0].Model->Add_Sub_Object_To_Bone( subobj, bone_index);
- }
- return 0;
- }
- /***********************************************************************************************
- * DistLODCLass::Set_Transform -- sets the transform for this model *
- * *
- * sets the transform in all LODs. *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Set_Transform(const Matrix3D &m)
- {
- RenderObjClass::Set_Transform(m);
- for (int i=0; i<LodCount; i++) {
- assert(Lods[i].Model != NULL);
- Lods[i].Model->Set_Transform(m);
- }
- }
- /***********************************************************************************************
- * DistLODClass::Set_Position -- set the position of this object *
- * *
- * sets the position of all lods *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Set_Position(const Vector3 &v)
- {
- RenderObjClass::Set_Position(v);
- for (int i=0; i<LodCount; i++) {
- assert(Lods[i].Model != NULL);
- Lods[i].Model->Set_Position(v);
- }
- }
- /***********************************************************************************************
- * DistLODClass::Set_Animation -- set the animation state of this model *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Set_Animation( void )
- {
- for (int i=0; i<LodCount; i++) {
- assert(Lods[i].Model != NULL);
- Lods[i].Model->Set_Animation();
- }
- }
- /***********************************************************************************************
- * DistLODClass::Set_Animation -- set the animation state of this model *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Set_Animation( HAnimClass * motion,float frame,int mode)
- {
- for (int i=0; i<LodCount; i++) {
- assert(Lods[i].Model != NULL);
- Lods[i].Model->Set_Animation(motion,frame,mode);
- }
- }
- /***********************************************************************************************
- * DistLODClass::Set_Animation -- set the animation state to a blend of two anims *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Set_Animation( HAnimClass * motion0,float frame0,HAnimClass * motion1,float frame1,float percentage)
- {
- for (int i=0; i<LodCount; i++) {
- assert(Lods[i].Model != NULL);
- Lods[i].Model->Set_Animation(motion0,frame0,motion1,frame1,percentage);
- }
- }
-
- /***********************************************************************************************
- * DistLODClass::Set_Animation -- set the animation state to a combination of anims *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Set_Animation( HAnimComboClass * anim_combo)
- {
- for (int i=0; i<LodCount; i++) {
- assert(Lods[i].Model != NULL);
- Lods[i].Model->Set_Animation( anim_combo);
- }
- }
-
- /***********************************************************************************************
- * DistLODClass::Peek_Animation *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 12/8/98 GTH : Created. *
- *=============================================================================================*/
- HAnimClass * DistLODClass::Peek_Animation( void )
- {
- return Lods[0].Model->Peek_Animation();
- }
- /***********************************************************************************************
- * DistLODClass::Get_Num_Bones -- returns the number of bones *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- int DistLODClass::Get_Num_Bones(void)
- {
- return Lods[0].Model->Get_Num_Bones();
- }
- /***********************************************************************************************
- * DistLODClass::Get_Bone_Name -- returns the name of the specified bone *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- const char * DistLODClass::Get_Bone_Name(int bone_index)
- {
- return Lods[0].Model->Get_Bone_Name(bone_index);
- }
- /***********************************************************************************************
- * DistLODClass::Get_Bone_Index -- returns the index of the given bone (if found) *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- int DistLODClass::Get_Bone_Index(const char * bonename)
- {
- // Highest LOD is used since lowest may be a Null3DObjClass.
- return Lods[0].Model->Get_Bone_Index(bonename);
- }
- /***********************************************************************************************
- * DistLODClass::Get_Bone_Transform -- returns the transform of the given bone *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- const Matrix3D & DistLODClass::Get_Bone_Transform(const char * bonename)
- {
- // Highest LOD is used since lowest may be a Null3DObjClass.
- return Lods[0].Model->Get_Bone_Transform(bonename);
- }
- /***********************************************************************************************
- * DistLODClass::Get_Bone_Transform -- returns the transform of the given bone *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- const Matrix3D & DistLODClass::Get_Bone_Transform(int boneindex)
- {
- // Highest LOD is used since lowest may be a Null3DObjClass.
- return Lods[0].Model->Get_Bone_Transform(boneindex);
- }
- /***********************************************************************************************
- * DistLODClass::Capture_Bone -- take control of a bone *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Capture_Bone(int bindex)
- {
- for (int i=0; i<LodCount; i++) {
- assert(Lods[i].Model != NULL);
- Lods[i].Model->Capture_Bone(bindex);
- }
- }
- /***********************************************************************************************
- * DistLODClass::Release_Bone -- release control of a bone *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Release_Bone(int bindex)
- {
- for (int i=0; i<LodCount; i++) {
- assert(Lods[i].Model != NULL);
- Lods[i].Model->Release_Bone(bindex);
- }
- }
- /***********************************************************************************************
- * DistLODClass::Is_Bone_Captured -- check whether the given bone is captured *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- bool DistLODClass::Is_Bone_Captured(int bindex) const
- {
- // Highest LOD is used since lowest may be a Null3DObjClass.
- return Lods[0].Model->Is_Bone_Captured(bindex);
- }
- /***********************************************************************************************
- * DistLODClass::Control_Bone -- set the transform for a captured bone *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Control_Bone(int bindex,const Matrix3D & tm,bool world_space_translation)
- {
- for (int i=0; i<LodCount; i++) {
- assert(Lods[i].Model != NULL);
- Lods[i].Model->Control_Bone(bindex,tm,world_space_translation);
- }
- }
- /***********************************************************************************************
- * DistLODClass::Cast_Ray -- cast a ray against this model *
- * *
- * casts the ray against the top-level LOD *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- bool DistLODClass::Cast_Ray(RayCollisionTestClass & raytest)
- {
- if (raytest.CollisionType & Get_Collision_Type()) {
- return Lods[HIGHEST_LOD].Model->Cast_Ray(raytest);
- } else {
- return false;
- }
- }
- /***********************************************************************************************
- * DistLODClass::Cast_AABox -- perform an AABox cast against this model *
- * *
- * tests against the top-level LOD *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/3/99 GTH : Created. *
- *=============================================================================================*/
- bool DistLODClass::Cast_AABox(AABoxCollisionTestClass & boxtest)
- {
- if (boxtest.CollisionType & Get_Collision_Type()) {
- return Lods[HIGHEST_LOD].Model->Cast_AABox(boxtest);
- } else {
- return false;
- }
- }
- /***********************************************************************************************
- * DistLODClass::Cast_OBBox -- perform an OBBox cast against this model *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/1/99 GTH : Created. *
- *=============================================================================================*/
- bool DistLODClass::Cast_OBBox(OBBoxCollisionTestClass & boxtest)
- {
- if (boxtest.CollisionType & Get_Collision_Type()) {
- return Lods[HIGHEST_LOD].Model->Cast_OBBox(boxtest);
- } else {
- return false;
- }
- }
- /***********************************************************************************************
- * DistLODCLass::Get_Num_Snap_Points -- returns number of snap points in this model *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/1/99 GTH : Created. *
- *=============================================================================================*/
- int DistLODClass::Get_Num_Snap_Points(void)
- {
- return Lods[0].Model->Get_Num_Snap_Points();
- }
- /***********************************************************************************************
- * DistLODClass::Get_Snap_Point -- returns the i'th snap point *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/1/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Get_Snap_Point(int index,Vector3 * set)
- {
- Lods[0].Model->Get_Snap_Point(index,set);
- }
- /***********************************************************************************************
- * DistLODCLass::Scale -- scale this model; passes on to each LOD *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/1/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Scale(float scale)
- {
- for (int i=0; i<LodCount; i++) {
- assert(Lods[CurLod].Model != NULL);
- Lods[CurLod].Model->Scale(scale);
- }
- }
- /***********************************************************************************************
- * DistLODClass::Scale -- scale this model; passes on to each LOD *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/1/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Scale(float scalex, float scaley, float scalez)
- {
- for (int i=0; i<LodCount; i++) {
- assert(Lods[i].Model != NULL);
- Lods[i].Model->Scale(scalex,scaley,scalez);
- }
- }
- /***********************************************************************************************
- * DistLODClass::Update_LOD -- adjusts the current LOD based on the distance *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/1/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Update_Lod(const CameraClass & camera)
- {
- // evaluate the distance from the camera and select an LOD based on it.
- float dist = (
- camera.Get_Position() -
- Lods[CurLod].Model->Get_Bounding_Sphere().Center
- ).Quick_Length();
- if (dist < Lods[CurLod].ResUpDist) {
- Increment_Lod();
- } else if (dist > Lods[CurLod].ResDownDist) {
- Decrement_Lod();
- }
- }
- /***********************************************************************************************
- * DistLODClass::Increment_Lod -- moves to a higher detail LOD *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/1/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Increment_Lod(void)
- {
- // TODO: change the order in which models are stored
- if (CurLod > 0) {
- if (Is_In_Scene()) {
- Lods[CurLod].Model->Notify_Removed(Scene);
- }
- CurLod--;
- if (Is_In_Scene()) {
- Lods[CurLod].Model->Notify_Added(Scene);
- }
- }
- }
- /***********************************************************************************************
- * DistLODClass::Decrement_Lod -- moves to a lower detail LOD *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/1/99 GTH : Created. *
- *=============================================================================================*/
- void DistLODClass::Decrement_Lod(void)
- {
- if (CurLod < LodCount - 1) {
- if (Is_In_Scene()) {
- Lods[CurLod].Model->Notify_Removed(Scene);
- }
- CurLod++;
- if (Is_In_Scene()) {
- Lods[CurLod].Model->Notify_Added(Scene);
- }
- }
- }
|