My Project
AnimInstanceBase.h
1 #pragma once
2 #include "IAttributeFields.h"
3 #include <map>
4 
5 namespace ParaEngine
6 {
7  struct SceneState;
8  class ShadowVolume;
9  struct LightParams;
10  using namespace std;
11 
13  struct AnimIndex
14  {
15  public:
16  AnimIndex():nIndex(-1), Provider(0), nCurrentFrame(0), nStartFrame(0), nEndFrame(0),loopType(0),nAnimID(0),nFramePlayed(0) {}
17  AnimIndex(int nIndex_):nIndex(nIndex_), Provider(0), nCurrentFrame(0), nStartFrame(0), nEndFrame(0),loopType(0),nAnimID(0),nFramePlayed(0){}
18  AnimIndex(int nIndex_, byte nProvider_):nIndex(nIndex_), Provider(nProvider_), nCurrentFrame(0), nStartFrame(0), nEndFrame(0),loopType(0),nAnimID(0),nFramePlayed(0){}
19  AnimIndex(int nIndex_, byte nProvider_, int nStartFrame_, int nEndFrame_, byte loopType_):nIndex(nIndex_), Provider(nProvider_), nCurrentFrame(nStartFrame_), nStartFrame(nStartFrame_), nEndFrame(nEndFrame_),loopType(loopType_),nAnimID(0),nFramePlayed(0){}
20  AnimIndex(int nIndex_, byte nProvider_, int nStartFrame_, int nEndFrame_, byte loopType_, int nAnimID):nIndex(nIndex_), Provider(nProvider_), nCurrentFrame(nStartFrame_), nStartFrame(nStartFrame_), nEndFrame(nEndFrame_),loopType(loopType_),nAnimID(nAnimID),nFramePlayed(0){}
21 
23  bool IsValid() const {return nIndex != -1;}
24 
26  bool operator==(const AnimIndex& right) const {return (this->nIndex == right.nIndex) && (this->Provider == right.Provider) && (this->loopType == right.loopType);}
27  bool operator!=(const AnimIndex& right) const {return (this->nIndex != right.nIndex) || (this->Provider != right.Provider) || ((this->loopType != right.loopType));}
28 
30  bool IsLooping() const {return loopType==0;};
31 
33  bool IsUndetermined() const {return loopType==2;};
34 
36  void Reset() {nCurrentFrame = nStartFrame;nFramePlayed=0;};
37 
39  void MakeInvalid() {nIndex = -1;Provider=0;};
40 
42  void AddCycle(){ nFramePlayed += (nEndFrame-nStartFrame);}
43  public:
44  // bone animation provider: 0 for local model bone animation pool; 1 for global bone animation provider
45  byte Provider;
46  // 0 for looping, 1 for non-looping, 2 for undeterminted(the animation needs to be refreshed upon finish, such as during async-loading).
47  byte loopType;
48  // current index, -1 if invalid
49  int nIndex;
50  // the animation ID as seen by outsiders
51  int nAnimID;
52  // current frame
53  int nCurrentFrame;
54  // start frame
55  int nStartFrame;
56  // end frame
57  int nEndFrame;
58  // total number of frames played
59  int nFramePlayed;
60  };
61 
67  {
68  public:
70  virtual ~CAnimInstanceBase(){};
71 
72  ATTRIBUTE_DEFINE_CLASS(CAnimInstanceBase);
73 
75  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
76 
77  ATTRIBUTE_METHOD1(CAnimInstanceBase, GetRenderCount_s, int*) { *p1 = cls->GetRenderCount(); return S_OK; }
78  ATTRIBUTE_METHOD1(CAnimInstanceBase, SetRenderCount_s, int) { cls->SetRenderCount(p1); return S_OK; }
79 
80  ATTRIBUTE_METHOD1(CAnimInstanceBase, IsAnimIDMapEnabled_s, bool*) { *p1 = cls->IsAnimIDMapEnabled(); return S_OK; }
81  ATTRIBUTE_METHOD1(CAnimInstanceBase, EnableAnimIDMap_s, bool) { cls->EnableAnimIDMap(p1); return S_OK; }
82 
83  ATTRIBUTE_METHOD(CAnimInstanceBase, ResetAnimation_s) { cls->ResetAnimation(); return S_OK; }
84 
85  ATTRIBUTE_METHOD1(CAnimInstanceBase, GetCurrentAnimation_s, int*) { *p1 = cls->GetCurrentAnimation(); return S_OK; }
86 
87  ATTRIBUTE_METHOD1(CAnimInstanceBase, ShowMesh_s, DWORD) { cls->ShowMesh(p1); return S_OK; }
88 
89  ATTRIBUTE_METHOD1(CAnimInstanceBase, GetSizeScale_s, float*) { *p1 = cls->GetSizeScale(); return S_OK; }
90  ATTRIBUTE_METHOD1(CAnimInstanceBase, SetSizeScale_s, float) { cls->SetSizeScale(p1); return S_OK; }
91 
92  ATTRIBUTE_METHOD1(CAnimInstanceBase, GetSpeedScale_s, float*) { *p1 = cls->GetSpeedScale(); return S_OK; }
93  ATTRIBUTE_METHOD1(CAnimInstanceBase, SetSpeedScale_s, float) { cls->SetSpeedScale(p1); return S_OK; }
94 
95  ATTRIBUTE_METHOD1(CAnimInstanceBase, IsUseGlobalTime_s, bool*) { *p1 = cls->IsUseGlobalTime(); return S_OK; }
96  ATTRIBUTE_METHOD1(CAnimInstanceBase, SetUseGlobalTime_s, bool) { cls->SetUseGlobalTime(p1); return S_OK; }
97 
98  ATTRIBUTE_METHOD1(CAnimInstanceBase, GetAnimFrame_s, int*) { *p1 = cls->GetAnimFrame(); return S_OK; }
99  ATTRIBUTE_METHOD1(CAnimInstanceBase, SetAnimFrame_s, int) { cls->SetAnimFrame(p1); return S_OK; }
100 
101  ATTRIBUTE_METHOD1(CAnimInstanceBase, IsAnimationEnabled_s, bool*) { *p1 = cls->IsAnimationEnabled(); return S_OK; }
102  ATTRIBUTE_METHOD1(CAnimInstanceBase, EnableAnimation_s, bool) { cls->EnableAnimation(p1); return S_OK; }
103 
104  protected:
105  // object status primitive
108  //bool m_bLoopAnim;
109  //DWORD m_dwLoiterIndex;
110 
111  // type specific informations
116  float m_fSpeedScale;
119 
125  map<int, int> m_mapAnimIDs;
126 
131 
132  public:
137  virtual int GetRenderCount();
138  virtual void SetRenderCount(int nCount);
139 
143  void EnableAnimIDMap(bool bEnable);
144 
148  bool IsAnimIDMapEnabled();
149 
156  map<int, int>* GetAnimIDMap();
157 
160  void ApplyLocalTransformToVec3( Vector3 *pOut,const Vector3 *pV);
161  void ApplyLocalTransformToVec1( float *pOut,float* pV);
162 
173  virtual void LoadAnimation(const char * sName, float * fSpeed, bool bAppend = false);
174  virtual void LoadAnimation(int nAnimID, float * fSpeed,bool bAppend = false);
175  virtual void LoadDefaultStandAnim(float * fSpeed);
176  virtual void LoadDefaultWalkAnim(float * fSpeed);
177 
179  virtual bool HasAnimId(int nAnimID);
180 
183  virtual int GetCurrentAnimation();
184 
187  virtual void ResetAnimation();
188 
190  virtual void SetModelColor(LinearColor modelColor);
193  virtual void ShowMesh(BOOL bShow, int nIndex);
194  virtual void ShowMesh(DWORD dwBitfields);
197  virtual void SetLocalTransform(Matrix4 mXForm);
198 
200  virtual void AdvanceTime( double dTimeDelta );
201 
205  virtual void Animate( double dTimeDelta, int nRenderNumber=0 );
206 
207  //Add third parameter, pass per instance material parameters --clayman 2012.7.4
209  virtual HRESULT Draw( SceneState * sceneState, const Matrix4* mxWorld,CParameterBlock* paramBlock = NULL);
210 
211  virtual void BuildShadowVolume(SceneState * sceneState, ShadowVolume * pShadowVolume, LightParams* pLight, Matrix4* mxWorld);
212 
213  /* new set */
215  virtual void SetSizeScale(float fScale);
217  virtual float GetSizeScale();
218 
221  virtual void GetCurrentRadius(float* fRadius){};
224  virtual void GetCurrentSize(float * fWidth, float * fDepth);
228  virtual void SetSpeedScale( float fScale );
233  virtual float GetSpeedScale();
236  virtual void GetCurrentSpeed (float* fSpeed);
239  virtual void GetSpeedOf(const char * sName, float * fSpeed);
240 
246  virtual void SetUseGlobalTime(bool bUseGlobalTime);
247 
253  virtual bool IsUseGlobalTime();
254 
258  virtual void SetAnimFrame(int nFrame);
259 
261  virtual int GetAnimFrame();
262 
266  virtual void SetBlendingFactor(float fBlendingFactor);
267 
269  virtual bool HasAnimation(int nAnimID);
270 
274  virtual bool HasAlphaBlendedObjects();
275 
277  virtual int GetValidAnimID(int nAnimID);
278 
280  void EnableAnimation(bool bAnimated);
281  bool IsAnimationEnabled() const;
282  };
283 }
bool m_bEnableAnimIDMap
whether the m_mapAnimIDs will be used.
Definition: AnimInstanceBase.h:128
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
ShadowVolume is a structure for storing shadow volume geometries.
Definition: ShadowVolume.h:39
It&#39;s used as parameter to Draw method of each scene object.
Definition: SceneState.h:284
bool IsLooping() const
whether use looping
Definition: AnimInstanceBase.h:30
void MakeInvalid()
make this instance invalid.
Definition: AnimInstanceBase.h:39
abstract class for all animation instance implementation.
Definition: AnimInstanceBase.h:66
different physics engine has different winding order.
Definition: EventBinding.h:32
void AddCycle()
add total frames to nFramePlayed.
Definition: AnimInstanceBase.h:42
float m_fSizeScale
scale parameters
Definition: AnimInstanceBase.h:115
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
LightParams is a structure for which a shadow volume is built.
Definition: ShadowVolume.h:8
bool IsValid() const
whether index is valid
Definition: AnimInstanceBase.h:23
bool IsUndetermined() const
if animation is undetermined, we should refresh this structure from asset, possibly because the anima...
Definition: AnimInstanceBase.h:33
LinearColor m_modelColor
color of this model
Definition: AnimInstanceBase.h:107
Matrix4 m_mxLocalTransform
mesh local world xform: center in the origin
Definition: AnimInstanceBase.h:113
bool m_bEnableAnimation
whether animation is enabled, true by default.
Definition: AnimInstanceBase.h:130
bool operator==(const AnimIndex &right) const
two index are considered equal if nIndex and Provider are the same.
Definition: AnimInstanceBase.h:26
int m_nRenderCount
the last render frame count that this object is rendered.
Definition: AnimInstanceBase.h:118
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: ParaMatrix4.h:23
it presents a given in bone animation providers or parax local model bone animation pools ...
Definition: AnimInstanceBase.h:13
A common interface for all classes implementing IAttributeFields By implementing this class&#39;s virtual...
Definition: IAttributeFields.h:59
virtual void GetCurrentRadius(float *fRadius)
normally this will read the radius of the current animation and calculate the correct size after scal...
Definition: AnimInstanceBase.h:221
map< int, int > m_mapAnimIDs
a mapping from one animation ID to another ID.
Definition: AnimInstanceBase.h:125
void Reset()
set the current frame to the start frame
Definition: AnimInstanceBase.h:36
A linear, 32-bit/component floating point RGBA color.
Definition: ParaColor.h:12
a list of CParameter{name, value} pairs of anything.
Definition: ParameterBlock.h:108