distlod.cpp 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  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/distlod.cpp $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 2/06/01 3:21p $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * DistLODDefClass -- default constructor for DistLODDefClass *
  35. * DistLODDefClass::DistLODDefClass -- manual constructor for DistLODDefClass *
  36. * DistLODDefClass::~DistLODDefClass -- destructor for DistLODDefClass *
  37. * DistLODDefClass::Free -- releases all memory in use by this object *
  38. * DistLODDefClass::Load -- initialize this object from a W3D file *
  39. * DistLODDefClass::read_header -- read the header from a W3D file *
  40. * DistLODDefClass::read_node -- read a model node description from a W3D file *
  41. * DistLODClass::DistLODClass -- constructor *
  42. * DistLODClass::DistLODClass -- copy constructor *
  43. * DistLODClass::~DistLODClass -- destructor *
  44. * DistLODClass::Free -- releases memory in use *
  45. * DistLODClass::Get_Name -- returns the name of this LOD object *
  46. * DistLODClass::Get_Num_Polys -- returns the number of polys in this model *
  47. * DistLODClass::Render -- Render this LOD. *
  48. * DistLODClass::Special_Render -- custom render function *
  49. * DistLODCLass::Get_Num_Sub_Objects -- returns the number of subobjects (levels of detail) *
  50. * DistLODClass::Get_Sub_Object -- returns pointer to the specified sub-object (LOD) *
  51. * DistLODCLass::Set_Transform -- sets the transform for this model *
  52. * DistLODClass::Set_Position -- set the position of this object *
  53. * DistLODClass::Set_Animation -- set the animation state of this model *
  54. * DistLODClass::Set_Animation -- set the animation state of this model *
  55. * DistLODClass::Set_Animation -- set the animation state to a blend of two anims *
  56. * DistLODClass::Set_Animation -- set the animation state to a combination of anims *
  57. * DistLODClass::Get_Num_Bones -- returns the number of bones *
  58. * DistLODClass::Get_Bone_Name -- returns the name of the specified bone *
  59. * DistLODClass::Get_Bone_Index -- returns the index of the given bone (if found) *
  60. * DistLODClass::Get_Bone_Transform -- returns the transform of the given bone *
  61. * DistLODClass::Get_Bone_Transform -- returns the transform of the given bone *
  62. * DistLODClass::Capture_Bone -- take control of a bone *
  63. * DistLODClass::Release_Bone -- release control of a bone *
  64. * DistLODClass::Is_Bone_Captured -- check whether the given bone is captured *
  65. * DistLODClass::Control_Bone -- set the transform for a captured bone *
  66. * DistLODClass::Cast_Ray -- cast a ray against this model *
  67. * DistLODClass::Cast_AABox -- perform an AABox cast against this model *
  68. * DistLODClass::Cast_OBBox -- perform an OBBox cast against this model *
  69. * DistLODCLass::Get_Num_Snap_Points -- returns number of snap points in this model *
  70. * DistLODClass::Get_Snap_Point -- returns the i'th snap point *
  71. * DistLODCLass::Scale -- scale this model; passes on to each LOD *
  72. * DistLODClass::Scale -- scale this model; passes on to each LOD *
  73. * DistLODClass::Update_LOD -- adjusts the current LOD based on the distance *
  74. * DistLODClass::Increment_Lod -- moves to a higher detail LOD *
  75. * DistLODClass::Decrement_Lod -- moves to a lower detail LOD *
  76. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  77. #include "distlod.h"
  78. #include "nstrdup.h"
  79. #include "ww3d.h"
  80. #include "assetmgr.h"
  81. #include "camera.h"
  82. #include "w3derr.h"
  83. #include "wwdebug.h"
  84. #include "chunkio.h"
  85. #include "hlod.h"
  86. #include "rinfo.h"
  87. #include "coltest.h"
  88. #include "inttest.h"
  89. /*
  90. ** Loader Instance
  91. */
  92. DistLODLoaderClass _DistLODLoader;
  93. RenderObjClass * DistLODPrototypeClass::Create(void)
  94. {
  95. DistLODClass * dist = NEW_REF( DistLODClass , ( *Definition ) );
  96. // Have to pull each LOD out of the DistLOD, create a copy of the name
  97. // and destroy the DistLOD so that the models are "containerless". Also
  98. // invert the order of the models in the DistLOD
  99. char * name = nstrdup(dist->Get_Name());
  100. WWASSERT(name != NULL);
  101. int count = dist->Get_Num_Sub_Objects();
  102. RenderObjClass ** robj = W3DNEWARRAY RenderObjClass * [count];
  103. for (int i=0; i<count; i++) {
  104. robj[count - 1 - i] = dist->Get_Sub_Object(i);
  105. WWASSERT(robj[count - 1 - i] != NULL);
  106. }
  107. dist->Release_Ref();
  108. WWDEBUG_SAY(("OBSOLETE Dist-LOD model found! Please re-export %s!\r\n",name));
  109. HLodClass * hlod = NEW_REF(HLodClass , (name,robj,count));
  110. // Now, release the temporary refs and memory for the name
  111. for (i=0; i<count; i++) {
  112. robj[i]->Release_Ref();
  113. }
  114. free(name);
  115. return hlod;
  116. }
  117. /*
  118. ** The Prototype Loader
  119. */
  120. PrototypeClass *DistLODLoaderClass::Load_W3D( ChunkLoadClass &cload )
  121. {
  122. DistLODDefClass * pCDistLODClass = W3DNEW DistLODDefClass;
  123. if (pCDistLODClass == NULL)
  124. {
  125. return NULL;
  126. }
  127. if (pCDistLODClass->Load_W3D(cload) != WW3D_ERROR_OK)
  128. {
  129. // load failed, delete the model and return an error
  130. delete pCDistLODClass;
  131. return NULL;
  132. } else {
  133. // ok, accept this model!
  134. DistLODPrototypeClass *pCLODProto = W3DNEW DistLODPrototypeClass (pCDistLODClass);
  135. return pCLODProto;
  136. }
  137. }
  138. /***********************************************************************************************
  139. * DistLODDefClass -- default constructor for DistLODDefClass *
  140. * *
  141. * DistLODDefClass is a "blueprint" for constructing a DistLODClass *
  142. * *
  143. * INPUT: *
  144. * *
  145. * OUTPUT: *
  146. * *
  147. * WARNINGS: *
  148. * *
  149. * HISTORY: *
  150. *=============================================================================================*/
  151. DistLODDefClass::DistLODDefClass(void) :
  152. Name(NULL),
  153. LodCount(0),
  154. Lods(NULL)
  155. {
  156. }
  157. /***********************************************************************************************
  158. * DistLODDefClass::DistLODDefClass -- manual constructor for DistLODDefClass *
  159. * *
  160. * This constructor allows you to create a DistLODDef Manually (and then use it to create *
  161. * the desired DistLODClass). The array of DistLODModelDefStructs which you pass in will *
  162. * only be read from so you are responsible for the memory used by them. *
  163. * *
  164. * INPUT: *
  165. * *
  166. * OUTPUT: *
  167. * *
  168. * WARNINGS: *
  169. * *
  170. * HISTORY: *
  171. * 7/15/98 GTH : Created. *
  172. *=============================================================================================*/
  173. DistLODDefClass::DistLODDefClass(const char * name,int lodcount,DistLODNodeDefStruct * modeldefs) :
  174. Name(NULL),
  175. LodCount(0),
  176. Lods(NULL)
  177. {
  178. assert(name != NULL);
  179. Name = nstrdup(name);
  180. LodCount = lodcount;
  181. Lods = W3DNEWARRAY DistLODNodeDefStruct[LodCount];
  182. for (int i=0; i<LodCount; i++) {
  183. Lods[i].Name = nstrdup(modeldefs[i].Name);
  184. Lods[i].ResDownDist = modeldefs[i].ResDownDist;
  185. Lods[i].ResUpDist = modeldefs[i].ResUpDist;
  186. }
  187. }
  188. /***********************************************************************************************
  189. * DistLODDefClass::~DistLODDefClass -- destructor for DistLODDefClass *
  190. * *
  191. * INPUT: *
  192. * *
  193. * OUTPUT: *
  194. * *
  195. * WARNINGS: *
  196. * *
  197. * HISTORY: *
  198. * 7/15/98 GTH : Created. *
  199. *=============================================================================================*/
  200. DistLODDefClass::~DistLODDefClass(void)
  201. {
  202. Free();
  203. }
  204. /***********************************************************************************************
  205. * DistLODDefClass::Free -- releases all memory in use by this object *
  206. * *
  207. * INPUT: *
  208. * *
  209. * OUTPUT: *
  210. * *
  211. * WARNINGS: *
  212. * *
  213. * HISTORY: *
  214. * 7/15/98 GTH : Created. *
  215. *=============================================================================================*/
  216. void DistLODDefClass::Free(void)
  217. {
  218. if (Name != NULL) {
  219. delete[] Name;
  220. Name = NULL;
  221. }
  222. if (Lods != NULL) {
  223. for (int i=0; i<LodCount; i++) {
  224. if (Lods[i].Name != NULL) {
  225. delete[] Lods[i].Name;
  226. }
  227. }
  228. delete[] Lods;
  229. Lods = NULL;
  230. }
  231. LodCount = 0;
  232. }
  233. /***********************************************************************************************
  234. * DistLODDefClass::Load -- initialize this object from a W3D file *
  235. * *
  236. * INPUT: *
  237. * *
  238. * OUTPUT: *
  239. * *
  240. * WARNINGS: *
  241. * *
  242. * HISTORY: *
  243. * 7/15/98 GTH : Created. *
  244. *=============================================================================================*/
  245. WW3DErrorType DistLODDefClass::Load_W3D(ChunkLoadClass & cload)
  246. {
  247. /*
  248. ** First make sure we release any memory in use
  249. */
  250. Free();
  251. if (read_header(cload) == false) {
  252. return WW3D_ERROR_LOAD_FAILED;
  253. }
  254. /*
  255. ** Loop through all the LODs and read the info from its chunk
  256. */
  257. for (int iLOD = 0; iLOD < LodCount; iLOD ++) {
  258. /*
  259. ** Open the next chunk, it should be a LOD struct
  260. */
  261. if (!cload.Open_Chunk()) return WW3D_ERROR_LOAD_FAILED;
  262. if (cload.Cur_Chunk_ID() != W3D_CHUNK_LOD) {
  263. // ERROR: Expected LOD struct!
  264. return WW3D_ERROR_LOAD_FAILED;
  265. }
  266. /*
  267. ** Read the data from the chunk into the LOD struct
  268. */
  269. W3dLODStruct lodStruct;
  270. if (cload.Read(&lodStruct,sizeof(W3dLODStruct)) != sizeof(W3dLODStruct)) {
  271. return WW3D_ERROR_LOAD_FAILED;
  272. }
  273. // Add the information from the chunk into the LOD array
  274. Lods[iLOD].Name = nstrdup (lodStruct.RenderObjName);
  275. Lods[iLOD].ResUpDist = lodStruct.LODMin;
  276. Lods[iLOD].ResDownDist = lodStruct.LODMax;
  277. // Close-out the chunk
  278. cload.Close_Chunk();
  279. }
  280. return WW3D_ERROR_OK;
  281. }
  282. /***********************************************************************************************
  283. * DistLODDefClass::read_header -- read the header from a W3D file *
  284. * *
  285. * INPUT: *
  286. * *
  287. * OUTPUT: *
  288. * *
  289. * WARNINGS: *
  290. * *
  291. * HISTORY: *
  292. * 7/15/98 GTH : Created. *
  293. *=============================================================================================*/
  294. bool DistLODDefClass::read_header(ChunkLoadClass & cload)
  295. {
  296. /*
  297. ** Open the first chunk, it should be the LOD header
  298. */
  299. if (!cload.Open_Chunk()) return false;
  300. if (cload.Cur_Chunk_ID() != W3D_CHUNK_LODMODEL_HEADER) {
  301. // ERROR: Expected LOD Header!
  302. return false;
  303. }
  304. W3dLODModelHeaderStruct lodHeader;
  305. if (cload.Read(&lodHeader,sizeof(W3dLODModelHeaderStruct)) != sizeof(W3dLODModelHeaderStruct)) {
  306. return false;
  307. }
  308. cload.Close_Chunk();
  309. // Copy the name into our internal variable
  310. Name = ::nstrdup (lodHeader.Name);
  311. LodCount = lodHeader.NumLODs;
  312. Lods = W3DNEWARRAY DistLODNodeDefStruct[LodCount];
  313. return true;
  314. }
  315. /***********************************************************************************************
  316. * DistLODDefClass::read_node -- read a model node description from a W3D file *
  317. * *
  318. * INPUT: *
  319. * *
  320. * OUTPUT: *
  321. * *
  322. * WARNINGS: *
  323. * *
  324. * HISTORY: *
  325. * 7/15/98 GTH : Created. *
  326. *=============================================================================================*/
  327. bool DistLODDefClass::read_node(ChunkLoadClass & cload,DistLODNodeDefStruct * node)
  328. {
  329. return true;
  330. }
  331. /***********************************************************************************************
  332. * DistLODClass::DistLODClass -- constructor *
  333. * *
  334. * INPUT: *
  335. * *
  336. * OUTPUT: *
  337. * *
  338. * WARNINGS: *
  339. * *
  340. * HISTORY: *
  341. * 3/3/99 GTH : Created. *
  342. *=============================================================================================*/
  343. DistLODClass::DistLODClass(const DistLODDefClass & def)
  344. {
  345. Set_Name(def.Get_Name());
  346. LodCount = def.LodCount;
  347. CurLod = 0;
  348. Lods = W3DNEWARRAY LODNodeClass[LodCount];
  349. for (int i=0; i<LodCount; i++) {
  350. // create a render object
  351. Lods[i].Model = WW3DAssetManager::Get_Instance()->Create_Render_Obj(def.Lods[i].Name);
  352. assert(Lods[i].Model != NULL);
  353. Lods[i].Model->Set_Container(this);
  354. // copy the distances
  355. Lods[i].ResUpDist = def.Lods[i].ResUpDist;
  356. Lods[i].ResDownDist = def.Lods[i].ResDownDist;
  357. }
  358. Update_Sub_Object_Bits();
  359. Update_Obj_Space_Bounding_Volumes();
  360. }
  361. /***********************************************************************************************
  362. * DistLODClass::DistLODClass -- copy constructor *
  363. * *
  364. * INPUT: *
  365. * *
  366. * OUTPUT: *
  367. * *
  368. * WARNINGS: *
  369. * *
  370. * HISTORY: *
  371. * 3/3/99 GTH : Created. *
  372. *=============================================================================================*/
  373. DistLODClass::DistLODClass(const DistLODClass & that) :
  374. CompositeRenderObjClass( that )
  375. {
  376. LodCount = that.LodCount;
  377. CurLod = VpPushLod = that.CurLod;
  378. Lods = W3DNEWARRAY LODNodeClass[LodCount];
  379. for (int i=0; i<LodCount; i++) {
  380. // create a render object
  381. Lods[i].Model = that.Lods[i].Model->Clone();
  382. assert(Lods[i].Model != NULL);
  383. Lods[i].Model->Set_Container(this);
  384. // copy the distances
  385. Lods[i].ResUpDist = that.Lods[i].ResUpDist;
  386. Lods[i].ResDownDist = that.Lods[i].ResDownDist;
  387. }
  388. Update_Obj_Space_Bounding_Volumes();
  389. }
  390. /***********************************************************************************************
  391. * DistLODClass::~DistLODClass -- destructor *
  392. * *
  393. * INPUT: *
  394. * *
  395. * OUTPUT: *
  396. * *
  397. * WARNINGS: *
  398. * *
  399. * HISTORY: *
  400. * 3/3/99 GTH : Created. *
  401. *=============================================================================================*/
  402. DistLODClass::~DistLODClass(void)
  403. {
  404. Free();
  405. }
  406. /***********************************************************************************************
  407. * DistLODClass::Free -- releases memory in use *
  408. * *
  409. * INPUT: *
  410. * *
  411. * OUTPUT: *
  412. * *
  413. * WARNINGS: *
  414. * *
  415. * HISTORY: *
  416. * 3/3/99 GTH : Created. *
  417. *=============================================================================================*/
  418. void DistLODClass::Free(void)
  419. {
  420. if (Lods != NULL) {
  421. for (int i=0; i<LodCount; i++) {
  422. if (Lods[i].Model != NULL) {
  423. Lods[i].Model->Set_Container(NULL);
  424. Lods[i].Model->Release_Ref();
  425. Lods[i].Model = NULL;
  426. }
  427. }
  428. delete[] Lods;
  429. Lods = NULL;
  430. }
  431. CurLod = 0;
  432. LodCount = 0;
  433. }
  434. /***********************************************************************************************
  435. * DistLODClass::Get_Num_Polys -- returns the number of polys in this model *
  436. * *
  437. * INPUT: *
  438. * *
  439. * OUTPUT: *
  440. * *
  441. * WARNINGS: *
  442. * returns the number of polys in the *current* lod. *
  443. * *
  444. * HISTORY: *
  445. * 3/3/99 GTH : Created. *
  446. *=============================================================================================*/
  447. int DistLODClass::Get_Num_Polys(void) const
  448. {
  449. return Lods[CurLod].Model->Get_Num_Polys();
  450. }
  451. /***********************************************************************************************
  452. * DistLODClass::Render -- Render this LOD. *
  453. * *
  454. * INPUT: *
  455. * *
  456. * OUTPUT: *
  457. * *
  458. * WARNINGS: *
  459. * *
  460. * HISTORY: *
  461. * 3/3/99 GTH : Created. *
  462. *=============================================================================================*/
  463. void DistLODClass::Render(RenderInfoClass & rinfo)
  464. {
  465. if (Is_Not_Hidden_At_All() == false) {
  466. return;
  467. }
  468. Update_Lod(rinfo.Camera);
  469. Lods[CurLod].Model->Render(rinfo);
  470. }
  471. /***********************************************************************************************
  472. * DistLODClass::Special_Render -- custom render function *
  473. * *
  474. * INPUT: *
  475. * *
  476. * OUTPUT: *
  477. * *
  478. * WARNINGS: *
  479. * *
  480. * HISTORY: *
  481. * 3/3/99 GTH : Created. *
  482. *=============================================================================================*/
  483. void DistLODClass::Special_Render(SpecialRenderInfoClass & rinfo)
  484. {
  485. Update_Lod(rinfo.Camera);
  486. Lods[CurLod].Model->Special_Render(rinfo);
  487. }
  488. /***********************************************************************************************
  489. * DistLODCLass::Get_Num_Sub_Objects -- returns the number of subobjects (levels of detail) *
  490. * *
  491. * INPUT: *
  492. * *
  493. * OUTPUT: *
  494. * *
  495. * WARNINGS: *
  496. * *
  497. * HISTORY: *
  498. * 3/1/99 GTH : Created. *
  499. *=============================================================================================*/
  500. int DistLODClass::Get_Num_Sub_Objects(void) const
  501. {
  502. return LodCount;
  503. }
  504. /***********************************************************************************************
  505. * DistLODClass::Get_Sub_Object -- returns pointer to the specified sub-object (LOD) *
  506. * *
  507. * INPUT: *
  508. * *
  509. * OUTPUT: *
  510. * *
  511. * WARNINGS: *
  512. * *
  513. * HISTORY: *
  514. * 3/1/99 GTH : Created. *
  515. *=============================================================================================*/
  516. RenderObjClass * DistLODClass::Get_Sub_Object(int index) const
  517. {
  518. assert(index >= 0);
  519. assert(index < LodCount);
  520. if (Lods[index].Model == NULL) {
  521. return NULL;
  522. } else {
  523. Lods[index].Model->Add_Ref();
  524. return Lods[index].Model;
  525. }
  526. }
  527. int DistLODClass::Add_Sub_Object_To_Bone(RenderObjClass * subobj,int bone_index)
  528. {
  529. // NOTE: this is broken code, a render object cannot have two containers...
  530. if (subobj->Class_ID() == CLASSID_DISTLOD) {
  531. // Add each lod of the sub object to a cooresponding model of mine
  532. DistLODClass * sub_lod_obj = (DistLODClass *)subobj;
  533. for (int i=0; i< LodCount; i++) {
  534. Lods[i].Model->Add_Sub_Object_To_Bone( sub_lod_obj->Lods[ MIN( i, sub_lod_obj->LodCount-1 ) ].Model, bone_index);
  535. }
  536. } else {
  537. Lods[0].Model->Add_Sub_Object_To_Bone( subobj, bone_index);
  538. }
  539. return 0;
  540. }
  541. /***********************************************************************************************
  542. * DistLODCLass::Set_Transform -- sets the transform for this model *
  543. * *
  544. * sets the transform in all LODs. *
  545. * *
  546. * INPUT: *
  547. * *
  548. * OUTPUT: *
  549. * *
  550. * WARNINGS: *
  551. * *
  552. * HISTORY: *
  553. * 3/3/99 GTH : Created. *
  554. *=============================================================================================*/
  555. void DistLODClass::Set_Transform(const Matrix3D &m)
  556. {
  557. RenderObjClass::Set_Transform(m);
  558. for (int i=0; i<LodCount; i++) {
  559. assert(Lods[i].Model != NULL);
  560. Lods[i].Model->Set_Transform(m);
  561. }
  562. }
  563. /***********************************************************************************************
  564. * DistLODClass::Set_Position -- set the position of this object *
  565. * *
  566. * sets the position of all lods *
  567. * *
  568. * INPUT: *
  569. * *
  570. * OUTPUT: *
  571. * *
  572. * WARNINGS: *
  573. * *
  574. * HISTORY: *
  575. * 3/3/99 GTH : Created. *
  576. *=============================================================================================*/
  577. void DistLODClass::Set_Position(const Vector3 &v)
  578. {
  579. RenderObjClass::Set_Position(v);
  580. for (int i=0; i<LodCount; i++) {
  581. assert(Lods[i].Model != NULL);
  582. Lods[i].Model->Set_Position(v);
  583. }
  584. }
  585. /***********************************************************************************************
  586. * DistLODClass::Set_Animation -- set the animation state of this model *
  587. * *
  588. * INPUT: *
  589. * *
  590. * OUTPUT: *
  591. * *
  592. * WARNINGS: *
  593. * *
  594. * HISTORY: *
  595. * 3/3/99 GTH : Created. *
  596. *=============================================================================================*/
  597. void DistLODClass::Set_Animation( void )
  598. {
  599. for (int i=0; i<LodCount; i++) {
  600. assert(Lods[i].Model != NULL);
  601. Lods[i].Model->Set_Animation();
  602. }
  603. }
  604. /***********************************************************************************************
  605. * DistLODClass::Set_Animation -- set the animation state of this model *
  606. * *
  607. * INPUT: *
  608. * *
  609. * OUTPUT: *
  610. * *
  611. * WARNINGS: *
  612. * *
  613. * HISTORY: *
  614. * 3/3/99 GTH : Created. *
  615. *=============================================================================================*/
  616. void DistLODClass::Set_Animation( HAnimClass * motion,float frame,int mode)
  617. {
  618. for (int i=0; i<LodCount; i++) {
  619. assert(Lods[i].Model != NULL);
  620. Lods[i].Model->Set_Animation(motion,frame,mode);
  621. }
  622. }
  623. /***********************************************************************************************
  624. * DistLODClass::Set_Animation -- set the animation state to a blend of two anims *
  625. * *
  626. * INPUT: *
  627. * *
  628. * OUTPUT: *
  629. * *
  630. * WARNINGS: *
  631. * *
  632. * HISTORY: *
  633. * 3/3/99 GTH : Created. *
  634. *=============================================================================================*/
  635. void DistLODClass::Set_Animation( HAnimClass * motion0,float frame0,HAnimClass * motion1,float frame1,float percentage)
  636. {
  637. for (int i=0; i<LodCount; i++) {
  638. assert(Lods[i].Model != NULL);
  639. Lods[i].Model->Set_Animation(motion0,frame0,motion1,frame1,percentage);
  640. }
  641. }
  642. /***********************************************************************************************
  643. * DistLODClass::Set_Animation -- set the animation state to a combination of anims *
  644. * *
  645. * INPUT: *
  646. * *
  647. * OUTPUT: *
  648. * *
  649. * WARNINGS: *
  650. * *
  651. * HISTORY: *
  652. * 3/3/99 GTH : Created. *
  653. *=============================================================================================*/
  654. void DistLODClass::Set_Animation( HAnimComboClass * anim_combo)
  655. {
  656. for (int i=0; i<LodCount; i++) {
  657. assert(Lods[i].Model != NULL);
  658. Lods[i].Model->Set_Animation( anim_combo);
  659. }
  660. }
  661. /***********************************************************************************************
  662. * DistLODClass::Peek_Animation *
  663. * *
  664. * INPUT: *
  665. * *
  666. * OUTPUT: *
  667. * *
  668. * WARNINGS: *
  669. * *
  670. * HISTORY: *
  671. * 12/8/98 GTH : Created. *
  672. *=============================================================================================*/
  673. HAnimClass * DistLODClass::Peek_Animation( void )
  674. {
  675. return Lods[0].Model->Peek_Animation();
  676. }
  677. /***********************************************************************************************
  678. * DistLODClass::Get_Num_Bones -- returns the number of bones *
  679. * *
  680. * INPUT: *
  681. * *
  682. * OUTPUT: *
  683. * *
  684. * WARNINGS: *
  685. * *
  686. * HISTORY: *
  687. * 3/3/99 GTH : Created. *
  688. *=============================================================================================*/
  689. int DistLODClass::Get_Num_Bones(void)
  690. {
  691. return Lods[0].Model->Get_Num_Bones();
  692. }
  693. /***********************************************************************************************
  694. * DistLODClass::Get_Bone_Name -- returns the name of the specified bone *
  695. * *
  696. * INPUT: *
  697. * *
  698. * OUTPUT: *
  699. * *
  700. * WARNINGS: *
  701. * *
  702. * HISTORY: *
  703. * 3/3/99 GTH : Created. *
  704. *=============================================================================================*/
  705. const char * DistLODClass::Get_Bone_Name(int bone_index)
  706. {
  707. return Lods[0].Model->Get_Bone_Name(bone_index);
  708. }
  709. /***********************************************************************************************
  710. * DistLODClass::Get_Bone_Index -- returns the index of the given bone (if found) *
  711. * *
  712. * INPUT: *
  713. * *
  714. * OUTPUT: *
  715. * *
  716. * WARNINGS: *
  717. * *
  718. * HISTORY: *
  719. * 3/3/99 GTH : Created. *
  720. *=============================================================================================*/
  721. int DistLODClass::Get_Bone_Index(const char * bonename)
  722. {
  723. // Highest LOD is used since lowest may be a Null3DObjClass.
  724. return Lods[0].Model->Get_Bone_Index(bonename);
  725. }
  726. /***********************************************************************************************
  727. * DistLODClass::Get_Bone_Transform -- returns the transform of the given bone *
  728. * *
  729. * INPUT: *
  730. * *
  731. * OUTPUT: *
  732. * *
  733. * WARNINGS: *
  734. * *
  735. * HISTORY: *
  736. * 3/3/99 GTH : Created. *
  737. *=============================================================================================*/
  738. const Matrix3D & DistLODClass::Get_Bone_Transform(const char * bonename)
  739. {
  740. // Highest LOD is used since lowest may be a Null3DObjClass.
  741. return Lods[0].Model->Get_Bone_Transform(bonename);
  742. }
  743. /***********************************************************************************************
  744. * DistLODClass::Get_Bone_Transform -- returns the transform of the given bone *
  745. * *
  746. * INPUT: *
  747. * *
  748. * OUTPUT: *
  749. * *
  750. * WARNINGS: *
  751. * *
  752. * HISTORY: *
  753. * 3/3/99 GTH : Created. *
  754. *=============================================================================================*/
  755. const Matrix3D & DistLODClass::Get_Bone_Transform(int boneindex)
  756. {
  757. // Highest LOD is used since lowest may be a Null3DObjClass.
  758. return Lods[0].Model->Get_Bone_Transform(boneindex);
  759. }
  760. /***********************************************************************************************
  761. * DistLODClass::Capture_Bone -- take control of a bone *
  762. * *
  763. * INPUT: *
  764. * *
  765. * OUTPUT: *
  766. * *
  767. * WARNINGS: *
  768. * *
  769. * HISTORY: *
  770. * 3/3/99 GTH : Created. *
  771. *=============================================================================================*/
  772. void DistLODClass::Capture_Bone(int bindex)
  773. {
  774. for (int i=0; i<LodCount; i++) {
  775. assert(Lods[i].Model != NULL);
  776. Lods[i].Model->Capture_Bone(bindex);
  777. }
  778. }
  779. /***********************************************************************************************
  780. * DistLODClass::Release_Bone -- release control of a bone *
  781. * *
  782. * INPUT: *
  783. * *
  784. * OUTPUT: *
  785. * *
  786. * WARNINGS: *
  787. * *
  788. * HISTORY: *
  789. * 3/3/99 GTH : Created. *
  790. *=============================================================================================*/
  791. void DistLODClass::Release_Bone(int bindex)
  792. {
  793. for (int i=0; i<LodCount; i++) {
  794. assert(Lods[i].Model != NULL);
  795. Lods[i].Model->Release_Bone(bindex);
  796. }
  797. }
  798. /***********************************************************************************************
  799. * DistLODClass::Is_Bone_Captured -- check whether the given bone is captured *
  800. * *
  801. * INPUT: *
  802. * *
  803. * OUTPUT: *
  804. * *
  805. * WARNINGS: *
  806. * *
  807. * HISTORY: *
  808. * 3/3/99 GTH : Created. *
  809. *=============================================================================================*/
  810. bool DistLODClass::Is_Bone_Captured(int bindex) const
  811. {
  812. // Highest LOD is used since lowest may be a Null3DObjClass.
  813. return Lods[0].Model->Is_Bone_Captured(bindex);
  814. }
  815. /***********************************************************************************************
  816. * DistLODClass::Control_Bone -- set the transform for a captured bone *
  817. * *
  818. * INPUT: *
  819. * *
  820. * OUTPUT: *
  821. * *
  822. * WARNINGS: *
  823. * *
  824. * HISTORY: *
  825. * 3/3/99 GTH : Created. *
  826. *=============================================================================================*/
  827. void DistLODClass::Control_Bone(int bindex,const Matrix3D & tm,bool world_space_translation)
  828. {
  829. for (int i=0; i<LodCount; i++) {
  830. assert(Lods[i].Model != NULL);
  831. Lods[i].Model->Control_Bone(bindex,tm,world_space_translation);
  832. }
  833. }
  834. /***********************************************************************************************
  835. * DistLODClass::Cast_Ray -- cast a ray against this model *
  836. * *
  837. * casts the ray against the top-level LOD *
  838. * *
  839. * INPUT: *
  840. * *
  841. * OUTPUT: *
  842. * *
  843. * WARNINGS: *
  844. * *
  845. * HISTORY: *
  846. * 3/3/99 GTH : Created. *
  847. *=============================================================================================*/
  848. bool DistLODClass::Cast_Ray(RayCollisionTestClass & raytest)
  849. {
  850. if (raytest.CollisionType & Get_Collision_Type()) {
  851. return Lods[HIGHEST_LOD].Model->Cast_Ray(raytest);
  852. } else {
  853. return false;
  854. }
  855. }
  856. /***********************************************************************************************
  857. * DistLODClass::Cast_AABox -- perform an AABox cast against this model *
  858. * *
  859. * tests against the top-level LOD *
  860. * *
  861. * INPUT: *
  862. * *
  863. * OUTPUT: *
  864. * *
  865. * WARNINGS: *
  866. * *
  867. * HISTORY: *
  868. * 3/3/99 GTH : Created. *
  869. *=============================================================================================*/
  870. bool DistLODClass::Cast_AABox(AABoxCollisionTestClass & boxtest)
  871. {
  872. if (boxtest.CollisionType & Get_Collision_Type()) {
  873. return Lods[HIGHEST_LOD].Model->Cast_AABox(boxtest);
  874. } else {
  875. return false;
  876. }
  877. }
  878. /***********************************************************************************************
  879. * DistLODClass::Cast_OBBox -- perform an OBBox cast against this model *
  880. * *
  881. * INPUT: *
  882. * *
  883. * OUTPUT: *
  884. * *
  885. * WARNINGS: *
  886. * *
  887. * HISTORY: *
  888. * 3/1/99 GTH : Created. *
  889. *=============================================================================================*/
  890. bool DistLODClass::Cast_OBBox(OBBoxCollisionTestClass & boxtest)
  891. {
  892. if (boxtest.CollisionType & Get_Collision_Type()) {
  893. return Lods[HIGHEST_LOD].Model->Cast_OBBox(boxtest);
  894. } else {
  895. return false;
  896. }
  897. }
  898. /***********************************************************************************************
  899. * DistLODCLass::Get_Num_Snap_Points -- returns number of snap points in this model *
  900. * *
  901. * INPUT: *
  902. * *
  903. * OUTPUT: *
  904. * *
  905. * WARNINGS: *
  906. * *
  907. * HISTORY: *
  908. * 3/1/99 GTH : Created. *
  909. *=============================================================================================*/
  910. int DistLODClass::Get_Num_Snap_Points(void)
  911. {
  912. return Lods[0].Model->Get_Num_Snap_Points();
  913. }
  914. /***********************************************************************************************
  915. * DistLODClass::Get_Snap_Point -- returns the i'th snap point *
  916. * *
  917. * INPUT: *
  918. * *
  919. * OUTPUT: *
  920. * *
  921. * WARNINGS: *
  922. * *
  923. * HISTORY: *
  924. * 3/1/99 GTH : Created. *
  925. *=============================================================================================*/
  926. void DistLODClass::Get_Snap_Point(int index,Vector3 * set)
  927. {
  928. Lods[0].Model->Get_Snap_Point(index,set);
  929. }
  930. /***********************************************************************************************
  931. * DistLODCLass::Scale -- scale this model; passes on to each LOD *
  932. * *
  933. * INPUT: *
  934. * *
  935. * OUTPUT: *
  936. * *
  937. * WARNINGS: *
  938. * *
  939. * HISTORY: *
  940. * 3/1/99 GTH : Created. *
  941. *=============================================================================================*/
  942. void DistLODClass::Scale(float scale)
  943. {
  944. for (int i=0; i<LodCount; i++) {
  945. assert(Lods[CurLod].Model != NULL);
  946. Lods[CurLod].Model->Scale(scale);
  947. }
  948. }
  949. /***********************************************************************************************
  950. * DistLODClass::Scale -- scale this model; passes on to each LOD *
  951. * *
  952. * INPUT: *
  953. * *
  954. * OUTPUT: *
  955. * *
  956. * WARNINGS: *
  957. * *
  958. * HISTORY: *
  959. * 3/1/99 GTH : Created. *
  960. *=============================================================================================*/
  961. void DistLODClass::Scale(float scalex, float scaley, float scalez)
  962. {
  963. for (int i=0; i<LodCount; i++) {
  964. assert(Lods[i].Model != NULL);
  965. Lods[i].Model->Scale(scalex,scaley,scalez);
  966. }
  967. }
  968. /***********************************************************************************************
  969. * DistLODClass::Update_LOD -- adjusts the current LOD based on the distance *
  970. * *
  971. * INPUT: *
  972. * *
  973. * OUTPUT: *
  974. * *
  975. * WARNINGS: *
  976. * *
  977. * HISTORY: *
  978. * 3/1/99 GTH : Created. *
  979. *=============================================================================================*/
  980. void DistLODClass::Update_Lod(const CameraClass & camera)
  981. {
  982. // evaluate the distance from the camera and select an LOD based on it.
  983. float dist = (
  984. camera.Get_Position() -
  985. Lods[CurLod].Model->Get_Bounding_Sphere().Center
  986. ).Quick_Length();
  987. if (dist < Lods[CurLod].ResUpDist) {
  988. Increment_Lod();
  989. } else if (dist > Lods[CurLod].ResDownDist) {
  990. Decrement_Lod();
  991. }
  992. }
  993. /***********************************************************************************************
  994. * DistLODClass::Increment_Lod -- moves to a higher detail LOD *
  995. * *
  996. * INPUT: *
  997. * *
  998. * OUTPUT: *
  999. * *
  1000. * WARNINGS: *
  1001. * *
  1002. * HISTORY: *
  1003. * 3/1/99 GTH : Created. *
  1004. *=============================================================================================*/
  1005. void DistLODClass::Increment_Lod(void)
  1006. {
  1007. // TODO: change the order in which models are stored
  1008. if (CurLod > 0) {
  1009. if (Is_In_Scene()) {
  1010. Lods[CurLod].Model->Notify_Removed(Scene);
  1011. }
  1012. CurLod--;
  1013. if (Is_In_Scene()) {
  1014. Lods[CurLod].Model->Notify_Added(Scene);
  1015. }
  1016. }
  1017. }
  1018. /***********************************************************************************************
  1019. * DistLODClass::Decrement_Lod -- moves to a lower detail LOD *
  1020. * *
  1021. * INPUT: *
  1022. * *
  1023. * OUTPUT: *
  1024. * *
  1025. * WARNINGS: *
  1026. * *
  1027. * HISTORY: *
  1028. * 3/1/99 GTH : Created. *
  1029. *=============================================================================================*/
  1030. void DistLODClass::Decrement_Lod(void)
  1031. {
  1032. if (CurLod < LodCount - 1) {
  1033. if (Is_In_Scene()) {
  1034. Lods[CurLod].Model->Notify_Removed(Scene);
  1035. }
  1036. CurLod++;
  1037. if (Is_In_Scene()) {
  1038. Lods[CurLod].Model->Notify_Added(Scene);
  1039. }
  1040. }
  1041. }