DeclAF.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __DECLAF_H__
  21. #define __DECLAF_H__
  22. /*
  23. ===============================================================================
  24. Articulated Figure
  25. ===============================================================================
  26. */
  27. class idDeclAF;
  28. typedef enum {
  29. DECLAF_CONSTRAINT_INVALID,
  30. DECLAF_CONSTRAINT_FIXED,
  31. DECLAF_CONSTRAINT_BALLANDSOCKETJOINT,
  32. DECLAF_CONSTRAINT_UNIVERSALJOINT,
  33. DECLAF_CONSTRAINT_HINGE,
  34. DECLAF_CONSTRAINT_SLIDER,
  35. DECLAF_CONSTRAINT_SPRING
  36. } declAFConstraintType_t;
  37. typedef enum {
  38. DECLAF_JOINTMOD_AXIS,
  39. DECLAF_JOINTMOD_ORIGIN,
  40. DECLAF_JOINTMOD_BOTH
  41. } declAFJointMod_t;
  42. typedef bool (*getJointTransform_t)( void *model, const idJointMat *frame, const char *jointName, idVec3 &origin, idMat3 &axis );
  43. class idAFVector {
  44. public:
  45. enum {
  46. VEC_COORDS = 0,
  47. VEC_JOINT,
  48. VEC_BONECENTER,
  49. VEC_BONEDIR
  50. } type;
  51. idStr joint1;
  52. idStr joint2;
  53. public:
  54. idAFVector( void );
  55. bool Parse( idLexer &src );
  56. bool Finish( const char *fileName, const getJointTransform_t GetJointTransform, const idJointMat *frame, void *model ) const;
  57. bool Write( idFile *f ) const;
  58. const char * ToString( idStr &str, const int precision = 8 );
  59. const idVec3 & ToVec3( void ) const { return vec; }
  60. idVec3 & ToVec3( void ) { return vec; }
  61. private:
  62. mutable idVec3 vec;
  63. bool negate;
  64. };
  65. class idDeclAF_Body {
  66. public:
  67. idStr name;
  68. idStr jointName;
  69. declAFJointMod_t jointMod;
  70. int modelType;
  71. idAFVector v1, v2;
  72. int numSides;
  73. float width;
  74. float density;
  75. idAFVector origin;
  76. idAngles angles;
  77. int contents;
  78. int clipMask;
  79. bool selfCollision;
  80. idMat3 inertiaScale;
  81. float linearFriction;
  82. float angularFriction;
  83. float contactFriction;
  84. idStr containedJoints;
  85. idAFVector frictionDirection;
  86. idAFVector contactMotorDirection;
  87. public:
  88. void SetDefault( const idDeclAF *file );
  89. };
  90. class idDeclAF_Constraint {
  91. public:
  92. idStr name;
  93. idStr body1;
  94. idStr body2;
  95. declAFConstraintType_t type;
  96. float friction;
  97. float stretch;
  98. float compress;
  99. float damping;
  100. float restLength;
  101. float minLength;
  102. float maxLength;
  103. idAFVector anchor;
  104. idAFVector anchor2;
  105. idAFVector shaft[2];
  106. idAFVector axis;
  107. enum {
  108. LIMIT_NONE = -1,
  109. LIMIT_CONE,
  110. LIMIT_PYRAMID
  111. } limit;
  112. idAFVector limitAxis;
  113. float limitAngles[3];
  114. public:
  115. void SetDefault( const idDeclAF *file );
  116. };
  117. class idDeclAF : public idDecl {
  118. friend class idAFFileManager;
  119. public:
  120. idDeclAF( void );
  121. virtual ~idDeclAF( void );
  122. virtual size_t Size( void ) const;
  123. virtual const char * DefaultDefinition( void ) const;
  124. virtual bool Parse( const char *text, const int textLength );
  125. virtual void FreeData( void );
  126. virtual void Finish( const getJointTransform_t GetJointTransform, const idJointMat *frame, void *model ) const;
  127. bool Save( void );
  128. void NewBody( const char *name );
  129. void RenameBody( const char *oldName, const char *newName );
  130. void DeleteBody( const char *name );
  131. void NewConstraint( const char *name );
  132. void RenameConstraint( const char *oldName, const char *newName );
  133. void DeleteConstraint( const char *name );
  134. static int ContentsFromString( const char *str );
  135. static const char * ContentsToString( const int contents, idStr &str );
  136. static declAFJointMod_t JointModFromString( const char *str );
  137. static const char * JointModToString( declAFJointMod_t jointMod );
  138. public:
  139. bool modified;
  140. idStr model;
  141. idStr skin;
  142. float defaultLinearFriction;
  143. float defaultAngularFriction;
  144. float defaultContactFriction;
  145. float defaultConstraintFriction;
  146. float totalMass;
  147. idVec2 suspendVelocity;
  148. idVec2 suspendAcceleration;
  149. float noMoveTime;
  150. float noMoveTranslation;
  151. float noMoveRotation;
  152. float minMoveTime;
  153. float maxMoveTime;
  154. int contents;
  155. int clipMask;
  156. bool selfCollision;
  157. idList<idDeclAF_Body *> bodies;
  158. idList<idDeclAF_Constraint *> constraints;
  159. private:
  160. bool ParseContents( idLexer &src, int &c ) const;
  161. bool ParseBody( idLexer &src );
  162. bool ParseFixed( idLexer &src );
  163. bool ParseBallAndSocketJoint( idLexer &src );
  164. bool ParseUniversalJoint( idLexer &src );
  165. bool ParseHinge( idLexer &src );
  166. bool ParseSlider( idLexer &src );
  167. bool ParseSpring( idLexer &src );
  168. bool ParseSettings( idLexer &src );
  169. bool WriteBody( idFile *f, const idDeclAF_Body &body ) const;
  170. bool WriteFixed( idFile *f, const idDeclAF_Constraint &c ) const;
  171. bool WriteBallAndSocketJoint( idFile *f, const idDeclAF_Constraint &c ) const;
  172. bool WriteUniversalJoint( idFile *f, const idDeclAF_Constraint &c ) const;
  173. bool WriteHinge( idFile *f, const idDeclAF_Constraint &c ) const;
  174. bool WriteSlider( idFile *f, const idDeclAF_Constraint &c ) const;
  175. bool WriteSpring( idFile *f, const idDeclAF_Constraint &c ) const;
  176. bool WriteConstraint( idFile *f, const idDeclAF_Constraint &c ) const;
  177. bool WriteSettings( idFile *f ) const;
  178. bool RebuildTextSource( void );
  179. };
  180. #endif /* !__DECLAF_H__ */