Antkeeper  0.0.1
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  m_skeleton(&skeleton),
27  m_relative_transforms(skeleton.get_bone_count(), bone_transform_type::identity()),
28  m_absolute_transforms(skeleton.get_bone_count(), bone_transform_type::identity())
29 {}
30 
32 {
33  update(0, m_absolute_transforms.size());
34 }
35 
36 void pose::update(bone_index_type first_index, std::size_t bone_count)
37 {
38  bone_index_type child_index = first_index;
39 
40  std::for_each
41  (
42  std::execution::seq,
43  m_absolute_transforms.begin() + first_index,
44  m_absolute_transforms.begin() + (first_index + bone_count),
45  [&](auto& child_absolute_transform)
46  {
47  const bone_index_type parent_index = m_skeleton->get_bone_parent(child_index);
48 
49  if (parent_index != child_index)
50  {
51  child_absolute_transform = m_absolute_transforms[parent_index] * m_relative_transforms[child_index];
52  }
53  else
54  {
55  child_absolute_transform = m_relative_transforms[child_index];
56  }
57 
58  ++child_index;
59  }
60  );
61 }
std::uint16_t bone_index_type
Bone index type.
Definition: bone.hpp:31
void update()
Updates the pose after one or more relative transforms have been changed.
Definition: pose.cpp:31
constexpr pose() noexcept=default
Constructs an empty pose.
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
T identity(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2)
Returns the percent identity between two proteins.
Definition: protein.hpp:63