Game Development Community

Bug (feature?): Camera doesn't interpolate rotations correctly

by Matthew Shapiro · in Torque X 2D · 03/25/2008 (7:30 pm) · 4 replies

So, create a new project and create a new T2dSceneCamera. Put a background or some image so that you can notice the direction you turn.

Now, take the new camera, set the rotation to 300. Now do Camera.AnimateRotation(5,1000);.

Notice the camera tries to rotate the long way around.

Is this intended or just an oversight?

#1
03/25/2008 (8:06 pm)
The source code that implements this is really simple. It just takes the current rotation, finds the target rotation, subtracts the angle that it needs to traverse and then divides it out by the amount f time specified. There's no smarts that tells it - hey, its faster to rotate the other way. I wouldn't call it a bug, but it would be nice if there was an extra parameter that lets us specify clockwise or counter-clockwise rotation.

John K.
#2
03/25/2008 (8:51 pm)
Well wouldn't it be better for the engine to figure out the shortest rotation path? Otherwise every time you want to animate the camera's rotation you have to manually figure out which way you need to go, instead of leaving it up to the engine.
#3
03/26/2008 (1:25 pm)
Matt,
Try Camera.AnimateRotation(365,1000), this will rotate the 'correct' direction.

Of course you still have to figure out which is the correct direction first, AFAIK there is no engine method for this.
bool isDestLarger = (TargetRotation > Camera.Rotation) ? true:false;
if (isDestLarger)
     ModifiedTargetRotation = (Math.Abs(TargetRotation - Camera.Rotation) > 180f) ? TargetRotation - (360f + Camera.Rotation) : TargetRotation;
else
     ModifiedTargetRotation = (Math.Abs(TargetRotation - Camera.Rotation) > 180f) ? 360f + TargetRotation : TargetRotation;
Camera.AnimateRotation(ModifiedTargetRotation,1000);
I haven't tested this code so I make no guarantees :)
#4
03/26/2008 (1:46 pm)
Cool thanks, I'll try that out when I get home.

*edit*Yep works. Thanks!