This a really simple question… but I couldn’t manage to get the math equations right.
I managed to write the code to rotate the camera around the y-axis (looking left and right).
However, I cant make my camera to rotate around the x-axis (like if i was looking up and down with my camera).
void Camera::RS_Camera_RotateSideWays(float speed)
{
//vVector = View - Pos; // Get the view vector
Vec3 vVector = Camera->View -Camera->Pos; // Get the view vector
Camera->View.z = (float)(Camera->Pos.z + SINE(speed)*vVector.x + COSINE(speed)*vVector.z);
Camera->View.x = (float)(Camera->Pos.x + COSINE(speed)*vVector.x - SINE(speed)*vVector.z);
}
So I tried this but it doesn’t work as intended:
void Camera::RS_Camera_RotateVertical(float speed)
{
//vVector = View - Pos; // Get the view vector
Vec3 vVector = Camera->View -Camera->Pos; // Get the view vector
Camera->View.y = (float)(Camera->Pos.y + SINE(speed)*vVector.x + COSINE(speed)*vVector.y);
Camera->View.x = (float)(Camera->Pos.x + COSINE(speed)*vVector.x - SINE(speed)*vVector.y);
}
Could anybody correct me?!
Thanks so much in advance,
Rod
Yes… I considered using matrices, but I read in SIGGRAPH course 2001 Advanced Rendering Techniques that using glLoadMatrix produces a performance drop in contrast to OpenGL glRotate, glTranslate, glScale.
void Camera::RS_Camera_RotateVertical(float speed)
{
//vVector = View - Pos; // Get the view vector
Vec3 vVector = Camera->View -Camera->Pos; // Get the view vector
LookAt->Orientation_Now.z = (float)(LookAt->Position_Now.z + SINE(speed)*vVector.y + COSINE(speed)*vVector.z);
LookAt->Orientation_Now.y = (float)(LookAt->Position_Now.y + COSINE(speed)*vVector.y - SINE(speed)*vVector.z);
}
You are right, x shouldn’t be included…but I tried this one and I am still getting it wrong… I am kind of lost with this math actually…
Any tips?!
If no one know the answer, could you atleast point me to a camera tutorial that uses glLookAt?!
Thanks so much in advance, I would really appreciate it.
Rod
What’s the error you are getting? Your code looks correct now, so it should work.
I’m not really sure about the meaning of your variables. You read from Camera->View and Camera->Pos, but you write LookAt->Orientation_Now and LookAt->Position_Now. Do you write the values back into Camera at some point?
but I read in SIGGRAPH course 2001 Advanced Rendering Techniques that using glLoadMatrix produces a performance drop in contrast to OpenGL glRotate, glTranslate, glScale
I doubt that. Especially because you won’t load the camera matrix very often per frame
no one knows?!
Please any tips would be welcome, i really want to make this work and I can’t find info anywhere on doing camera rotations of this type with glulookat.
If you want you could search for “gluLookAt implementation” on google. Software “drivers” like MesaGL have implementations that emulate the behaviour of GLUT. Just a thought if you don’t want to have GLUT as a dependency in your code…