]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/framework/DeclAF.h
hello world
[icculus/iodoom3.git] / neo / framework / DeclAF.h
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 /*
33 ===============================================================================
34
35         Articulated Figure
36
37 ===============================================================================
38 */
39
40 class idDeclAF;
41
42 typedef enum {
43         DECLAF_CONSTRAINT_INVALID,
44         DECLAF_CONSTRAINT_FIXED,
45         DECLAF_CONSTRAINT_BALLANDSOCKETJOINT,
46         DECLAF_CONSTRAINT_UNIVERSALJOINT,
47         DECLAF_CONSTRAINT_HINGE,
48         DECLAF_CONSTRAINT_SLIDER,
49         DECLAF_CONSTRAINT_SPRING
50 } declAFConstraintType_t;
51
52 typedef enum {
53         DECLAF_JOINTMOD_AXIS,
54         DECLAF_JOINTMOD_ORIGIN,
55         DECLAF_JOINTMOD_BOTH
56 } declAFJointMod_t;
57
58 typedef bool (*getJointTransform_t)( void *model, const idJointMat *frame, const char *jointName, idVec3 &origin, idMat3 &axis );
59
60 class idAFVector {
61 public:
62         enum {
63                 VEC_COORDS = 0,
64                 VEC_JOINT,
65                 VEC_BONECENTER,
66                 VEC_BONEDIR
67         }                                               type;
68         idStr                                   joint1;
69         idStr                                   joint2;
70
71 public:
72                                                         idAFVector( void );
73
74         bool                                    Parse( idLexer &src );
75         bool                                    Finish( const char *fileName, const getJointTransform_t GetJointTransform, const idJointMat *frame, void *model ) const;
76         bool                                    Write( idFile *f ) const;
77         const char *                    ToString( idStr &str, const int precision = 8 );
78         const idVec3 &                  ToVec3( void ) const { return vec; }
79         idVec3 &                                ToVec3( void ) { return vec; }
80
81 private:
82         mutable idVec3                  vec;
83         bool                                    negate;
84 };
85
86 class idDeclAF_Body {
87 public:
88         idStr                                   name;
89         idStr                                   jointName;
90         declAFJointMod_t                jointMod;
91         int                                             modelType;
92         idAFVector                              v1, v2;
93         int                                             numSides;
94         float                                   width;
95         float                                   density;
96         idAFVector                              origin;
97         idAngles                                angles;
98         int                                             contents;
99         int                                             clipMask;
100         bool                                    selfCollision;
101         idMat3                                  inertiaScale;
102         float                                   linearFriction;
103         float                                   angularFriction;
104         float                                   contactFriction;
105         idStr                                   containedJoints;
106         idAFVector                              frictionDirection;
107         idAFVector                              contactMotorDirection;
108 public:
109         void                                    SetDefault( const idDeclAF *file );
110 };
111
112 class idDeclAF_Constraint {
113 public:
114         idStr                                   name;
115         idStr                                   body1;
116         idStr                                   body2;
117         declAFConstraintType_t  type;
118         float                                   friction;
119         float                                   stretch;
120         float                                   compress;
121         float                                   damping;
122         float                                   restLength;
123         float                                   minLength;
124         float                                   maxLength;
125         idAFVector                              anchor;
126         idAFVector                              anchor2;
127         idAFVector                              shaft[2];
128         idAFVector                              axis;
129         enum {
130                 LIMIT_NONE = -1,
131                 LIMIT_CONE,
132                 LIMIT_PYRAMID
133         }                                               limit;
134         idAFVector                              limitAxis;
135         float                                   limitAngles[3];
136
137 public:
138         void                                    SetDefault( const idDeclAF *file );
139 };
140
141 class idDeclAF : public idDecl {
142         friend class idAFFileManager;
143 public:
144                                                         idDeclAF( void );
145         virtual                                 ~idDeclAF( void );
146
147         virtual size_t                  Size( void ) const;
148         virtual const char *    DefaultDefinition( void ) const;
149         virtual bool                    Parse( const char *text, const int textLength );
150         virtual void                    FreeData( void );
151
152         virtual void                    Finish( const getJointTransform_t GetJointTransform, const idJointMat *frame, void *model ) const;
153
154         bool                                    Save( void );
155
156         void                                    NewBody( const char *name );
157         void                                    RenameBody( const char *oldName, const char *newName );
158         void                                    DeleteBody( const char *name );
159
160         void                                    NewConstraint( const char *name );
161         void                                    RenameConstraint( const char *oldName, const char *newName );
162         void                                    DeleteConstraint( const char *name );
163
164         static int                              ContentsFromString( const char *str );
165         static const char *             ContentsToString( const int contents, idStr &str );
166
167         static declAFJointMod_t JointModFromString( const char *str );
168         static const char *             JointModToString( declAFJointMod_t jointMod );
169
170 public:
171         bool                                    modified;
172         idStr                                   model;
173         idStr                                   skin;
174         float                                   defaultLinearFriction;
175         float                                   defaultAngularFriction;
176         float                                   defaultContactFriction;
177         float                                   defaultConstraintFriction;
178         float                                   totalMass;
179         idVec2                                  suspendVelocity;
180         idVec2                                  suspendAcceleration;
181         float                                   noMoveTime;
182         float                                   noMoveTranslation;
183         float                                   noMoveRotation;
184         float                                   minMoveTime;
185         float                                   maxMoveTime;
186         int                                             contents;
187         int                                             clipMask;
188         bool                                    selfCollision;
189         idList<idDeclAF_Body *>                 bodies;
190         idList<idDeclAF_Constraint *>   constraints;
191
192 private:
193         bool                                    ParseContents( idLexer &src, int &c ) const;
194         bool                                    ParseBody( idLexer &src );
195         bool                                    ParseFixed( idLexer &src );
196         bool                                    ParseBallAndSocketJoint( idLexer &src );
197         bool                                    ParseUniversalJoint( idLexer &src );
198         bool                                    ParseHinge( idLexer &src );
199         bool                                    ParseSlider( idLexer &src );
200         bool                                    ParseSpring( idLexer &src );
201         bool                                    ParseSettings( idLexer &src );
202
203         bool                                    WriteBody( idFile *f, const idDeclAF_Body &body ) const;
204         bool                                    WriteFixed( idFile *f, const idDeclAF_Constraint &c ) const;
205         bool                                    WriteBallAndSocketJoint( idFile *f, const idDeclAF_Constraint &c ) const;
206         bool                                    WriteUniversalJoint( idFile *f, const idDeclAF_Constraint &c ) const;
207         bool                                    WriteHinge( idFile *f, const idDeclAF_Constraint &c ) const;
208         bool                                    WriteSlider( idFile *f, const idDeclAF_Constraint &c ) const;
209         bool                                    WriteSpring( idFile *f, const idDeclAF_Constraint &c ) const;
210         bool                                    WriteConstraint( idFile *f, const idDeclAF_Constraint &c ) const;
211         bool                                    WriteSettings( idFile *f ) const;
212
213         bool                                    RebuildTextSource( void );
214 };
215
216 #endif /* !__DECLAF_H__ */