diff options
Diffstat (limited to 'src/client/camera.cc')
-rw-r--r-- | src/client/camera.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/client/camera.cc b/src/client/camera.cc index e8a6625..dd49aa6 100644 --- a/src/client/camera.cc +++ b/src/client/camera.cc @@ -25,6 +25,8 @@ namespace camera // gameworld coordinates of the camera target math::Vector3f target; +// gameworld coordinates of the camera eye +math::Vector3f eye; // target yaw, angle in XZ plane, positive is looking left float yaw_target; @@ -168,18 +170,55 @@ void draw(float elapsed) // map camera coordinates to opengl coordinates switch (mode) { case Free: + // calculate the position of the eye + eye.x = -distance-1; + eye.y = 0; + eye.z = distance/2; + + eye.x = eye.z * sin(-pitch_current * M_1_PI * 0.5f) + eye.x * cos(-pitch_current * M_1_PI * 0.5f); + eye.y = eye.y; + eye.z = eye.z * sin(-pitch_current * M_1_PI * 0.5f) - eye.x * cos(-pitch_current * M_1_PI * 0.5f); + + eye.x = eye.x * cos(-yaw_current * M_1_PI * 0.5f) - eye.y * sin(-yaw_current * M_1_PI * 0.5f); + eye.y = eye.x * sin(-yaw_current * M_1_PI * 0.5f) + eye.y * cos(-yaw_current * M_1_PI * 0.5f); + eye.z = eye.z; + + eye = eye + target; + + // draw the camera transformation gl::translate(1.0f+distance, 0.0f, -distance/2); gl::rotate(-pitch_current, 0, 1.0f, 0 ); gl::rotate(-yaw_current, 0, 0, 1.0f); gl::translate(-1*target); break; + case Track: + // calculate the position of the eye + eye.x = -distance-1; + eye.y = 0; + eye.z = distance; + + eye.x = eye.z * sin(-pitch_current * M_1_PI * 0.5f) + eye.x * cos(-pitch_current * M_1_PI * 0.5f); + eye.y = eye.y; + eye.z = eye.z * sin(-pitch_current * M_1_PI * 0.5f) - eye.x * cos(-pitch_current * M_1_PI * 0.5f); + + eye.x = eye.x * cos(-yaw_current * M_1_PI * 0.5f) - eye.y * sin(-yaw_current * M_1_PI * 0.5f); + eye.y = eye.x * sin(-yaw_current * M_1_PI * 0.5f) + eye.y * cos(-yaw_current * M_1_PI * 0.5f); + eye.z = eye.z; + + eye = eye + target; + + // draw the camera transformation gl::translate(1.0f+distance, 0.0f, -distance); gl::rotate(-pitch_current, 0, 1.0f, 0); gl::rotate(-yaw_current, 0, 0, 1.0f); gl::translate(-1*target); break; + case Overview: + eye = target; + eye.z = eye.z + distance; + gl::rotate(-75.0f, 0.0f, 1.0f, 0.0f); gl::translate(0.0f, 0.0f, -distance); //gl::translate(x_offset, 0.0f, z_offset); |