Camera

Started by
-1 comments, last by danne89 18 years, 11 months ago
Hi! I'm trying to make a camera. Can anyone point out what I'm doing wrong. It's perhaps more math then programming. I want to move in the direction v = [0, 0, S, 0], in local coordinates for the camera. Then I need to rotate that vector so I get it in global coordinates. The angles I want to rotate with is yaw, pitch and roll. Say my rotation matrix is M. Then I get Mv = [Sm13, Sm23, Sm33, Sm43]. So I only need to care about the third row in the matrix. I should multiply the seperate matricies in the order Yaw * Pitch * Roll. Then I get: m13 = sin Yaw * cos Roll + cos Yaw * sin Roll * sin Pitch m23 = cos Yaw * cos Roll * sin Pitch - sin Yaw * sin Roll m33 = cos Yaw * cos Pitch m43 = 0 My code which is trying to do this:
void movePlane(float secsPerFrame)
{
    GLdouble m13, m23, m33;
    m13 = sin(camera.heading) * cos(camera.roll) + cos(camera.heading) * sin(camera.roll) * sin(camera.pitch);
    m23 = cos(camera.heading) * cos(camera.roll) * sin(camera.pitch) - sin(camera.heading) * sin (camera.roll);
    m33 = cos(camera.heading) * cos(camera.pitch);
    camera.x += secsPerFrame * -speed * m13;
    camera.y += secsPerFrame * -speed * m23;
    camera.z += secsPerFrame * -speed * m33;
I don't get to proper result. The plane takes off when I increase the pitch, for instance. :)
http://www.cis.gsu.edu/~shong/oojokes/

This topic is closed to new replies.

Advertisement