Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
SkeletonAnimDef.h
Go to the documentation of this file.
1/* Copyright (C) 2021 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"
28
29#include <memory>
30#include <vector>
31
32////////////////////////////////////////////////////////////////////////////////////////
33// CBoneState: structure describing state of a bone at some point
35{
36public:
37 // translation of bone relative to root
39 // rotation of bone relative to root
41};
42
43
44////////////////////////////////////////////////////////////////////////////////////////
45// CSkeletonAnimDef: raw description - eg bonestates - of an animation that plays upon
46// a skeleton
48{
49public:
50 // current file version given to saved animations
51 enum { FILE_VERSION = 1 };
52 // supported file read version - files with a version less than this will be rejected
53 enum { FILE_READ_VERSION = 1 };
54
55
56public:
57 // Key: description of a single key in a skeleton animation
58 typedef CBoneState Key;
59
60public:
61 // CSkeletonAnimDef constructor + destructor
64
65 // return the number of keys in this animation
66 size_t GetNumKeys() const { return (size_t)m_NumKeys; }
67
68 // accessors: get a key for given bone at given time
69 Key& GetKey(size_t frame, size_t bone) { return m_Keys[frame*m_NumKeys+bone]; }
70 const Key& GetKey(size_t frame, size_t bone) const { return m_Keys[frame*m_NumKeys+bone]; }
71
72 // get duration of this anim, in ms
73 float GetDuration() const { return m_NumFrames*m_FrameTime; }
74
75 // return length of each frame, in ms
76 float GetFrameTime() const { return m_FrameTime; }
77 // return number of frames in animation
78 size_t GetNumFrames() const { return (size_t)m_NumFrames; }
79
80 // build matrices for all bones at the given time (in MS) in this animation
81 void BuildBoneMatrices(float time, CMatrix3D* matrices, bool loop) const;
82
83 // anim I/O functions
84 static std::unique_ptr<CSkeletonAnimDef> Load(const VfsPath& filename);
85 static void Save(const VfsPath& pathname, const CSkeletonAnimDef& anim);
86
87public:
88 // frame time - time between successive frames, in ms
90 // number of keys in each frame - should match number of bones in the skeleton
91 size_t m_NumKeys;
92 // number of frames in the animation
94 // animation data - m_NumKeys*m_NumFrames total keys
95 std::vector<Key> m_Keys;
96 // Unique identifier - used by CModelDef to cache bounds per-animDef.
97 // (hopefully we won't run into the u32 limit too soon).
99};
100
101#endif
Definition: SkeletonAnimDef.h:35
CVector3D m_Translation
Definition: SkeletonAnimDef.h:38
CQuaternion m_Rotation
Definition: SkeletonAnimDef.h:40
Definition: Matrix3D.h:34
Definition: Quaternion.h:26
Definition: SkeletonAnimDef.h:48
@ FILE_VERSION
Definition: SkeletonAnimDef.h:51
size_t GetNumFrames() const
Definition: SkeletonAnimDef.h:78
Key & GetKey(size_t frame, size_t bone)
Definition: SkeletonAnimDef.h:69
static void Save(const VfsPath &pathname, const CSkeletonAnimDef &anim)
Definition: SkeletonAnimDef.cpp:135
float GetDuration() const
Definition: SkeletonAnimDef.h:73
u32 m_UID
Definition: SkeletonAnimDef.h:98
CBoneState Key
Definition: SkeletonAnimDef.h:58
float GetFrameTime() const
Definition: SkeletonAnimDef.h:76
size_t m_NumKeys
Definition: SkeletonAnimDef.h:91
size_t m_NumFrames
Definition: SkeletonAnimDef.h:93
float m_FrameTime
Definition: SkeletonAnimDef.h:89
@ FILE_READ_VERSION
Definition: SkeletonAnimDef.h:53
size_t GetNumKeys() const
Definition: SkeletonAnimDef.h:66
static std::unique_ptr< CSkeletonAnimDef > Load(const VfsPath &filename)
Definition: SkeletonAnimDef.cpp:105
~CSkeletonAnimDef()
Definition: SkeletonAnimDef.cpp:53
CSkeletonAnimDef()
Definition: SkeletonAnimDef.cpp:39
const Key & GetKey(size_t frame, size_t bone) const
Definition: SkeletonAnimDef.h:70
void BuildBoneMatrices(float time, CMatrix3D *matrices, bool loop) const
Definition: SkeletonAnimDef.cpp:60
std::vector< Key > m_Keys
Definition: SkeletonAnimDef.h:95
Definition: Vector3D.h:31
Definition: path.h:80
uint32_t u32
Definition: types.h:39