1 /* 2 =========================================================================== 3 4 Doom 3 GPL Source Code 5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). 8 9 Doom 3 Source Code is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Doom 3 Source Code is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 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. 23 24 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. 25 26 =========================================================================== 27 */ 28 29 #ifndef __DECLAF_H__ 30 #define __DECLAF_H__ 31 32 #include "idlib/containers/List.h" 33 #include "idlib/math/Matrix.h" 34 #include "idlib/math/Angles.h" 35 #include "idlib/Str.h" 36 #include "idlib/Lexer.h" 37 #include "framework/DeclManager.h" 38 39 /* 40 =============================================================================== 41 42 Articulated Figure 43 44 =============================================================================== 45 */ 46 47 class idDeclAF; 48 49 typedef enum { 50 DECLAF_CONSTRAINT_INVALID, 51 DECLAF_CONSTRAINT_FIXED, 52 DECLAF_CONSTRAINT_BALLANDSOCKETJOINT, 53 DECLAF_CONSTRAINT_UNIVERSALJOINT, 54 DECLAF_CONSTRAINT_HINGE, 55 DECLAF_CONSTRAINT_SLIDER, 56 DECLAF_CONSTRAINT_SPRING 57 } declAFConstraintType_t; 58 59 typedef enum { 60 DECLAF_JOINTMOD_AXIS, 61 DECLAF_JOINTMOD_ORIGIN, 62 DECLAF_JOINTMOD_BOTH 63 } declAFJointMod_t; 64 65 typedef bool (*getJointTransform_t)( void *model, const idJointMat *frame, const char *jointName, idVec3 &origin, idMat3 &axis ); 66 67 class idAFVector { 68 public: 69 enum { 70 VEC_COORDS = 0, 71 VEC_JOINT, 72 VEC_BONECENTER, 73 VEC_BONEDIR 74 } type; 75 idStr joint1; 76 idStr joint2; 77 78 public: 79 idAFVector( void ); 80 81 bool Parse( idLexer &src ); 82 bool Finish( const char *fileName, const getJointTransform_t GetJointTransform, const idJointMat *frame, void *model ) const; 83 bool Write( idFile *f ) const; 84 const char * ToString( idStr &str, const int precision = 8 ); ToVec3(void)85 const idVec3 & ToVec3( void ) const { return vec; } ToVec3(void)86 idVec3 & ToVec3( void ) { return vec; } 87 88 private: 89 mutable idVec3 vec; 90 bool negate; 91 }; 92 93 class idDeclAF_Body { 94 public: 95 idStr name; 96 idStr jointName; 97 declAFJointMod_t jointMod; 98 int modelType; 99 idAFVector v1, v2; 100 int numSides; 101 float width; 102 float density; 103 idAFVector origin; 104 idAngles angles; 105 int contents; 106 int clipMask; 107 bool selfCollision; 108 idMat3 inertiaScale; 109 float linearFriction; 110 float angularFriction; 111 float contactFriction; 112 idStr containedJoints; 113 idAFVector frictionDirection; 114 idAFVector contactMotorDirection; 115 public: 116 void SetDefault( const idDeclAF *file ); 117 }; 118 119 class idDeclAF_Constraint { 120 public: 121 idStr name; 122 idStr body1; 123 idStr body2; 124 declAFConstraintType_t type; 125 float friction; 126 float stretch; 127 float compress; 128 float damping; 129 float restLength; 130 float minLength; 131 float maxLength; 132 idAFVector anchor; 133 idAFVector anchor2; 134 idAFVector shaft[2]; 135 idAFVector axis; 136 enum { 137 LIMIT_NONE = -1, 138 LIMIT_CONE, 139 LIMIT_PYRAMID 140 } limit; 141 idAFVector limitAxis; 142 float limitAngles[3]; 143 144 public: 145 void SetDefault( const idDeclAF *file ); 146 }; 147 148 class idDeclAF : public idDecl { 149 friend class idAFFileManager; 150 public: 151 idDeclAF( void ); 152 virtual ~idDeclAF( void ); 153 154 virtual size_t Size( void ) const; 155 virtual const char * DefaultDefinition( void ) const; 156 virtual bool Parse( const char *text, const int textLength ); 157 virtual void FreeData( void ); 158 159 virtual void Finish( const getJointTransform_t GetJointTransform, const idJointMat *frame, void *model ) const; 160 161 bool Save( void ); 162 163 void NewBody( const char *name ); 164 void RenameBody( const char *oldName, const char *newName ); 165 void DeleteBody( const char *name ); 166 167 void NewConstraint( const char *name ); 168 void RenameConstraint( const char *oldName, const char *newName ); 169 void DeleteConstraint( const char *name ); 170 171 static int ContentsFromString( const char *str ); 172 static const char * ContentsToString( const int contents, idStr &str ); 173 174 static declAFJointMod_t JointModFromString( const char *str ); 175 static const char * JointModToString( declAFJointMod_t jointMod ); 176 177 public: 178 bool modified; 179 idStr model; 180 idStr skin; 181 float defaultLinearFriction; 182 float defaultAngularFriction; 183 float defaultContactFriction; 184 float defaultConstraintFriction; 185 float totalMass; 186 idVec2 suspendVelocity; 187 idVec2 suspendAcceleration; 188 float noMoveTime; 189 float noMoveTranslation; 190 float noMoveRotation; 191 float minMoveTime; 192 float maxMoveTime; 193 int contents; 194 int clipMask; 195 bool selfCollision; 196 idList<idDeclAF_Body *> bodies; 197 idList<idDeclAF_Constraint *> constraints; 198 199 private: 200 bool ParseContents( idLexer &src, int &c ) const; 201 bool ParseBody( idLexer &src ); 202 bool ParseFixed( idLexer &src ); 203 bool ParseBallAndSocketJoint( idLexer &src ); 204 bool ParseUniversalJoint( idLexer &src ); 205 bool ParseHinge( idLexer &src ); 206 bool ParseSlider( idLexer &src ); 207 bool ParseSpring( idLexer &src ); 208 bool ParseSettings( idLexer &src ); 209 210 bool WriteBody( idFile *f, const idDeclAF_Body &body ) const; 211 bool WriteFixed( idFile *f, const idDeclAF_Constraint &c ) const; 212 bool WriteBallAndSocketJoint( idFile *f, const idDeclAF_Constraint &c ) const; 213 bool WriteUniversalJoint( idFile *f, const idDeclAF_Constraint &c ) const; 214 bool WriteHinge( idFile *f, const idDeclAF_Constraint &c ) const; 215 bool WriteSlider( idFile *f, const idDeclAF_Constraint &c ) const; 216 bool WriteSpring( idFile *f, const idDeclAF_Constraint &c ) const; 217 bool WriteConstraint( idFile *f, const idDeclAF_Constraint &c ) const; 218 bool WriteSettings( idFile *f ) const; 219 220 bool RebuildTextSource( void ); 221 }; 222 223 #endif /* !__DECLAF_H__ */ 224