Camera roation animation problem.

Problems building or running the engine, queries about how to use features etc.
User avatar
y721
Gremlin
Posts: 153
Joined: Mon Nov 08, 2004 3:15 am
Location: Taiwan

Camera roation animation problem.

Post by y721 »

Hi:

I try to rotate camera with animation. The camera does extra rotation when animation around angle -180 and 0 degree.

here is my code..

pAnim->setInterpolationMode (Animation::IM_SPLINE);

KeyFrame* key = pTrack->createKeyFrame(0); // startposition
key->setTranslate (pNode->getPosition ());
key->setRotation (pNode->getOrientation ());

// last frame
key = pTrack->createKeyFrame (fAnimLen);
key->setTranslate (pos);

// rotate axis = Y, angle = lookAt - pos on x-z plane
Vector3 dir = lookAt - pos;
float angle = atan2 (dir.x, dir.z) - Math::PI; // Camera point neg. z

Quaternion q (Radian (angle), Vector3::UNIT_Y);
key->setRotation (q);


My camera's up vector is the same with Y axis.
I checked the forum that this problem is supposed to be fixed, right?

I also try the following code

if (angle > Math::PI)
angle -= 2*Math::PI;
else if (angle < -Math::PI)
angle += 2*Math::PI;

But the problem only fixed partially.

Can anyone help? Thank you.
User avatar
PeterNewman
Greenskin
Posts: 128
Joined: Mon Jun 21, 2004 2:34 am
Location: Victoria, Australia

Post by PeterNewman »

I -think- that what can happen is the rotation math's doesn't know that -180 == 180, so rather then continuing rotating in the same direction, it'll figure it has to spin from 180 to -180, going through 0.

Had that happen to us, anyway.