Pitch and Yaw methods in Camera Class
For my OpenGl final year project and Graphics coursework i''m using a Camera Class for position movements. I have used the F.S Hill Book as a startin point for creating the Camera class.
At the moment ive got the ''Slide'' and ''roll'' movements working fine..
The roll is calculated as:-
void Camera::roll(float angle) {
//rolls the camera through angles
float cs = cos(3.14159265/180 * angle);
float sn = sin(3.14159265/180 * angle);
Vector3 t = u; //remember the value of old U
u.set(cs*t.x - sn*v.x, cs*t.y - sn*v.y, cs*t.z - sn*v.z);
v.set(sn*t.x + cs*v.x, sn*t.y + cs*v.y, sn*t.z + cs*v.z);
setModelViewMatrix();
}
I know that the pitch and roll will be similar to this taking in an angle. i also know that i have to edit the u.set and v.set parts to adjust for the different movements but i havent been able to find anything on t''internet for the way to calculate the new yaw and pitch using an angle.
Any ideas on how i calculate a yaw or/and pitch movement ?
Thanks!
I think you should use quaternions: here on Nehe there should be a tutorial or an article about it.
Thanks for the reply. I''m not sure i really want to look at using Quaternions, I havent really got much time left to implement the project... and eveything else works fine.
its just i need the maths to work out the new coords using a angle and the current positions, Then i can add this maths to the pitch and yaw methods. Im sure these would take no time putting in once i had the actual maths.. Though maybe im being dumb!:-) (Im guessing there just differing versions of the roll method).
thanks
Simon
its just i need the maths to work out the new coords using a angle and the current positions, Then i can add this maths to the pitch and yaw methods. Im sure these would take no time putting in once i had the actual maths.. Though maybe im being dumb!:-) (Im guessing there just differing versions of the roll method).
thanks
Simon
March 03, 2004 12:14 AM
I work at Boeing in the flight sim dept & just wanna suggest that you always apply heading, pitch, & roll to the model matrix in THAT ORDER ( h.p.r. )
so a good way to do it would be to calculate heading, apply it, then calculate pitch, apply IT, & then it never really matters what the other 2 are... roll is always calculated the same... just rotate around the current Z-axis after the other 2 angles have been applied. good luck man.
so a good way to do it would be to calculate heading, apply it, then calculate pitch, apply IT, & then it never really matters what the other 2 are... roll is always calculated the same... just rotate around the current Z-axis after the other 2 angles have been applied. good luck man.
What would you know?
Anyway, I would help better than this but I''m in a hurry, I''m pretty sure you''re doing the above thing wrong as shouldn''t you be rotating around the view vector?
Pitch you just rotate around the dot product of the up (view - position) vectors and yaw you just rotate around the up vector.
Quaternions would be easier I must say, just take a few hours to learn the basics about applying them (don''t try to learn the maths with such short a time
just pretend you know they''re true!) and apply them with the rotation vectors above.
Anyway can anyone give code for this? I have to go.
Anyway, I would help better than this but I''m in a hurry, I''m pretty sure you''re doing the above thing wrong as shouldn''t you be rotating around the view vector?
Pitch you just rotate around the dot product of the up (view - position) vectors and yaw you just rotate around the up vector.
Quaternions would be easier I must say, just take a few hours to learn the basics about applying them (don''t try to learn the maths with such short a time

Anyway can anyone give code for this? I have to go.
The Love Of Trees
thanks for the help guys. I managed to sort it a few minutes ago.. ive done it like this.
void Camera:: rotAxes(Vector3& a, Vector3& b, float angle) { // rotate orthogonal vectors a (like x axis) and b(like y axia) through angle degrees
float ang = 3.14159265/180*angle;
float C = cos(ang), S = sin(ang);
Vector3 t(C * a.x + S * b.x, C * a.y + S * b.y, C * a.z + S * b.z); b.set(-S * a.x + C * b.x, -S * a.y + C * b.y,
-S * a.z + C * b.z);
a.set(t.x, t.y, t.z); // put tmp into a''
}
void Camera::roll(float angle) {
rotAxes(u, v, -angle);
setModelViewMatrix();
}
void Camera:
itch(float angle) {
rotAxes(v, n, angle);
setModelViewMatrix();
}
void Camera::yaw(float angle) {
//yaws the camera through angles
rotAxes(u, n, angle);
setModelViewMatrix();
}
Seems to be working fine now and moving correctly. It probably isnt the best way of doing it, but it does work so happy about if for now. i will look at quaternions at some point soon.
Thanks again!
void Camera:: rotAxes(Vector3& a, Vector3& b, float angle) { // rotate orthogonal vectors a (like x axis) and b(like y axia) through angle degrees
float ang = 3.14159265/180*angle;
float C = cos(ang), S = sin(ang);
Vector3 t(C * a.x + S * b.x, C * a.y + S * b.y, C * a.z + S * b.z); b.set(-S * a.x + C * b.x, -S * a.y + C * b.y,
-S * a.z + C * b.z);
a.set(t.x, t.y, t.z); // put tmp into a''
}
void Camera::roll(float angle) {
rotAxes(u, v, -angle);
setModelViewMatrix();
}
void Camera:

rotAxes(v, n, angle);
setModelViewMatrix();
}
void Camera::yaw(float angle) {
//yaws the camera through angles
rotAxes(u, n, angle);
setModelViewMatrix();
}
Seems to be working fine now and moving correctly. It probably isnt the best way of doing it, but it does work so happy about if for now. i will look at quaternions at some point soon.
Thanks again!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement