Antkeeper  0.0.1
ccd-ik-solver.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_CCD_IK_SOLVER_HPP
21 #define ANTKEEPER_ANIMATION_CCD_IK_SOLVER_HPP
22 
25 #include <vector>
26 
27 class ik_rig;
28 
32 class ccd_ik_solver: public ik_solver
33 {
34 public:
43  ccd_ik_solver(ik_rig& ik_rig, bone_index_type root_bone_index, bone_index_type effector_bone_index);
44 
47 
48  void solve() override;
49 
55  inline void set_max_iterations(std::size_t iterations) noexcept
56  {
57  m_max_iterations = iterations;
58  }
59 
61  [[nodiscard]] inline std::size_t get_max_iterations() const noexcept
62  {
63  return m_max_iterations;
64  }
65 
67 
70 
76  inline void set_effector_position(const math::fvec3& position) noexcept
77  {
78  m_effector_position = position;
79  }
80 
82  [[nodiscard]] inline const math::fvec3& get_effector_position() const
83  {
84  return m_effector_position;
85  }
86 
88 
91 
97  inline void set_goal_center(const math::fvec3& center) noexcept
98  {
99  m_goal_center = center;
100  }
101 
107  inline void set_goal_radius(float radius) noexcept
108  {
109  m_sqr_goal_radius = radius * radius;
110  }
111 
113  [[nodiscard]] inline const math::fvec3& get_goal_center() const
114  {
115  return m_goal_center;
116  }
117 
119 
120 private:
121  ik_rig* m_ik_rig{nullptr};
122  std::size_t m_max_iterations{10};
123  std::vector<bone_index_type> m_bone_indices;
124  math::fvec3 m_effector_position{0.0f, 0.0f, 0.0f};
125  math::fvec3 m_goal_center{0.0f, 0.0f, 0.0f};
126  float m_sqr_goal_radius{1e-5f};
127 };
128 
129 #endif // ANTKEEPER_ANIMATION_CCD_IK_SOLVER_HPP
std::uint16_t bone_index_type
Bone index type.
Definition: bone.hpp:31
Cyclic Coordinate Descent (CCD) IK solver.
ccd_ik_solver(ik_rig &ik_rig, bone_index_type root_bone_index, bone_index_type effector_bone_index)
Constructs a CCD IK solver.
void solve() override
Sets the maximum number of solving iterations.
const math::fvec3 & get_effector_position() const
Returns the position of the end effector, relative to the tip bone.
void set_goal_center(const math::fvec3 &center) noexcept
Sets the center of the IK goal.
const math::fvec3 & get_goal_center() const
Returns the center of the IK goal, in world-space.
std::size_t get_max_iterations() const noexcept
Returns the maximum number of solving iterations.
void set_max_iterations(std::size_t iterations) noexcept
Sets the maximum number of solving iterations.
void set_goal_radius(float radius) noexcept
Sets the radius of the IK goal.
void set_effector_position(const math::fvec3 &position) noexcept
Sets the position of the end effector.
Abstract base class for IK solvers.
Definition: ik-solver.hpp:27
n-dimensional vector.
Definition: vector.hpp:44