Skip to content

Commit

Permalink
Refactor clamp_to_cos_angle to clamp_to_cos_half_angle
Browse files Browse the repository at this point in the history
  • Loading branch information
fire committed Apr 7, 2024
1 parent e82006c commit 6ab7915
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/ik_bone_segment_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void IKBoneSegment3D::_update_optimal_rotation(Ref<IKBone3D> p_for_bone, double
_set_optimal_rotation(p_for_bone, &tip_headings, &target_headings, &heading_weights, p_damp, p_translate, p_constraint_mode);
}

Quaternion IKBoneSegment3D::clamp_to_cos_angle(Quaternion p_quat, double p_cos_half_angle) {
Quaternion IKBoneSegment3D::clamp_to_cos_half_angle(Quaternion p_quat, double p_cos_half_angle) {
if (p_quat.w < 0.0) {
p_quat = p_quat * -1;
}
Expand Down Expand Up @@ -163,7 +163,7 @@ 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_cos_angle(rotation.get_rotation_quaternion(), cos(dampening / 2.0));
rotation = clamp_to_cos_half_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);
p_for_bone->set_global_pose(result);
Expand Down
2 changes: 1 addition & 1 deletion src/ik_bone_segment_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class IKBoneSegment3D : public Resource {
public:
const double evec_prec = static_cast<double>(1E-6);
void update_pinned_list(Vector<Vector<double>> &r_weights);
static Quaternion clamp_to_cos_angle(Quaternion p_quat, double p_cos_half_angle);
static Quaternion clamp_to_cos_half_angle(Quaternion p_quat, double p_cos_half_angle);
static void recursive_create_headings_arrays_for(Ref<IKBoneSegment3D> p_bone_segment);
void create_headings_arrays();
void recursive_create_penalty_array(Ref<IKBoneSegment3D> p_bone_segment, Vector<Vector<double>> &r_penalty_array, Vector<Ref<IKBone3D>> &r_pinned_bones, double p_falloff);
Expand Down
2 changes: 1 addition & 1 deletion src/ik_kusudama_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void IKKusudama3D::set_snap_to_twist_limit(Ref<IKNode3D> p_bone_direction, Ref<I
Basis align_rot = (global_twist_center.inverse() * global_transform_to_set.basis).orthonormalized();
Quaternion twist_rotation, swing_rotation; // Hold the ik transform's decomposed swing and twist away from global_twist_centers's global basis.
get_swing_twist(align_rot.get_rotation_quaternion(), Vector3(0, 1, 0), swing_rotation, twist_rotation);
twist_rotation = IKBoneSegment3D::clamp_to_cos_angle(twist_rotation, twist_half_range_half_cos);
twist_rotation = IKBoneSegment3D::clamp_to_cos_half_angle(twist_rotation, twist_half_range_half_cos);
Basis recomposition = (global_twist_center * (swing_rotation * twist_rotation)).orthonormalized();
Basis rotation = parent_global_inverse * recomposition;
p_to_set->set_transform(Transform3D(rotation, p_to_set->get_transform().origin));
Expand Down

0 comments on commit 6ab7915

Please sign in to comment.