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-05-03 14:47:12 +0000
committerStijn Buys <ingar@osirion.org>2008-05-03 14:47:12 +0000
commit5d1e18b796d41e035d0d3e828cc6db54ed21a4b6 (patch)
treed4fc3cd9dd34a5064c6b159309ca9d247081e0d8 /src/client/camera.cc
parent3dedab035c98772fd9607480bddc8ffd9d7dc799 (diff)
camera handling, Cockpit view
Diffstat (limited to 'src/client/camera.cc')
-rw-r--r--src/client/camera.cc161
1 files changed, 82 insertions, 79 deletions
diff --git a/src/client/camera.cc b/src/client/camera.cc
index c2bbc83..8144781 100644
--- a/src/client/camera.cc
+++ b/src/client/camera.cc
@@ -10,6 +10,7 @@
#include "client/client.h"
#include "client/camera.h"
#include "render/render.h"
+#include "sys/sys.h"
using math::degrees360f;
using math::degrees180f;
@@ -27,51 +28,43 @@ math::Vector3f target;
math::Vector3f eye;
math::Axis axis;
-// target yaw, angle in XZ plane, positive is looking left
-float yaw_target;
-// target pitch, angle in XZ plane, positive is looking left
-float pitch_target;
-// distance from the camera to the target
-float distance;
+
// current camera mode
Mode mode;
// private variables
-// current yaw, angle in XZ plane, positive is looking left
+// current and target yaw angle in XZ plane, positive is looking left
float yaw_current;
-// current pitch, angle in XY, positive is looking up
-float pitch_current;
+float yaw_target;
+// movement direction in free mode
+float target_direction;
-// current direction rotation speed
-float current_direction_speed;
-// current pitcj rotation speed
-float current_pitch_speed;
+// current and target pitch angle in XY, positive is looking up
+float pitch_current;
+float pitch_target;
+// movement direction in free mode
+float target_pitch;
-// default pitch in mode::Overview
-float pitch_overview;
+float distance;
// default pitch in mode::Track
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;
+const float pitch_overview = -75.0f;
void set_mode(Mode newmode);
void init()
{
- rotate_offset_inc = 5.0f;
-
yaw_current = 0;
yaw_target = 0;
pitch_current = pitch_track * 2;
pitch_target = pitch_track;
+ target_pitch = 0.0f;
+ target_direction = 0.0f;
+
distance = 0.4f;
set_mode(Track);
@@ -84,12 +77,13 @@ void shutdown()
void set_mode(Mode newmode) {
- current_direction_speed = 0;
- current_pitch_speed = 0;
yaw_target = 0;
yaw_current = yaw_target;
pitch_target = pitch_track;
- pitch_current = pitch_target;
+ pitch_current = pitch_target;
+
+ target_direction = 0.0f;
+ target_pitch = 0.0f;
distance = 0.4f;
switch(newmode) {
@@ -101,6 +95,12 @@ void set_mode(Mode newmode) {
case Free:
// switch camera to Free mode
mode = Free;
+ pitch_target = 2.0 * pitch_track;
+ pitch_current = pitch_target;
+ break;
+
+ case Cockpit:
+ mode = Cockpit;
break;
case Overview:
@@ -125,11 +125,21 @@ void next_mode()
case Free:
// switch camera to Track mode
set_mode(Track);
+ con_print << "camera mode: track" << std::endl;
break;
+
case Track:
+ // switch camera to Cockpit mode
+ set_mode(Cockpit);
+ con_print << "camera mode: cockpit" << std::endl;
+ break;
+
+ case Cockpit:
// switch camera to Free mode
set_mode(Free);
+ con_print << "camera mode: free" << std::endl;
break;
+
default:
break;
}
@@ -149,7 +159,7 @@ void draw(float seconds)
target.clear();
axis.clear();
- pitch_current = -75.0f;
+ pitch_current = pitch_overview;
axis.change_pitch(pitch_current);
distance = 20.0f;
@@ -160,38 +170,46 @@ void draw(float seconds)
set_mode(Track);
target.assign(core::localcontrol()->location());
- if (core::localcontrol()->model())
- target += core::localcontrol()->model()->maxbbox().z * core::localcontrol()->axis().up();
if (mode == Track) {
+ if (core::localcontrol()->model())
+ target += core::localcontrol()->model()->maxbbox().x * core::localcontrol()->axis().forward();
+
// make the camera swing while turning
- yaw_target = -25.0f * core::localcontrol()->target_direction;
- pitch_target = pitch_track - 25 * core::localcontrol()->target_pitch;
- /*
- d = -math::dotproduct(axis.forward(), core::localcontrol()->axis().forward()) + 1;
- axis.change_direction(360.0f * d * seconds);
-
- //d = -math::dotproduct(axis.left(), core::localcontrol()->axis().left()) + 1;
- // axis.change_pitch(360.0f * d * seconds);
- */
- }
+ target_direction = core::localcontrol()->target_direction;
+ pitch_target = core::localcontrol()->target_pitch;
+
+ yaw_target = - 45 * target_direction;
+ pitch_target = pitch_track -45 * target_pitch;
+
+ } else if (mode == Free) {
+
+ yaw_target = yaw_current - 90 * target_direction;
+ pitch_target = pitch_current - 90 * target_pitch;
+ } else if (mode == Cockpit) {
+ if (core::localcontrol()->model())
+ target += core::localcontrol()->model()->maxbbox().x * core::localcontrol()->axis().forward();
+ }
+
axis.assign(core::localcontrol()->axis());
- // adjust direction
- d = degrees180f(yaw_current - yaw_target);
- yaw_current = degrees360f( yaw_current - d * seconds);
- axis.change_direction(yaw_current);
+ if (mode != Cockpit) {
+ // adjust direction
+ d = degrees180f(yaw_current - yaw_target);
+ yaw_current = degrees360f( yaw_current - 2* d * seconds);
+ axis.change_direction(yaw_current);
- // adjust pitch target
- d = degrees180f(pitch_current - pitch_target);
- pitch_current = degrees360f(pitch_current - d *seconds);
- axis.change_pitch(pitch_current);
+ // adjust pitch target
+ d = degrees180f(pitch_current - pitch_target);
+ pitch_current = degrees360f(pitch_current - 2* d *seconds);
+ axis.change_pitch(pitch_current);
- if (core::localcontrol()->model())
- distance = 1+core::localcontrol()->model()->radius();
- else
- distance = 1.5f;
+ if (core::localcontrol()->model())
+ distance = 1+core::localcontrol()->model()->radius();
+ else
+ distance = 1.5f;
+ }
}
// map world coordinates to opengl coordinates
@@ -207,44 +225,29 @@ void draw(float seconds)
// match the camera with the current target
gl::translate(-1.0f * target);
- // apply camera offset
- gl::translate((1.0f+distance) * axis.forward());
-
- // calculate eye position
- eye = target - ((1.0f+distance) * axis.forward());
-}
+ if (mode != Cockpit) {
+ // apply camera offset
+ gl::translate((1.0f+distance) * axis.forward());
-void key_right()
-{
- if (mode == Free) {
- yaw_target = degrees360f( yaw_target + rotate_offset_inc);
- }
-}
-
-void key_left()
-{
- if (mode == Free) {
- yaw_target = degrees360f( yaw_target - rotate_offset_inc);
+ // calculate eye position
+ eye = target - ((1.0f+distance) * axis.forward());
+ } else {
+ eye.assign(target);
}
}
-void key_down()
+void set_direction(float direction)
{
- if (mode == Free) {
- pitch_target = pitch_target + rotate_offset_inc;
- if (pitch_target > 90.0f) pitch_target = 90.0f;
- }
+ target_direction = direction;
+ math::clamp(target_direction, -1.0f, 1.0f);
}
-void key_up()
+void set_pitch(float pitch)
{
- if (mode == Free) {
- pitch_target = pitch_target - rotate_offset_inc;
- if (pitch_target < -90.0f) pitch_target = -90.0f;
- }
+ target_pitch = pitch;
+ math::clamp(target_pitch, -1.0f, 1.0f);
}
-
void reset()
{
set_mode(mode);