TwoBoneIK
Two-bone IK solver. Analytical, single-iteration, runs in O(1).
- Module
- Animation
- Header
#include "Animation/IK/TwoBoneIK.h"- Namespace
Mowo
Algorithm (law of cosines on the triangle root-mid-end): 1. Forward-kinematics pass over localTransforms to get world space. 2. Compute current bend angle at mid bone. 3. Compute desired bend angle from target distance via cos rule. 4. Rotate at midBone by Δangle around the chain's plane normal so the chain reaches the target distance. Δangle is current-minus-desired: opening the angle BETWEEN the segments shrinks the interior angle at the joint, so the two run opposite ways. 5. Rotate at rootBone so the end-effector direction points at the target. 6. With a pole hint, swing the solved chain about the root→end axis so the mid joint faces the pole. That axis passes through the effector, so this step cannot pull the end bone off the target it just reached. 7. Optionally override the end bone's rotation (target orientation — e.g. align foot to floor normal, or wrist to a grip).
Outputs are written back into localTransforms for the root, mid, and optionally end bone, preserving each bone's translation + scale.
Public functions
| Returns | Name | Description |
|---|---|---|
void | Solve | Full form. |
void | Solve | Position-only convenience overload — preserves whatever rotation the end bone inherited from the chain after the solve. |
Function details
Solve
static void Solve(const Skeleton& skeleton, const TwoBoneIKChain& chain, const Vec3& targetPos, const Quat& targetRot, std::vector<Mat4>& localTransforms)Full form. targetRot non-identity overrides the end bone's world rotation. localTransforms.size() must == skeleton.GetBoneCount().
Solve
static void Solve(const Skeleton& skeleton, const TwoBoneIKChain& chain, const Vec3& targetPos, std::vector<Mat4>& localTransforms)Position-only convenience overload — preserves whatever rotation the end bone inherited from the chain after the solve.