Antkeeper  0.0.1
ik-rig.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_IK_RIG_HPP
21 #define ANTKEEPER_ANIMATION_IK_RIG_HPP
22 
26 #include <memory>
27 #include <vector>
28 
32 class ik_rig
33 {
34 public:
40  explicit ik_rig(scene::skeletal_mesh& skeletal_mesh);
41 
44  [[nodiscard]] inline const scene::skeletal_mesh& get_skeletal_mesh() const noexcept
45  {
46  return *m_skeletal_mesh;
47  }
48  [[nodiscard]] inline scene::skeletal_mesh& get_skeletal_mesh() noexcept
49  {
50  return *m_skeletal_mesh;
51  }
53 
56 
63  void set_constraint(bone_index_type index, std::shared_ptr<ik_constraint> constraint);
64 
66  void clear_constraints();
67 
76  [[nodiscard]] inline const ik_constraint* get_constraint(bone_index_type index) const
77  {
78  return m_constraints[index].get();
79  }
80  [[nodiscard]] inline ik_constraint* get_constraint(bone_index_type index)
81  {
82  return m_constraints[index].get();
83  }
85 
87 
90 
94  void solve();
95 
101  void add_solver(std::shared_ptr<ik_solver> solver);
102 
106  void remove_solvers();
107 
109 
110 private:
111  scene::skeletal_mesh* m_skeletal_mesh{nullptr};
112  std::vector<std::shared_ptr<ik_constraint>> m_constraints;
113  std::vector<std::shared_ptr<ik_solver>> m_solvers;
114 };
115 
116 #endif // ANTKEEPER_ANIMATION_IK_RIG_HPP
std::uint16_t bone_index_type
Bone index type.
Definition: bone.hpp:31
Abstract base class for IK joint constraints.
scene::skeletal_mesh & get_skeletal_mesh() noexcept
Returns the skeleton with which the IK rig is associated.
Definition: ik-rig.hpp:48
void clear_constraints()
Removes all constraints from the IK rig.
Definition: ik-rig.cpp:32
void remove_solvers()
Removes all solvers from the IK rig.
Definition: ik-rig.cpp:53
ik_constraint * get_constraint(bone_index_type index)
Sets the IK constraint of a bone.
Definition: ik-rig.hpp:80
const ik_constraint * get_constraint(bone_index_type index) const
Returns the IK constraint of a bone.
Definition: ik-rig.hpp:76
const scene::skeletal_mesh & get_skeletal_mesh() const noexcept
Returns the skeleton with which the IK rig is associated.
Definition: ik-rig.hpp:44
void add_solver(std::shared_ptr< ik_solver > solver)
Adds a solver to the IK rig.
Definition: ik-rig.cpp:48
void solve()
Solves each solver in the IK rig.
Definition: ik-rig.cpp:40
void set_constraint(bone_index_type index, std::shared_ptr< ik_constraint > constraint)
Sets the IK constraint of a bone.
Definition: ik-rig.cpp:27
ik_rig(scene::skeletal_mesh &skeletal_mesh)
Constructs an IK rig.
Definition: ik-rig.cpp:22