Yaw, pitch, roll camera
Yaw, pitch and roll is a way of describing the rotation of the camera in 3D. There is other ways like quaternions but this is the simplest. Yaw, pitch and roll is the name of how much we should rotate around each axis.
Yaw, pitch and roll[edit]
Think about yourself as the camera right now. Look around a bit. Yaw is the angle when moving the head left ↔ right (rotation around Y-axis). Pitch is up and down (rotation around X-axis). Roll, which we usually don't experience is when you tilt your head (rotation around Z-axis).
This can be a bit confusing at start but you get used to it. Depending on the application we might omit roll. In a typical FPS we can, but a flight simulator would strange if the camera can't roll.
Also, yaw might sometimes be refered to as heading, but it's the same thing.
Basic camera (omitting roll)[edit]
- class Camera{
- public:
- void view();
- void motion(int x,int y);
- protected:
- Vector3 pos;
- Vector3 target;
- GLfloat phi;
- GLfloat theta;
- };
- void Camera::motion(int x,int y){
- theta+= x / 200; /* Adjust this to control the sensitivity */
- phi+= y / 200;
- target.x = cos(theta) * sin(phi);
- target.y = cos(phi);
- target.z = sin(theta) * sin(phi);
- }
- void Camera::view(){
- gluLookAt (pos.x,pos.y,pos.z,
- pos.x + target.x,
- pos.y + target.y,
- pos.z + target.z,
- 0,1,0
- );
- }
I won't explain the formula used to convert the angles to a vector, use it if you want. It works in this case. When you move the mouse call the motion method with dx and dy.