Viej0
April 18th, 2008, 10:19 AM
Hi. I have a problem simulating the draft of a ball on having rolled on a floor.
well... I use the mesh's quaternion rotation directly to rotate it without having to do transformations with Euler's angles. But a problem happens.
What I do is to obtain the axis of rotation and the angle of rotation to apply on the mesh's quaternion an angle-axis rotated quaternion.
Initially it seems to work, I am applying the rotations like it sees in the code of below, but a moment comes that the rotation becomes mad or something and the sphere already does not roll like it should.
I do not understand which can be the mistake ..: (
Here the code..
// Cross product betweend speed(direction) vector of ball, and plane's normal(0,0,1) to get axis rotation vector
vDir = PointNormalize(speedX,speedY,0.0f);
vAxis = PointCross(vDir.x, vDir.y, 0.0f,
0.0f, 0.0f, 1.0f);
// Normalize the axis rotation vector
vAxis = PointNormalize(vAxis.x,vAxis.y,vAxis.z);
// Len of speed (to give angle of rotation)
len = PointLength(speedX, speedY, 0);
angle = len * 0.022f;
// This function multiply mesh's rotation quaternion by a quaternion angle-axis rotated (with vAxis and angle)
Object_ApplyRotation(this, angle, vAxis.x,vAxis.y,vAxis.z);
Render();
UpdateSpeed();
//The new rotations work during a time.., but many rotations do that the ball rotates of strange forms..!
can anyone help me? thanks!
well... I use the mesh's quaternion rotation directly to rotate it without having to do transformations with Euler's angles. But a problem happens.
What I do is to obtain the axis of rotation and the angle of rotation to apply on the mesh's quaternion an angle-axis rotated quaternion.
Initially it seems to work, I am applying the rotations like it sees in the code of below, but a moment comes that the rotation becomes mad or something and the sphere already does not roll like it should.
I do not understand which can be the mistake ..: (
Here the code..
// Cross product betweend speed(direction) vector of ball, and plane's normal(0,0,1) to get axis rotation vector
vDir = PointNormalize(speedX,speedY,0.0f);
vAxis = PointCross(vDir.x, vDir.y, 0.0f,
0.0f, 0.0f, 1.0f);
// Normalize the axis rotation vector
vAxis = PointNormalize(vAxis.x,vAxis.y,vAxis.z);
// Len of speed (to give angle of rotation)
len = PointLength(speedX, speedY, 0);
angle = len * 0.022f;
// This function multiply mesh's rotation quaternion by a quaternion angle-axis rotated (with vAxis and angle)
Object_ApplyRotation(this, angle, vAxis.x,vAxis.y,vAxis.z);
Render();
UpdateSpeed();
//The new rotations work during a time.., but many rotations do that the ball rotates of strange forms..!
can anyone help me? thanks!