FashGek / hotween

Automatically exported from code.google.com/p/hotween
0 stars 0 forks source link

PlugQuaternion Bug #34

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,
PlugQuaternion doesn't work properly with finding Shortest rotation.
I just made a patch. Hope this will be on next release. 
thanks.

Index: PlugQuaternion.cs
===================================================================
--- PlugQuaternion.cs   (revision 229)
+++ PlugQuaternion.cs   (working copy)
@@ -256,8 +256,11 @@
             if (isRelative && !tweenObj.isFrom)
             {
                 changeVal = typedEndVal;
-                return;
             }
+            else
+            {
+                changeVal = typedEndVal - typedStartVal;
+            }

             if (beyond360)
             {
@@ -265,20 +268,18 @@
                 return;
             }

-            Vector3 ev = typedEndVal;
-            if (ev.x > 360)
+            if (changeVal.x > 360)
             {
-                ev.x = ev.x % 360;
+                changeVal.x = changeVal.x % 360;
             }
-            if (ev.y > 360)
+            if (changeVal.y > 360)
             {
-                ev.y = ev.y % 360;
+                changeVal.y = changeVal.y % 360;
             }
-            if (ev.z > 360)
+            if (changeVal.z > 360)
             {
-                ev.z = ev.z % 360;
+                changeVal.z = changeVal.z % 360;
             }
-            changeVal = ev - typedStartVal;

             // Find shortest rotation
             float abs = (changeVal.x > 0 ? changeVal.x : -changeVal.x);

Original issue reported on code.google.com by amug...@gmail.com on 24 Jul 2012 at 6:19

GoogleCodeExporter commented 9 years ago
Thanks amugana for patching it. Before applying the patch though, could you 
send me an example of a case where HOTween fails to apply the shortest 
rotation? I can't replicate it here, and I want to be sure we have the same 
thing in mind :)

Original comment by daniele....@gmail.com on 24 Jul 2012 at 9:32

GoogleCodeExporter commented 9 years ago

Original comment by daniele....@gmail.com on 24 Jul 2012 at 9:32

GoogleCodeExporter commented 9 years ago
i just checked the case.

When relative is 'on' rotation from '0' to '270' runs whole 270 degree

HOTween.To( transform, 0.5f, new TweenParms().Prop("localRotation", 
Quaternion.Euler(0,0,-90), true));

Original comment by amug...@gmail.com on 24 Jul 2012 at 1:56

GoogleCodeExporter commented 9 years ago
I see. Then everything is correct, actually. Quaternions can't be negative, so 
converting 0,0,-90 to a Quaternion actually creates a Quaternion of 0,0,270 
(you can see it if you Log Quaternion.Euler(0,0,-90).eulerAngles), which in 
case of a relative rotation tween, correctly rotates the object by 270 degrees.

You can instead directly use Vector3 values for rotation tweens, like:
HOTween.To( transform, 0.5f, new TweenParms().Prop("localRotation", new 
Vector3(0,0,-90), true));
which will correctly rotate your object by 90 degrees.

Original comment by daniele....@gmail.com on 24 Jul 2012 at 7:35

GoogleCodeExporter commented 9 years ago
oh my. didn't know that. thanks :)

Original comment by amug...@gmail.com on 24 Jul 2012 at 11:15

GoogleCodeExporter commented 9 years ago
Thanks to you. Even if in the end we found this issue was not an issue, I 
appreciated enormously that you included a patch :)

Original comment by daniele....@gmail.com on 25 Jul 2012 at 9:01