Antkeeper  0.0.1
rest-pose.cpp
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 
22 #include <algorithm>
23 #include <execution>
24 
26  pose(skeleton),
27  m_inverse_absolute_transforms(skeleton.get_bone_count(), bone_transform_type::identity())
28 {}
29 
30 void rest_pose::update(bone_index_type first_index, std::size_t bone_count)
31 {
32  // Update absolute transforms
33  pose::update(first_index, bone_count);
34 
35  // Update inverse absolute transforms
36  std::for_each
37  (
38  // std::execution::par_unseq,
39  std::execution::seq,
40  m_inverse_absolute_transforms.begin() + first_index,
41  m_inverse_absolute_transforms.begin() + (first_index + bone_count),
42  [&](auto& inverse_absolute_transform)
43  {
44  bone_index_type bone_index = static_cast<bone_index_type>(&inverse_absolute_transform - m_inverse_absolute_transforms.data());
45  inverse_absolute_transform = math::inverse(m_absolute_transforms[bone_index]);
46  }
47  );
48 }
49 
51 {
52  if (m_skeleton)
53  {
54  const std::size_t bone_count = m_skeleton->get_bone_count();
55 
56  if (bone_count != m_inverse_absolute_transforms.size())
57  {
58  m_relative_transforms.resize(bone_count);
59  m_absolute_transforms.resize(bone_count);
60  m_inverse_absolute_transforms.resize(bone_count);
61  }
62  }
63 }
std::uint16_t bone_index_type
Bone index type.
Definition: bone.hpp:31
Base class for skeleton poses.
Definition: pose.hpp:32
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
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
void resize()
Updates the number of bones in the rest pose if the skeleton has been modified.
Definition: rest-pose.cpp:50
void update()
Updates the pose after one or more relative transforms have been changed.
Definition: pose.cpp:31
rest_pose() noexcept=default
Constructs an empty rest pose.
Skeletal animation skeleton.
Definition: skeleton.hpp:35
std::size_t get_bone_count() const noexcept
Returns the number of bones in the skeleton.
Definition: skeleton.hpp:148
T identity(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2)
Returns the percent identity between two proteins.
Definition: protein.hpp:63