msl.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. //-------------------------------------------------------------------------------
  2. //
  3. // Multiple TG Shape Layer
  4. //
  5. //---------------------------------------------------------------------------//
  6. // Copyright (C) Microsoft Corporation. All rights reserved. //
  7. //===========================================================================//
  8. // Replace MLR for a myriad number of reasons.
  9. //
  10. // Started 4/16/99
  11. //
  12. // FFS
  13. //
  14. //-------------------------------------------------------------------------------
  15. #ifndef MSL_H
  16. #define MSL_H
  17. //-------------------------------------------------------------------------------
  18. // Include Files
  19. #ifndef TGL_H
  20. #include "tgl.h"
  21. #endif
  22. #ifndef TXMMGR_H
  23. #include "txmmgr.h"
  24. #endif
  25. // ARM
  26. namespace Microsoft
  27. {
  28. namespace Xna
  29. {
  30. namespace Arm
  31. {
  32. struct IProviderEngine;
  33. }
  34. }
  35. }
  36. //-------------------------------------------------------------------------------
  37. // Structs used by layer.
  38. //
  39. class TG_MultiShape;
  40. class TG_AnimateShape;
  41. //-------------------------------------------------------------------------------
  42. // The meat and Potatoes part.
  43. // TG_TypeMultiShape
  44. class TG_TypeMultiShape
  45. {
  46. friend TG_MultiShape;
  47. friend TG_TypeShape;
  48. friend TG_Shape;
  49. friend TG_AnimateShape;
  50. //---------------------------------------------------------
  51. // This class runs a multi-shape appearance. Anything
  52. // with an ASE file of more then one shape should use this
  53. // Class. Uses everything from TG_Shape except parse.
  54. // That is local to here to get all of the pieces. Each
  55. // Shape is transformed, rendered etc. in TG_Shape.
  56. // This will store animation information and use it, too!
  57. //-------------
  58. //Data Members
  59. protected:
  60. long numTG_TypeShapes; //Number of TG_Shapes
  61. long numTextures; //Total Textures for all shapes.
  62. TG_TypeNodePtr *listOfTypeShapes; //Memory holding all TG_TypeNodes and TypeShapes
  63. TG_TexturePtr listOfTextures; //List of texture Structures for all shapes.
  64. #ifdef _DEBUG
  65. char *shapeName; //FileName of shape
  66. #endif
  67. public:
  68. Stuff::Vector3D maxBox; //Bounding Box Max Coords
  69. Stuff::Vector3D minBox; //Bounding Box Min Coords
  70. float extentRadius; //Bounding Sphere Coords
  71. //-----------------
  72. //Member Functions
  73. protected:
  74. public:
  75. void * operator new (size_t mySize);
  76. void operator delete (void * us);
  77. void init (void)
  78. {
  79. numTG_TypeShapes = 0;
  80. listOfTypeShapes = NULL;
  81. numTextures = 0;
  82. listOfTextures = NULL;
  83. #ifdef _DEBUG
  84. shapeName = NULL;
  85. #endif
  86. maxBox.x =
  87. maxBox.y =
  88. maxBox.z = -100000.0f;
  89. minBox.x =
  90. minBox.y =
  91. minBox.z = 100000.0f;
  92. extentRadius = 0.0f;
  93. }
  94. TG_TypeMultiShape (void)
  95. {
  96. init();
  97. }
  98. void destroy (void);
  99. ~TG_TypeMultiShape (void)
  100. {
  101. destroy();
  102. }
  103. //Function returns 0 if OK. -1 if file not found or file not ASE Format.
  104. //Function runs through each piece of ASE file and creates a separate
  105. //TG_Shape for each one. First pass is count number of GEOMOBJECTS.
  106. //Second pass is load each one.
  107. long LoadTGMultiShapeFromASE (char *fileName, bool forceMakeBinary = false, Microsoft::Xna::Arm::IProviderEngine * armProvider = NULL);
  108. //Function returns 0 if OK. -1 if textureName is longer then nameLength-1.
  109. //This function digs the texture name(s) out of the ASE file so that the
  110. //User can load and manage them anyway they want to.
  111. long GetTextureName (DWORD textureNum, char *textureName, long nameLength);
  112. //Function returns 0 if OK. -1 if textureNum is out of range of numTextures.
  113. //This function takes the gosTextureHandle passed in and assigns it to the
  114. //textureNum entry of the listOfTextures;
  115. long SetTextureHandle (DWORD textureNum, DWORD gosTextureHandle);
  116. //Function returns 0 if OK. -1 if textureNum is out of range of numTextures.
  117. //This function takes the gosTextureHandle passed in and assigns it to the
  118. //textureNum entry of the listOfTextures;
  119. long SetTextureAlpha (DWORD textureNum, bool alphaFlag);
  120. DWORD GetTextureHandle (DWORD textureNum)
  121. {
  122. if (textureNum < numTextures)
  123. return listOfTextures[textureNum].mcTextureNodeIndex;
  124. return 0xffffffff;
  125. }
  126. long GetNumShapes (void)
  127. {
  128. return numTG_TypeShapes;
  129. }
  130. long GetNumTextures (void)
  131. {
  132. return numTextures;
  133. }
  134. char *GetNodeId (long shapeNum)
  135. {
  136. if ((shapeNum >= 0) && (shapeNum < numTG_TypeShapes))
  137. return (listOfTypeShapes[shapeNum]->getNodeId());
  138. return NULL;
  139. }
  140. Stuff::Point3D GetNodeCenter (long shapeNum)
  141. {
  142. Stuff::Point3D result;
  143. result.x = result.y = result.z = 0.0f;
  144. if ((shapeNum >= 0) && (shapeNum < numTG_TypeShapes))
  145. result = listOfTypeShapes[shapeNum]->GetNodeCenter();
  146. return result;
  147. }
  148. Stuff::Point3D GetNodeCenter (char * nodeId)
  149. {
  150. Stuff::Point3D result;
  151. result.x = result.y = result.z = 0.0f;
  152. for (long i=0;i<numTG_TypeShapes;i++)
  153. {
  154. if (stricmp(listOfTypeShapes[i]->getNodeId(),nodeId) == 0)
  155. result = listOfTypeShapes[i]->GetNodeCenter();
  156. }
  157. return result;
  158. }
  159. //This function creates an instance of the TG_MultiShape from the Type
  160. TG_MultiShape *CreateFrom (void);
  161. void SetAlphaTest (bool flag)
  162. {
  163. for (long i=0;i<numTG_TypeShapes;i++)
  164. listOfTypeShapes[i]->SetAlphaTest(flag);
  165. }
  166. void SetFilter (bool flag)
  167. {
  168. for (long i=0;i<numTG_TypeShapes;i++)
  169. listOfTypeShapes[i]->SetFilter(flag);
  170. }
  171. void SetLightRGBs (DWORD hPink, DWORD hGreen, DWORD hYellow)
  172. {
  173. for (long i=0;i<numTG_TypeShapes;i++)
  174. listOfTypeShapes[i]->SetLightRGBs(hPink,hGreen,hYellow);
  175. }
  176. long LoadBinaryCopy (char *fileName);
  177. void SaveBinaryCopy (char *fileName);
  178. };
  179. typedef TG_TypeMultiShape* TG_TypeMultiShapePtr;
  180. //-------------------------------------------------------------------------------
  181. // The meat and Potatoes part.
  182. // TG_MultiShape
  183. class TG_MultiShape
  184. {
  185. //---------------------------------------------------------
  186. // This class runs a multi-shape appearance. Anything
  187. // with an ASE file of more then one shape should use this
  188. // Class. Uses everything from TG_Shape except parse.
  189. // That is local to here to get all of the pieces. Each
  190. // Shape is transformed, rendered etc. in TG_Shape.
  191. // This will store animation information and use it, too!
  192. friend TG_TypeMultiShape;
  193. friend TG_Shape;
  194. friend TG_TypeShape;
  195. friend TG_AnimateShape;
  196. //-------------
  197. //Data Members
  198. protected:
  199. TG_TypeMultiShapePtr myMultiType; //Pointer to the type
  200. long numTG_Shapes; //Number of TG_Shapes
  201. TG_ShapeRecPtr listOfShapes; //Memory holding all TG_ShapeRecs
  202. float frameNum; //Frame number of animation
  203. bool d_useShadows;
  204. bool isHudElement;
  205. BYTE alphaValue; //To fade shapes in and out
  206. bool isClamped; //So I can force a shape to clamp its textures
  207. //-----------------
  208. //Member Functions
  209. protected:
  210. public:
  211. void * operator new (size_t mySize);
  212. void operator delete (void * us);
  213. void init (void)
  214. {
  215. myMultiType = NULL;
  216. numTG_Shapes = 0;
  217. listOfShapes = NULL;
  218. frameNum = 0.0f;
  219. d_useShadows = true;
  220. isHudElement = false;
  221. alphaValue = 0xff;
  222. isClamped = false;
  223. }
  224. TG_MultiShape (void)
  225. {
  226. init();
  227. }
  228. void destroy (void);
  229. ~TG_MultiShape (void)
  230. {
  231. destroy();
  232. }
  233. //This function sets the list of lights used by the TransformShape function
  234. //to light the shape.
  235. //Function returns 0 if lightList entries are all OK. -1 otherwise.
  236. //
  237. long SetLightList (TG_LightPtr *lightList, DWORD nLights);
  238. //This function sets the fog values for the shape. Straight fog right now.
  239. void SetFogRGB (DWORD fRGB);
  240. //This function does the actual transform math, clip checks and lighting math.
  241. //The matrices passed in are the translation/rotation matrix for the shape and
  242. //Its inverse. Also will animate.
  243. //Function returns -1 if all vertex screen positions are off screen.
  244. //Function returns 0 if any one vertex screen position is off screen.
  245. //Function returns 1 is all vertex screen positions are on screen.
  246. // NOTE: THIS IS NOT A RIGOROUS CLIP!!!!!!!!!
  247. long TransformMultiShape (Stuff::Point3D *pos, Stuff::UnitQuaternion *rot);
  248. //This function rotates the heirarchy from this node down. Used for torso twists, arms, etc.
  249. // SHould only be called once this way. This way is DAMNED SLOW!!! STRICMP! IT returns the node num
  250. // Call that from then on!
  251. long SetNodeRotation (char *nodeName, Stuff::UnitQuaternion *rot);
  252. void SetNodeRotation (long nodeNum, Stuff::UnitQuaternion *rot)
  253. {
  254. if ((nodeNum >= 0) && (nodeNum < numTG_Shapes))
  255. listOfShapes[nodeNum].baseRotation = *rot;
  256. }
  257. //This function takes the current listOfVisibleFaces and draws them using
  258. //gos_DrawTriangle.
  259. void Render (bool refreshTextures = false, float forceZ = -1.0f);
  260. //This function takes the current listOfShadowTriangles and draws them using
  261. //gos_DrawTriangle.
  262. void RenderShadows (bool refreshTextures = false);
  263. long GetNumShapes (void)
  264. {
  265. return numTG_Shapes;
  266. }
  267. void ScaleShape (float scaleFactor)
  268. {
  269. if (scaleFactor >= 0.0f)
  270. {
  271. for (long i=0;i<numTG_Shapes;i++)
  272. listOfShapes[i].node->shapeScalar = scaleFactor;
  273. }
  274. }
  275. long GetNumVerticesInShape (long i)
  276. {
  277. if ((i >= 0) && (i < numTG_Shapes))
  278. {
  279. return myMultiType->listOfTypeShapes[i]->GetNumTypeVertices();
  280. }
  281. return 0;
  282. }
  283. Stuff::Vector3D GetShapeVertexInWorld(long shapeNum, long vertexNum, float rotation);
  284. Stuff::Vector3D GetShapeVertexInEditor(long shapeNum, long vertexNum, float rotation);
  285. float GetFrameNum (void)
  286. {
  287. return frameNum;
  288. }
  289. void SetFrameNum (float frame)
  290. {
  291. frameNum = frame;
  292. }
  293. void SetIsClamped (bool value)
  294. {
  295. isClamped = value;
  296. }
  297. //Function returns 0 if OK. -1 if textureName is longer then nameLength-1.
  298. //This function digs the texture name(s) out of the ASE file so that the
  299. //User can load and manage them anyway they want to.
  300. long GetTextureName (DWORD textureNum, char *textureName, long nameLength)
  301. {
  302. return myMultiType->GetTextureName(textureNum,textureName,nameLength);
  303. }
  304. long GetNumTextures (void)
  305. {
  306. return myMultiType->GetNumTextures();
  307. }
  308. //Function returns 0 if OK. -1 if textureNum is out of range of numTextures.
  309. //This function takes the gosTextureHandle passed in and assigns it to the
  310. //textureNum entry of the listOfTextures;
  311. long SetTextureHandle (DWORD textureNum, DWORD gosTextureHandle)
  312. {
  313. return myMultiType->SetTextureHandle(textureNum,gosTextureHandle);
  314. }
  315. DWORD GetTextureHandle (DWORD textureNum)
  316. {
  317. return myMultiType->GetTextureHandle(textureNum);
  318. }
  319. float GetExtentRadius (void)
  320. {
  321. return myMultiType->extentRadius;
  322. }
  323. Stuff::Vector3D GetMaxBox (void)
  324. {
  325. return myMultiType->maxBox;
  326. }
  327. Stuff::Vector3D GetMinBox (void)
  328. {
  329. return myMultiType->minBox;
  330. }
  331. //Function returns 0 if OK. -1 if textureNum is out of range of numTextures.
  332. //This function takes the gosTextureHandle passed in and assigns it to the
  333. //textureNum entry of the listOfTextures;
  334. long SetTextureAlpha (DWORD textureNum, bool alphaFlag)
  335. {
  336. return myMultiType->SetTextureAlpha(textureNum,alphaFlag);
  337. }
  338. Stuff::Point3D GetRootNodeCenter (void)
  339. {
  340. Stuff::Point3D result;
  341. result.x = result.y = result.z = 0.0f;
  342. for (long i=0;i<numTG_Shapes;i++)
  343. {
  344. if (listOfShapes[i].parentNode == NULL)
  345. {
  346. result = listOfShapes[i].node->myType->GetNodeCenter();
  347. }
  348. }
  349. return result;
  350. }
  351. Stuff::Point3D GetRootRelativeNodeCenter (void)
  352. {
  353. Stuff::Point3D result;
  354. result.x = result.y = result.z = 0.0f;
  355. for (long i=0;i<numTG_Shapes;i++)
  356. {
  357. if (listOfShapes[i].parentNode == NULL)
  358. {
  359. result = listOfShapes[i].node->myType->GetRelativeNodeCenter();
  360. }
  361. }
  362. return result;
  363. }
  364. void SetCurrentAnimation (long shapeNum, TG_AnimationPtr anim)
  365. {
  366. if ((shapeNum >= 0) && (shapeNum < numTG_Shapes))
  367. listOfShapes[shapeNum].currentAnimation = anim;
  368. }
  369. //This function clears all of the animation pointers.
  370. //As such, the shape will stop animating and return to base pose.
  371. void ClearAnimation (void)
  372. {
  373. for (long i=0;i<numTG_Shapes;i++)
  374. listOfShapes[i].currentAnimation = NULL;
  375. }
  376. void SetARGBHighLight (DWORD argb)
  377. {
  378. for (long i=0;i<numTG_Shapes;i++)
  379. listOfShapes[i].node->SetARGBHighLight(argb);
  380. }
  381. void SetLightsOut (bool lightFlag)
  382. {
  383. for (long i=0;i<numTG_Shapes;i++)
  384. listOfShapes[i].node->SetLightsOut(lightFlag);
  385. }
  386. Stuff::Vector3D GetTransformedNodePosition (Stuff::Point3D *pos, Stuff::UnitQuaternion *rot, char *nodeId);
  387. Stuff::Vector3D GetTransformedNodePosition (Stuff::Point3D *pos, Stuff::UnitQuaternion *rot, long nodeId);
  388. TG_TypeMultiShapePtr GetMultiType (void)
  389. {
  390. return myMultiType;
  391. }
  392. // This function takes the shape named nodeName and all of its children, detaches them
  393. // from the current heirarchy and stuffs them into a new MultiShape which it passes back
  394. // Uses are endless but for now limited to blowing the arms off of the mechs!
  395. TG_MultiShape* Detach (char *nodeName);
  396. // This function takes the shape named nodeName and all of its children and stops processing
  397. // them forever. Since we can never re-attach a mech arm in the field, this is OK!
  398. void StopUsing (char *nodeName);
  399. // Tells me if the passed in nodeName is a child of the parentName.
  400. bool isChildOf (char *nodeName, char* parentName);
  401. char *GetNodeId (long shapeNum)
  402. {
  403. if ((shapeNum >= 0) && (shapeNum < numTG_Shapes))
  404. return (listOfShapes[shapeNum].node->getNodeName());
  405. return NULL;
  406. }
  407. long GetNodeNameId (char * nodeId)
  408. {
  409. for (long i=0;i<numTG_Shapes;i++)
  410. {
  411. //-----------------------------------------------------------------
  412. // Scan through the list of shapes and dig out the number needed.
  413. // DO NOT UPDATE THE HEIRARCHY!!!!
  414. // This thing may not have updated itself this turn yet!!!
  415. if (stricmp(listOfShapes[i].node->myType->getNodeId(),nodeId) == 0)
  416. return i;
  417. }
  418. return -1;
  419. }
  420. void SetIsHudElement (void)
  421. {
  422. isHudElement = true;
  423. }
  424. void SetAlphaValue (BYTE aVal)
  425. {
  426. alphaValue = aVal;
  427. }
  428. BYTE GetAlphaValue (void)
  429. {
  430. return alphaValue;
  431. }
  432. bool PerPolySelect (long mouseX, long mouseY)
  433. {
  434. float mx = mouseX;
  435. float my = mouseY;
  436. for (long i=0;i<numTG_Shapes;i++)
  437. {
  438. if (listOfShapes[i].node->numVisibleFaces && listOfShapes[i].node->PerPolySelect(mx,my))
  439. return true;
  440. }
  441. return false;
  442. }
  443. void SetRecalcShadows (bool flag)
  444. {
  445. for (long i=0;i<numTG_Shapes;i++)
  446. {
  447. listOfShapes[i].node->SetRecalcShadows(flag);
  448. }
  449. }
  450. void SetUseShadow (bool flag)
  451. {
  452. d_useShadows = flag;
  453. }
  454. };
  455. typedef TG_MultiShape* TG_MultiShapePtr;
  456. //-------------------------------------------------------------------------------
  457. // The meat and Potatoes part of the animation system
  458. // TG_AnimShape
  459. class TG_AnimateShape
  460. {
  461. friend TG_TypeMultiShape;
  462. friend TG_MultiShape;
  463. //--------------------------------------------------------------------
  464. //This class stores a single gesture worth of animation data.
  465. //Works by loading the animation data for each NODE in the multiShape
  466. //From an ASE file. When we change an animation gesture, this class
  467. //will shove the correct pointers to the data down to the TG_ShapeRecs.
  468. //Other then data storage, parsing, and the pointer sets, does zipp!
  469. protected:
  470. TG_AnimationPtr listOfAnimation;
  471. long count;
  472. long actualCount;
  473. bool shapeIdsSet;
  474. public:
  475. void * operator new (size_t mySize);
  476. void operator delete (void * us);
  477. void init (void)
  478. {
  479. listOfAnimation = NULL;
  480. count = actualCount = 0;
  481. shapeIdsSet = false;
  482. }
  483. TG_AnimateShape (void)
  484. {
  485. init();
  486. }
  487. ~TG_AnimateShape (void)
  488. {
  489. destroy();
  490. }
  491. long LoadBinaryCopy (char *fileName);
  492. void SaveBinaryCopy (char *fileName);
  493. //This function frees all of the RAM allocated by this class and resets vars to initial state.
  494. void destroy (void);
  495. //This function loads the animation data contained in the file passed in.
  496. //It sets up a pointer to the multi-shape so that animation data for each
  497. //Node in the Multi-Shape can be loaded.
  498. //It mallocs memory.
  499. long LoadTGMultiShapeAnimationFromASE (char *filename, TG_TypeMultiShapePtr shape, bool skipIfBinary = false, bool forceMakeBinary = false);
  500. //This function copies the pointers to the animation data in this class to the
  501. //TG_MultiShape being drawn. Nothing else happens.
  502. void SetAnimationState (TG_MultiShapePtr mShape);
  503. float GetFrameRate (void)
  504. {
  505. if (listOfAnimation)
  506. return listOfAnimation[0].frameRate;
  507. return 30.0f;
  508. }
  509. void SetFrameRate (float nFrameRate)
  510. {
  511. if (listOfAnimation)
  512. listOfAnimation[0].frameRate = nFrameRate;
  513. }
  514. void ReverseFrameRate (void)
  515. {
  516. if (listOfAnimation)
  517. listOfAnimation[0].frameRate = -listOfAnimation[0].frameRate;
  518. }
  519. long GetNumFrames (void)
  520. {
  521. if (listOfAnimation)
  522. return listOfAnimation[0].numFrames;
  523. return 0;
  524. }
  525. void resetShapeIds (void)
  526. {
  527. shapeIdsSet = false;
  528. }
  529. };
  530. typedef TG_AnimateShape *TG_AnimateShapePtr;
  531. //-------------------------------------------------------------------------------
  532. #endif