diff options
author | Stijn Buys <ingar@osirion.org> | 2008-03-03 17:39:02 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-03-03 17:39:02 +0000 |
commit | b0af6f8e14449e8bd49efe94da1041628a549120 (patch) | |
tree | aea4b9f1930af1b89e96d05832bc8559fae0a7f0 /src/client/camera.cc | |
parent | e379b1bfeb231716e07f0e4ae9ef024be9bfd08f (diff) |
usable models, target_engine
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); |