My Project
Bone.h
1 #ifndef __BONE_H__
2 #define __BONE_H__
3 
4 #include "utils.h"
5 #include "ModelUtils.h"
6 #include "GeosetAnim.h"
7 #include "Texture.h"
8 #include <vector>
9 using namespace std;
10 
11 namespace ParaEngine
12 {
13 class CSkeleton;
14 
15 //line near
17  int frameNum;
18  D3DXVECTOR3 vec;
19 };
21  int frameNum;
22  D3DXVECTOR3 vec;
23  D3DXVECTOR3 inTan;
24  D3DXVECTOR3 outTan;
25 };
27  int frameNum;
28  D3DXQUATERNION vec;
29 };
31  int frameNum;
32  D3DXQUATERNION vec;
33  D3DXQUATERNION inTan;
34  D3DXQUATERNION outTan;
35 };
36 
55 class CBone1
56 {
57 public:
58  CBone1(void);
59  ~CBone1(void);
60 
61  void Read(TypePointer inP,int inSize);
62 
63  int GetGeosetID() { return geosetID; };
64  int GetGeosetAnimID() { return geosetAnimID; };
65  void SetGeosetAlpha(float alpha) {geosetAnimAlpha=alpha;};
66  float GetGeosetAlpha() {return geosetAnimAlpha;};
67 
68  char* GetBoneName() { return boneName; };
69  int GetObjectID() { return objectID; };
70  int GetParentID() { return parentID; };
71 
72  D3DXMATRIX* GetFinalTransformMatrix() { return &finalMatrix; };
73  D3DXMATRIX* GetCombinedTransformMatrix() { return &combinedMatrix; };
74  D3DXMATRIX* CalcTransformMatrix(D3DXVECTOR3* center, const AnimInfo& animInfo,const D3DXMATRIX* parentMatrix);
75 
76  D3DXMATRIX* TransformMatrixMultiply(const D3DXMATRIX* matrix);
77 
78 private:
79 bool GetTransferMatrix(D3DXVECTOR3* vec,const AnimInfo& animInfo);
80 bool GetTransferMatrixNoneBlending(D3DXVECTOR3* vec,const AnimInfo& animInfo);
81 bool GetRotationMatrix(D3DXQUATERNION* quat,const AnimInfo& animInfo);
82 bool GetRotationMatrixNoneBlending(D3DXQUATERNION* quat,const AnimInfo& animInfo);
83 bool GetScaleMatrix(D3DXVECTOR3* vec,const AnimInfo& animInfo);
84 bool GetScaleMatrixNoneBlending(D3DXVECTOR3* vec,const AnimInfo& animInfo);
85 bool CheckHideByScale(const AnimInfo& animInfo);
86 
87 public:
88 
90  enum LineType{
91  NOT_INTERP=0,
92  LINEAR,
94  BEZIER
95  };
96 
98  enum MotionType{
100  KGRT=0,
101  KGSC=1,
102  KGTR=2,
103  MAX_MOTION=3
104  };
105 
106  int objectID;
107  int parentID;
108  int nextID;
109  D3DXMATRIX localMatrix;
110  D3DXMATRIX combinedMatrix;
111  D3DXMATRIX offsetMatrix;
112  D3DXMATRIX finalMatrix;
113 
114 
115 private:
116  char* boneName;
117  int nodeType;
118 
119  //key frames count
120  int keyFrameCount[MAX_MOTION];
121  //Linear Type
122  int lineType[MAX_MOTION];
123  void* keyFrames[MAX_MOTION];
124 
125  int geosetID;
126  int geosetAnimID;
127 
128  float geosetAnimAlpha;
129 public:
130  friend class CMDXModel;
131  friend class CSkeleton;
132 };
133 
134 
135 
136 class CBone2
137 {
138 public:
139  CBone2(void);
140  ~CBone2(void);
141 
142  void Read(TypePointer &inP);
143 
144  D3DXMATRIX* GetFinalTransformMatrix() { return &transformMatrix; };
145  D3DXMATRIX* CalcTransformMatrix(D3DXVECTOR3* center, const AnimInfo& animInfo,const D3DXMATRIX* parentMatrix);
146 
147 private:
148 
149 bool GetTransferMatrix(D3DXVECTOR3* vec,const AnimInfo& animInfo);
150 bool GetRotationMatrix(D3DXQUATERNION* quat,const AnimInfo& animInfo);
151 bool GetScaleMatrix(D3DXVECTOR3* vec,const AnimInfo& animInfo);
152 bool CheckHideByScale(const AnimInfo& animInfo);
153 
154 public:
155 
156  int count;
157 
158  //Linear Type (0:don't interpret;1:linear;2:hermite;3:bezier)
159  enum LineType{
160  NOT_INTERP=0,
161  LINEAR,
162  HERMITE,
163  BEZIER
164  };
165 
166  enum MotionType{
167  KGTR=0,
168  KGRT,
169  KGSC,
170  MAX_MOTION
171  };
172 
173 private:
174  //key frames count
175  int keyFrameCount[MAX_MOTION];
176  //Linear Type
177  int lineType[MAX_MOTION];
178  void* keyFrames[MAX_MOTION];
179 
180  D3DXMATRIX transformMatrix;
181 };
182 
183 
184 
185 
186 
187 #define MDX_MAX_PARTICLES 100
188 
189 typedef struct // Create A Structure For Particle
190 {
191  bool used;
192  bool activated; // Active (Yes/No)
193  float life; // Particle Life
194  float fade; // Fade Speed
195  float r; // Red Value
196  float g; // Green Value
197  float b; // Blue Value
198  float x; // X Position
199  float y; // Y Position
200  float z; // Z Position
201  float xi; // X Direction
202  float yi; // Y Direction
203  float zi; // Z Direction
204  float xg; // X Gravity
205  float yg; // Y Gravity
206  float zg; // Z Gravity
207 } MyParticle; // Particle Structure
208 
209 
210 
211 
212 class CEmitter
213 {
214 public:
215  CEmitter(void);
216  ~CEmitter(void);
217 
218  void Read(TypePointer inP,int inSize);
219  void Render(D3DXMATRIX *parentMatrix, D3DXVECTOR3 *center, const AnimInfo& animInfo, long texbindid, long texwidth, long texlength);
220  void SetCurrentOptions(const AnimInfo& animInfo);
221 
222  char* GetName() { return eName; };
223  long GetObjectID() { return objectID; };
224  long GetParentID() { return parentID; };
225 
226  struct TVisibility
227  {
228  long kframe;
229  float f;
230  };
231 
232 
233  MyParticle Particles[MDX_MAX_PARTICLES]; // Particle Array (Room For Particle Info)
234 
235 
236  char* eName;
237  long objectID;
238  long parentID;
239  long Flags;
240  CBone2 bone;
241  float curSpeed;
242  float Variation;
243  float Latitude;
244  float Gravity;
245  float Lifespan;
246  float curEmissionRate;
247  float curLength;
248  float curWidth;
249  long FilterMode;
250  long Rows;
251  long Columns;
252  long Flag2;
253  float TailLength;
254  float Time;
255 
256  struct colors3
257  {
258  float B;
259  float G;
260  float R;
261  } SegmentColor[3];
262 
263  unsigned char Alpha1, Alpha2, Alpha3;
264  float ScalingX, ScalingY, ScalingZ;
265  long LifeSpanUVAnim1, LifeSpanUVAnim2, LifeSpanUVAnim3;
266  long DecayUVAnim1, DecayUVAnim2, DecayUVAnim3;
267  long TailUVAnim1, TailUVAnim2, TailUVAnim3;
268  long TailDecayUVAnim1, TailDecayUVAnim2, TailDecayUVAnim3;
269  long TextureID;
270  long Squirt;
271  long PriorityPlane;
272  long ReplaceableID;
273 
274  long numParticles;
275 
276  TVisibility* Visibility;
277  long numVisibility;
278  float curVisibility;
279 
280  TVisibility* EmissnRate;
281  long numEmissnRate;
282 
283  TVisibility* Length;
284  long numLength;
285 
286  TVisibility* Width;
287  long numWidth;
288 
289  TVisibility* Speed;
290  long numSpeed;
291 };
292 
293 
294 
295 #define MAX_NUM_EMMITTERS 4
296 
298 {
299 public:
300  CEmitters(void);
301  ~CEmitters(void);
302  void Cleanup();
303 
304  void Read(TypePointer inP,int inSize);
305  void Render(const AnimInfo& animInfo, const CSkeleton *skel, CTexture *curtex);
306 
307  long numEmitters;
308  UINT nEmitterArraySize;
309  CEmitter* Emitters; // array
310 };
311 
318 {
319 public:
320  CSkeleton(void);
321  ~CSkeleton(void);
322 
323  void Cleanup();
324 
325  void ReadGeosetAnims(TypePointer inP,int inSize);
326  void ReadHelpers(TypePointer inP,int inSize);
327  void ReadBones(TypePointer inP,int inSize);
328  void ReadPivotPoints(TypePointer inP,int inSize);
329 
330  void SortBones();
331  void CalcTransformMatrix(const AnimInfo& animInfo);
332 
333  float GetTransformMatrix(D3DXMATRIX &mat,float& animAlpha,int *index,int count);
334 
335  CBone1* CreateNewBone();
336 
337 private:
338  void CalcTransformMatrix(const AnimInfo& animInfo,D3DXMATRIX *parentMatrix,int parentID);
339 
340 public:
341  CGeosetAnim geosetAnims;
342  int nFirstBoneID;
343 
344  vector <CBone1*> bones;
345 
346  CEmitters BlizEmitters2;
347 };
348 
349 }
350 #endif //__BONE_H__
Definition: Bone.h:189
D3DXMATRIX finalMatrix
offsetMatrix will transform original mesh vertice from their bone pose to local bone space...
Definition: Bone.h:112
Definition: Bone.h:16
D3DXMATRIX combinedMatrix
the localMatrix in the bone pose. localMatrix is used if no animation or translation keyframes is ava...
Definition: Bone.h:110
Each x file model must has a skeleton(including static object) A skeleton contains a collection of bo...
Definition: Bone.h:317
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: utils.h:13
Definition: Bone.h:26
D3DXMATRIX localMatrix
the object ID of its next bone in the skeleton.-1 if it is the last bone
Definition: Bone.h:109
Definition: Bone.h:30
LineType
Linear Type (0:don&#39;t interpret;1:linear;2:hermite;3:bezier)
Definition: Bone.h:90
Definition: Bone.h:212
The class stands for the bone or frame in the character&#39;s skeleton.
Definition: Bone.h:55
Definition: Bone.h:20
Model textures are managed separately with the paraengine asset manager&#39;s texture pool...
Definition: Texture.h:32
For animating the alpha of bones.
Definition: GeosetAnim.h:43
Definition: ModelUtils.h:7
Definition: Bone.h:136
This is the ParaX mesh and animation file format model.
Definition: MDXModel.h:61
Definition: Bone.h:297
MotionType
LiXizhi: this is the order defined by X file template.
Definition: Bone.h:99
D3DXMATRIX offsetMatrix
combinedMatrix will transform the vertices from the local bone space to its character space...
Definition: Bone.h:111
Definition: Bone.h:226
int parentID
the object ID, which is the same as the its index in the skeleton list
Definition: Bone.h:107
Definition: Bone.h:256
int nextID
the object ID of its parent bone
Definition: Bone.h:108
this is the most oftenly used.
Definition: Bone.h:93