Simulant  21.12-574
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
rig.h
1 #pragma once
2 
3 #include <string>
4 
5 #include "../../math/quaternion.h"
6 #include "../../math/vec3.h"
7 #include "../../generic/containers/heap_array.h"
8 
9 namespace smlt {
10 
11 class Rig;
12 class Skeleton;
13 class Joint;
14 
15 class RigJoint {
16 public:
17  RigJoint() {}
18 
19  void rotate_to(const smlt::Quaternion& rotation);
20  void move_to(const smlt::Vec3& translation);
21 
22  const Vec3& translation() const {
23  return translation_;
24  }
25 
26  const Quaternion& rotation() const {
27  return rotation_;
28  }
29 
30  RigJoint* parent() const {
31  return parent_;
32  }
33 
34  std::string name() const;
35 
36 private:
37  friend class Rig;
38  friend class SkeletalFrameUnpacker;
39 
40  Rig* rig_ = nullptr;
41  RigJoint* parent_ = nullptr;
42 
43  const Joint* skeleton_joint_ = nullptr;
44 
45  Vec3 translation_, absolute_translation_;
46  Quaternion rotation_, absolute_rotation_;
47 };
48 
49 
50 class Rig {
51 public:
52  Rig(const Skeleton* skeleton);
53  RigJoint* joint(std::size_t index);
54  RigJoint* find_joint(const std::string& name);
55 
56  /* Should always be equal to the skeleton joint count */
57  std::size_t joint_count() const;
58 
59 private:
60  friend class RigJoint;
61  friend class SkeletalFrameUnpacker;
62 
63  bool absolute_transformations_dirty_ = true;
64  void recalc_absolute_transformations();
65 
66  heap_array<RigJoint> joints_;
67 };
68 
69 }
smlt::Vec3
Definition: vec3.h:23
smlt::Quaternion
Definition: quaternion.h:20
smlt::Skeleton
Definition: skeleton.h:94
smlt
Definition: animation.cpp:25
smlt::RigJoint
Definition: rig.h:15
smlt::Joint
Definition: skeleton.h:25
smlt::heap_array
Definition: heap_array.h:14
smlt::SkeletalFrameUnpacker
Definition: skeleton.h:163
smlt::Rig
Definition: rig.h:50