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);
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());
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);
So I'd like to understand what exactly setRotation does and why does my above tentatives not work.
Thanks for your help!