In the project I am currently working on ( a 3D space-shooter ), the Objects should be able to rotate freely in 3D. As i tried to rotate them with Matrices, the Objects are flipping around when encountering the upside-down position. As i searched in this forum, I hear quaternions would help, but i didn't got them to work. This is my code to rotate a Object in the game:
Code: Select all
void cObject::rotate(core::vector3df& vAngles, float fDeltaTime)
{
// make rotation vector from direction
core::vector3df vRot = getTargetAngle(mvNetDirectionF);
// add new rotation
vRot += vAngles * fDeltaTime;
// Build quaternion
core::quaternion qOriginal(vRot.X,vRot.Y,vRot.Z);
// Calculate new direction
core::vector3df Target(0,0,1);
Target = qOriginal * Target;
// update direction
mvNetDirectionF = Target;
}
Code: Select all
pObject->rotate(core::vector3df(0,45.f,0),mfDeltaTime);
Can anyone help me as this is a really simple task, I just don't know how to use the quaternions properly
( As said, if I am using matrices instead of the quaternion there, it rotates, but there is this flip-over... )