Skip to content

Commit

Permalink
Fix bug with snap rotation on rotated canvas. (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
andybak authored Jul 26, 2023
1 parent 98c7817 commit 6bfa2fe
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Assets/Scripts/Widgets/GrabWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,13 +1235,14 @@ virtual protected TrTransform GetSnappedTransform(TrTransform xf_GS)

if (SelectionManager.m_Instance.CurrentSnapAngleIndex != 0)
{
// Calculate the nearest snap angle
var rot_CS = xf_GS.rotation * App.Scene.Pose.rotation.TrueInverse();
Quaternion nearestSnapRotation_CS = QuantizeAngle(rot_CS);

// Decide whether to snap to the old or the new snap angle
float snapAngle = SelectionManager.m_Instance.SnappingAngle;
float stickiness = m_ValidSnapRotationStickyAngle / 90f;
float stickyAngle = snapAngle * stickiness;

if (nearestSnapRotation_CS != m_PrevSnapRotation)
{
float a = Quaternion.Angle(xf_GS.rotation, App.Scene.Pose.rotation * m_PrevSnapRotation);
Expand All @@ -1251,7 +1252,9 @@ virtual protected TrTransform GetSnappedTransform(TrTransform xf_GS)
}
}

outXf_GS.rotation = App.Scene.Pose.rotation * m_PrevSnapRotation;
// Apply the resulting change in rotation to the original transform
var rotationDelta = m_PrevSnapRotation * Quaternion.Inverse(rot_CS);
outXf_GS.rotation = rotationDelta * outXf_GS.rotation;

Quaternion qDelta = outXf_GS.rotation * Quaternion.Inverse(xf_GS.rotation);
Vector3 grabSpot = InputManager.m_Instance.GetControllerPosition(m_InteractingController);
Expand Down

0 comments on commit 6bfa2fe

Please sign in to comment.