Advertisement

Rotation due to movement

Started by June 22, 2003 06:18 AM
3 comments, last by DirectXXX 21 years, 8 months ago
I have a 3d ball moving in a Ground of normal upward. I wanted its rotation due to velocity. So i used this trick. // Normalizing Velocity D3DXVec3Normalize(&VelocityNormal, &vVelocity); Taking Croos of GroundNormal and VelNormal D3DXVec3Cross(&vRotationAxis, &TableBaseNormal, VelocityNormal); // using formula theta = arclength/radius sAngle += D3DXVec3Length(&vVelocity)/BallRadius; But a jump in rotation ocures when velocity goes instantly reverse afer collidion. Means the resultant of cross product goes negative. Rotation works fine but the Jumping is problem. Did you understand what i mean. [edited by - DirectXXX on June 22, 2003 5:38:59 PM]
3D Side-Scroller game demo Project-X2 "playable"Lashkar: A 3D Game & Simulation Project demo @ lashkar.berlios.de
It seems correct to me. If the ball collides and starts moving in the opposite direction, then it should rotate in the opposite direction, too.

Maybe the amount of rotation is wrong because amount of movement is not the same as the velocity when there is a collision.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Advertisement
It looks like you are storing sAngle and vRotationAxis, and then frame by frame creating a world matrix based on those.

If you are then that is where your problem lies. When vRotationAxis changes direction, for example by pointing in reverse, sAngle becomes wrong, because that is still a rotation around the original axis.

You need to adjust sAngle with some complex maths whenever you change the rotation axis. Fortunately this maths is pre-done: quaternions. These are also just a rotation axis and angle (effectively) so it would be better to work with those and use the functions/macros to control rotation.
Of course, if you are not too hot on quaternions, you could still just use a rotation matrix. This would be what I would do, as I have still not got fully to grips with quaternions.

If you aren''t making that mistake then I have no idea. Your formula theta = arclength/radius looks a bit suspect. That only works for small angles, so I suppose there could be a problem there.
Yes i have access to some quaternion funcs too

D3DXQuaternionRotationAxis.

I will better try with them.

Also i tried to use yaw, pitch, roll. Sperately the all work fine in one direction But unexpected rotation happened. I think it is GimbleLock.
3D Side-Scroller game demo Project-X2 "playable"Lashkar: A 3D Game & Simulation Project demo @ lashkar.berlios.de
Don''t use Yaw/Pitch/Roll. Use a rotation axis instead. Keep a quaternion of the current orientation of the object, then at each frame, find the speed at which the ball is moving.

angular_velocity = velocity / radius

Your way of calculating the axis is right. You shouldn''t assume that the time step is always 1, so that''s why you should evaluate the angular_velocity before evaluating delta_theta, which is just:

delta_theta = angular_velocity * time_step.

Then, rotate your current rotation quaternion by delta_theta around the rotation axis.

Cédric

This topic is closed to new replies.

Advertisement