Skip to content

Commit

Permalink
Optimize IK bone rotation solving
Browse files Browse the repository at this point in the history
Removed an unnecessary normalization step in the IK bone rotation
calculation to streamline the update process, as the rotation quaternion
is already normalized. Additionally, eliminated the redundant
orthonormalization of the result transform, simplifying the code and
potentially improving performance.
  • Loading branch information
fire committed Jan 19, 2024
1 parent 14a9017 commit 77077df
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/ik_bone_segment_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,9 @@ void IKBoneSegment3D::_set_optimal_rotation(Ref<IKBone3D> p_for_bone, PackedVect
Basis rotation = qcp.weighted_superpose(*r_htip, *r_htarget, *r_weights, p_translate);
Vector3 translation = qcp.get_translation();
double dampening = (p_dampening != -1.0) ? p_dampening : bone_damp;
rotation = clamp_to_quadrance_angle(rotation.get_rotation_quaternion(), cos(dampening / 2.0)).normalized();
rotation = clamp_to_quadrance_angle(rotation.get_rotation_quaternion(), cos(dampening / 2.0));
p_for_bone->get_ik_transform()->rotate_local_with_global(rotation.get_rotation_quaternion());
Transform3D result = Transform3D(p_for_bone->get_global_pose().basis, p_for_bone->get_global_pose().origin + translation);
result.orthonormalize();
p_for_bone->set_global_pose(result);
}
// Calculate orientation before twist to avoid exceeding the twist bound when updating the rotation.
Expand Down

0 comments on commit 77077df

Please sign in to comment.