Proper Scenenode Rotation?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
the_viking
Posts: 23
Joined: Fri Aug 06, 2004 12:28 pm

Proper Scenenode Rotation?

Post by the_viking »

Hi there,

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;
}
Calls to the rotate function are made as following:

Code: Select all

	pObject->rotate(core::vector3df(0,45.f,0),mfDeltaTime);
But when rotating the object, I does not only rotate on the right axes, i does also rotate so fast i can't figure out how it rotates really...

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... )
Guest

Post by Guest »

I'm not sure about this - because not everything Irrlicht is documented as well as I'd like, but maybe the rotation needs to be entered in radians instead of degrees?

(PI radians = 180 degrees)
the_viking
Posts: 23
Joined: Fri Aug 06, 2004 12:28 pm

Post by the_viking »

Well, you're right, that was the reason for the ultra-fast rotations ^^
Thanks, didn't looked properly into the quaternion source...

But the flipping isn't gone... so my main problem is still there.. :(

\E:
The class cObject has a scene node as a member object, but the facing of the scennode is stored for networking purposes as a Directional vector in the cObject class. Conversion to a rotation is done before drawing, so that's not the problem, i know that the conversion from the direction to the rotation works fine.
T101
Posts: 44
Joined: Thu Jul 29, 2004 4:41 pm

Post by T101 »

No, it's not OK to convert back and forth between a vector and a rotation.

Look at the folowing two situations:

Code: Select all

    /     \
   /       \
  /         \
 /           \
/____     ____\
Both seen from the same crosssection.
What's the difference between the one on the left and the one on the right?
1. yaw (angle in the ground plane) is rotated over 180 degrees
2. pitch (angle to the ground) is rotated over 90 degrees

Which is it? No way to tell from the vector. Since there is no roll in a direction vector.
You either need to simply store the angles and after those change, modify the vectors/matrix, or you need to store two vectors: one additional at right angles, e.g. an upvector.

Personally, I'd replicate a rotation - just three floats instead of six.

If you do something like you say you're doing now, chances are that pitch will always be between +90 and -90 degrees, and yaw will be between -180 and +180 degrees (or between 0 and 360).
the_viking
Posts: 23
Joined: Fri Aug 06, 2004 12:28 pm

Post by the_viking »

Yeah, i saw by myself the Idea with the direction vector is not the best solution :)

So now i use a rotation vector and i convert it to a direction vector when my objects should move to a direction

Thanx everyone!
Post Reply