Antkeeper  0.0.1
pose.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_ANIMATION_POSE_HPP
21 #define ANTKEEPER_ANIMATION_POSE_HPP
22 
24 #include <vector>
25 
26 class skeleton;
27 
31 class pose
32 {
33 public:
39  explicit pose(const skeleton& skeleton);
40 
42  constexpr pose() noexcept = default;
43 
47  void update();
48 
57  virtual void update(bone_index_type first_index, std::size_t bone_count);
58 
65  inline void set_relative_transform(bone_index_type index, const bone_transform_type& transform)
66  {
67  m_relative_transforms[index] = transform;
68  }
69 
77  {
78  m_relative_transforms[index].translation = translation;
79  }
80 
88  {
89  m_relative_transforms[index].rotation = rotation;
90  }
91 
99  {
100  m_relative_transforms[index].scale = scale;
101  }
102 
104  [[nodiscard]] inline const skeleton* get_skeleton() const noexcept
105  {
106  return m_skeleton;
107  }
108 
116  [[nodiscard]] inline const bone_transform_type& get_relative_transform(bone_index_type index) const
117  {
118  return m_relative_transforms[index];
119  }
120 
128  [[nodiscard]] inline const bone_transform_type& get_absolute_transform(bone_index_type index) const
129  {
130  return m_absolute_transforms[index];
131  }
132 
133 protected:
135  const skeleton* m_skeleton{nullptr};
136 
138  std::vector<bone_transform_type> m_relative_transforms;
139 
141  std::vector<bone_transform_type> m_absolute_transforms;
142 };
143 
144 #endif // ANTKEEPER_ANIMATION_POSE_HPP
std::uint16_t bone_index_type
Bone index type.
Definition: bone.hpp:31
Base class for skeleton poses.
Definition: pose.hpp:32
const skeleton * get_skeleton() const noexcept
Returns the skeleton with which the pose is associated.
Definition: pose.hpp:104
void set_relative_translation(bone_index_type index, const bone_transform_type::vector_type &translation)
Sets the relative translation of a bone pose.
Definition: pose.hpp:76
void set_relative_transform(bone_index_type index, const bone_transform_type &transform)
Sets the relative transform describing a bone pose.
Definition: pose.hpp:65
void set_relative_scale(bone_index_type index, const bone_transform_type::vector_type &scale)
Sets the relative scale of a bone pose.
Definition: pose.hpp:98
void update()
Updates the pose after one or more relative transforms have been changed.
Definition: pose.cpp:31
const skeleton * m_skeleton
Skeleton with which the pose is associated.
Definition: pose.hpp:135
const bone_transform_type & get_relative_transform(bone_index_type index) const
Returns the relative transform describing a bone pose.
Definition: pose.hpp:116
const bone_transform_type & get_absolute_transform(bone_index_type index) const
Returns the absolute transform describing a bone pose.
Definition: pose.hpp:128
void set_relative_rotation(bone_index_type index, const bone_transform_type::quaternion_type &rotation)
Sets the relative rotation of a bone pose.
Definition: pose.hpp:87
constexpr pose() noexcept=default
Constructs an empty pose.
std::vector< bone_transform_type > m_relative_transforms
Relative ransforms for each bone in a skeleton.
Definition: pose.hpp:138
std::vector< bone_transform_type > m_absolute_transforms
Absolute transforms for each bone in a skeleton.
Definition: pose.hpp:141
Skeletal animation skeleton.
Definition: skeleton.hpp:35
quaternion< T > rotation(const vec3< T > &from, const vec3< T > &to, T tolerance=T{1e-6})
Constructs a quaternion representing the minimum rotation from one direction to another direction.
Definition: quaternion.hpp:691
constexpr mat4< T > scale(const vec3< T > &v)
Constructs a scale matrix.
Quaternion composed of a real scalar part and imaginary vector part.
Definition: quaternion.hpp:39
n-dimensional vector.
Definition: vector.hpp:44