Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-04-27 16:50:30 +0000
committerStijn Buys <ingar@osirion.org>2008-04-27 16:50:30 +0000
commit84d474fd3bd78f5ba6dcee65323f267fa8061b03 (patch)
tree45a2061ffe0a0eaf2675f5143859f2c06a233241 /src/client/camera.cc
parenta4b36e6d1e20b5036d1ed7cf9f61a48dbbf77812 (diff)
more 3D changes
Diffstat (limited to 'src/client/camera.cc')
-rw-r--r--src/client/camera.cc135
1 files changed, 47 insertions, 88 deletions
diff --git a/src/client/camera.cc b/src/client/camera.cc
index 585aafc..c66a933 100644
--- a/src/client/camera.cc
+++ b/src/client/camera.cc
@@ -22,11 +22,8 @@ namespace client
namespace camera
{
-// public variables
-
// 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
@@ -48,16 +45,12 @@ float pitch_current;
// default pitch in mode::Overview
float pitch_overview;
-
-// current x offset
-float x_offset;
-// current z offset
-float z_offset;
-
// default pitch in mode::Track
-const float pitch_track = 0.0f; // 15.0f;
+const float pitch_track = 15.0f;
+
// default rotate offset increase/decrease
float rotate_offset_inc;
+
// default translate offset increase/decrease
const float translate_offset_inc = 0.1;
@@ -85,31 +78,27 @@ void set_mode(Mode newmode) {
case Track:
// switch camera to Track mode
mode = Track;
- // FIXME
- //yaw_target = core::localcontrol()->direction();
yaw_target = 0;
yaw_current = yaw_target;
pitch_target = pitch_track;
pitch_current = pitch_target;
distance = 0.4f;
break;
+
case Free:
// switch camera to Free mode
mode = Free;
- // FIXME
- //yaw_target = core::localcontrol()->direction();
yaw_target = 0;
yaw_current = yaw_target;
pitch_target = pitch_track;
pitch_current = pitch_target;
distance = 0.4f;
break;
+
case Overview:
// switch camera to Overview mode
mode = Overview;
- x_offset = 0;
- z_offset = 0;
- distance = 20.0f;
+
default:
break;
}
@@ -140,97 +129,73 @@ void next_mode()
void draw(float elapsed)
{
+ math::Matrix4f matrix;
+ math::Axis axis;
+
+ float d = 0;
+
if (!core::localcontrol()) {
- // switch the camera to Overview of the player is not controling anything
+
if (mode != Overview) {
set_mode(Overview);
-
- camera::target = math::Vector3f(0,0,0);
}
+
+ target.clear();
+ axis.clear();
+ pitch_current = -75.0f;
+ axis.change_pitch(pitch_current);
+
+ distance = 20.0f;
+
} else {
+
if (mode == Overview)
set_mode(Track);
- camera::target = core::localcontrol()->location();
- }
+ target.assign(core::localcontrol()->location());
+
+ axis.assign(core::localcontrol()->axis());
- if (mode == Track) {
- // FIXME
- //yaw_target = core::localcontrol()->direction();
- yaw_target = 0;
- }
+ // adjust direction
+ d = degrees180f(yaw_current - yaw_target);
+ yaw_current = degrees360f( yaw_current - d * elapsed);
+ axis.change_direction(yaw_current);
- if ((mode == Free) || (mode == Track)) {
- // adjust yaw
- float d = degrees180f(yaw_current - yaw_target);
- yaw_current = degrees360f( yaw_current - d * elapsed) ;
-
// adjust pitch target
d = degrees180f(pitch_current - pitch_target);
- pitch_current = degrees360f( pitch_current - d *elapsed);
- }
+ pitch_current = degrees360f(pitch_current - d *elapsed);
+ axis.change_pitch(pitch_current);
- // map world coordinates to opengl coordinates
- gl::rotate(90.0f, 0, 1.0, 0);
- gl::rotate(-90.0f, 1.0f , 0, 0);
-
- math::Matrix4f matrix;
-
- // map camera coordinates to opengl coordinates
- switch (mode) {
- case Free:
- case Track:
if (core::localcontrol()->model())
distance = 1+core::localcontrol()->model()->radius();
else
distance = 1.5f;
+ }
- target = core::localcontrol()->location();
- matrix = core::localcontrol()->axis();
+ // map world coordinates to opengl coordinates
+ gl::rotate(90.0f, 0, 1.0, 0);
+ gl::rotate(-90.0f, 1.0f , 0, 0);
- // apply the transpose of the axis transformation (the axis is orhtonormal)
- gl::multmatrix(matrix.transpose());
+ // assign transformation matrix
+ matrix.assign(axis);
- // match the camera with the current target
- gl::translate(-1.0f * target);
-
- // draw the local camera transformation
- gl::translate(distance * core::localcontrol()->axis().forward());
- gl::translate((distance-1)/-2.0f * core::localcontrol()->axis().up());
-
- /*
- // draw the camera transformation
- gl::translate(0.0f, 0.0f, -3*distance/4);
- gl::translate(1.2+distance, 0.0f, 0.0f);
- gl::rotate(-pitch_current, 0.0f, 1.0f, 0.0f);
- gl::rotate(-yaw_current, 0.0f, 0.0f, 1.0f);
- */
-
- // reposition, the engine will draw relative to 0,0,0
- //gl::translate(-1 * target);
- break;
-
- case Overview:
+ // apply the transpose of the axis transformation (the axis is orhtonormal)
+ gl::multmatrix(matrix.transpose());
- eye = target;
- eye.z = eye.z + distance-1;
+ // match the camera with the current target
+ gl::translate(-1.0f * target);
+
+ // apply camera offset
+ gl::translate((1.0f+distance) * axis.forward());
- 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);
- gl::translate(-1*target);
- break;
- default:
- break;
- }
+ // calculate eye position
+ eye = target - ((1.0f+distance) * axis.forward());
}
void key_right()
{
if (mode == Free) {
yaw_target = degrees360f( yaw_target + rotate_offset_inc);
- } else if (mode == Overview) {
- z_offset += translate_offset_inc;
}
}
@@ -238,28 +203,22 @@ void key_left()
{
if (mode == Free) {
yaw_target = degrees360f( yaw_target - rotate_offset_inc);
- } else if (mode == Overview) {
- z_offset -= translate_offset_inc;
}
}
-void key_up()
+void key_down()
{
if (mode == Free) {
pitch_target = pitch_target + rotate_offset_inc;
if (pitch_target > 90.0f) pitch_target = 90.0f;
- } else if (mode == Overview) {
- x_offset += translate_offset_inc;
}
}
-void key_down()
+void key_up()
{
if (mode == Free) {
pitch_target = pitch_target - rotate_offset_inc;
if (pitch_target < -90.0f) pitch_target = -90.0f;
- } else if (mode == Overview) {
- x_offset -= translate_offset_inc;
}
}