Skip to content

Commit

Permalink
IK ClipJoint handle scaled bones
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhues committed Dec 17, 2023
1 parent 8879cb1 commit 8b2fe90
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions examples/17_IK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ ae::Vec3 ClipJoint(
{
// @TODO: Assumes j0 is oriented so z is the primary axis

const float b01Len = ( bind0.GetTranslation() - bind1.GetTranslation() ).Length();
const ae::Vec3 b0 = ( j0Inv * ae::Vec4( bind0.GetTranslation(), 1.0f ) ).GetXYZ();
const ae::Vec3 b1 = ( j0Inv * ae::Vec4( bind1.GetTranslation(), 1.0f ) ).GetXYZ();
const float b01Len = ( b0 - b1 ).Length();
const ae::Vec2 j1Flat = [&]()
{
ae::Vec3 p;
Expand Down Expand Up @@ -299,8 +301,8 @@ int main()
const char* anchorBoneName = "QuickRigCharacter_RightShoulder";

ae::Skeleton currentPose = TAG_ALL;
const ae::Matrix4 testJoint0Bind = ae::Matrix4::Translation( 0.0f, 0.0f, 0.0f );// * ae::Matrix4::Scaling( 0.2f );
const ae::Matrix4 testJoint1Bind = ae::Matrix4::Translation( 0.0f, 0.0f, 2.0f );// * ae::Matrix4::Scaling( 0.2f );
const ae::Matrix4 testJoint0Bind = ae::Matrix4::Translation( 0.0f, 0.0f, 0.0f ) * ae::Matrix4::Scaling( 0.2f );
const ae::Matrix4 testJoint1Bind = ae::Matrix4::Translation( 0.0f, 0.0f, 2.0f ) * ae::Matrix4::Scaling( 0.2f );
ae::Matrix4 targetTransform, testJoint0, testJoint1;
auto SetDefault = [&]()
{
Expand Down Expand Up @@ -369,10 +371,15 @@ int main()
ImGui::RadioButton( "Translate", (int*)&gizmoOperation, ImGuizmo::TRANSLATE );
ImGui::SameLine();
ImGui::RadioButton( "Rotate", (int*)&gizmoOperation, ImGuizmo::ROTATE );
ImGui::SameLine();
ImGui::RadioButton( "Scale", (int*)&gizmoOperation, ImGuizmo::SCALE );

ImGui::BeginDisabled( gizmoOperation == ImGuizmo::SCALE );
ImGui::RadioButton( "World", (int*)&gizmoMode, ImGuizmo::WORLD );
ImGui::SameLine();
ImGui::RadioButton( "Local", (int*)&gizmoMode, ImGuizmo::LOCAL );
ImGuizmo::MODE scaleGizmoMode = ImGuizmo::LOCAL;
ImGui::RadioButton( "Local", (int*)( ( gizmoOperation == ImGuizmo::SCALE ) ? &scaleGizmoMode : &gizmoMode ), ImGuizmo::LOCAL );
ImGui::EndDisabled();

ImGui::Separator();

Expand Down Expand Up @@ -414,6 +421,10 @@ int main()
else { gizmoMode = ( gizmoMode == ImGuizmo::WORLD ) ? ImGuizmo::LOCAL : ImGuizmo::WORLD; }
}
if ( input.GetPress( ae::Key::R ) )
{
gizmoOperation = ImGuizmo::SCALE;
}
if ( input.GetPress( ae::Key::Space ) )
{
SetDefault();
}
Expand Down Expand Up @@ -567,7 +578,7 @@ int main()
worldToView.data,
viewToProj.data,
gizmoOperation,
gizmoMode,
( gizmoOperation == ImGuizmo::SCALE ) ? ImGuizmo::LOCAL : gizmoMode,
GetSelectedTransform().data
);

Expand Down

0 comments on commit 8b2fe90

Please sign in to comment.