Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkeletonAnimDef.h
Go to the documentation of this file.
1 /* Copyright (C) 2009 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19  * Raw description of a skeleton animation
20  */
21 
22 #ifndef INCLUDED_SKELETONANIMDEF
23 #define INCLUDED_SKELETONANIMDEF
24 
25 #include "maths/Vector3D.h"
26 #include "maths/Quaternion.h"
27 #include "lib/file/vfs/vfs_path.h"
28 
29 ////////////////////////////////////////////////////////////////////////////////////////
30 // CBoneState: structure describing state of a bone at some point
31 class CBoneState
32 {
33 public:
34  // translation of bone relative to root
36  // rotation of bone relative to root
38 };
39 
40 
41 ////////////////////////////////////////////////////////////////////////////////////////
42 // CSkeletonAnimDef: raw description - eg bonestates - of an animation that plays upon
43 // a skeleton
45 {
46 public:
47  // current file version given to saved animations
48  enum { FILE_VERSION = 1 };
49  // supported file read version - files with a version less than this will be rejected
50  enum { FILE_READ_VERSION = 1 };
51 
52 
53 public:
54  // Key: description of a single key in a skeleton animation
55  typedef CBoneState Key;
56 
57 public:
58  // CSkeletonAnimDef constructor + destructor
61 
62  // return the number of keys in this animation
63  size_t GetNumKeys() const { return (size_t)m_NumKeys; }
64 
65  // accessors: get a key for given bone at given time
66  Key& GetKey(size_t frame, size_t bone) { return m_Keys[frame*m_NumKeys+bone]; }
67  const Key& GetKey(size_t frame, size_t bone) const { return m_Keys[frame*m_NumKeys+bone]; }
68 
69  // get duration of this anim, in ms
70  float GetDuration() const { return m_NumFrames*m_FrameTime; }
71 
72  // return length of each frame, in ms
73  float GetFrameTime() const { return m_FrameTime; }
74  // return number of frames in animation
75  size_t GetNumFrames() const { return (size_t)m_NumFrames; }
76 
77  // build matrices for all bones at the given time (in MS) in this animation
78  void BuildBoneMatrices(float time, CMatrix3D* matrices, bool loop) const;
79 
80  // anim I/O functions
81  static CSkeletonAnimDef* Load(const VfsPath& filename);
82  static void Save(const VfsPath& pathname, const CSkeletonAnimDef* anim);
83 
84 public:
85  // frame time - time between successive frames, in ms
86  float m_FrameTime;
87  // number of keys in each frame - should match number of bones in the skeleton
88  size_t m_NumKeys;
89  // number of frames in the animation
90  size_t m_NumFrames;
91  // animation data - m_NumKeys*m_NumFrames total keys
93 };
94 
95 #endif
Key & GetKey(size_t frame, size_t bone)
size_t GetNumKeys() const
float GetFrameTime() const
CVector3D m_Translation
static void Save(const VfsPath &pathname, const CSkeletonAnimDef *anim)
void BuildBoneMatrices(float time, CMatrix3D *matrices, bool loop) const
Definition: path.h:75
CQuaternion m_Rotation
size_t GetNumFrames() const
const Key & GetKey(size_t frame, size_t bone) const
float GetDuration() const
static CSkeletonAnimDef * Load(const VfsPath &filename)