Rotation problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Dr_Asik
Posts: 18
Joined: Wed Jun 02, 2010 2:15 am

Rotation problem

Post by Dr_Asik »

I'd like to understand how the rotation of a node works in Irrlicht.

What I'm trying to model is a billiards cue stick. It should always point towards the ball, but the user can rotate it around in sort of a hemisphere.

The cue stick's reference point is its tip, the tip that hits the ball. So I've got some code to place it based on spherical coordinates.

I must specify that the up vector in our world is (0, 0, 1).

Code: Select all

// spherical coordinates
float m_cueDistance = 5; // distance between cue and ball
float m_thetaY = 0; // angle between cue stick orientation and Y axis
float m_thetaZ = PI / 2; // angle between cue stick orientation and Z axis

Code: Select all

// update position based on new values of coordinates
float sinThetaZ = sin(m_thetaZ);
vector3df position(cos(m_thetaY) * sinThetaZ, sin(m_thetaY) * sinThetaZ, cos(m_thetaZ));
position *= m_cueDistance;
cueStickNode->setPosition(position);
This code does work well. Now, the rotation of the cue stick must be ajusted accordingly, and this is where I have stumbled.

I have read that to make an object face another one, I could matrix4::buildCameraLookAtMatrixLH. So here is my tentative to use that:

Code: Select all

matrix4 lookAt;
lookAt.buildCameraLookAtMatrixLH(position, ballPosition, vector3df(0, 0, 1));
cueStickNode->setRotation(lookAt.getRotationDegrees());
That did not work all, the rotation was anything but what I wanted.

So then I tried to understand what setRotation did. My best guess (because I did not find any documentation about that anywhere), is that it takes three angles in degrees, each representing the angle between the object's orientation and the respective axis. So to test that hypothesis, I wrote the following code:

Code: Select all

cueStickNode->setRotation(RADTODEG * m_thetaY + (PI / 2.0f), RADTODEG * m_thetaY, RADTODEG * m_thetaZ);
But again, this did not lead to the expected result.

So I'd like to understand what exactly setRotation does and why does my above tentatives not work.

Thanks for your help!
Post Reply