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>2007-10-27 13:18:04 +0000
committerStijn Buys <ingar@osirion.org>2007-10-27 13:18:04 +0000
commitaa50057b86c35de70ed87921ecdb1288e7e17e41 (patch)
tree20e20f38e230464b6dbd4d5aae6677a33a91a8e0
parentbabef2ec1d88b6057b0e17bf1c04dfa3c9d0d5a0 (diff)
camera handling updates
-rw-r--r--src/client/camera.cc30
-rw-r--r--src/client/camera.h4
-rw-r--r--src/client/input.cc34
-rw-r--r--src/client/input.h6
4 files changed, 46 insertions, 28 deletions
diff --git a/src/client/camera.cc b/src/client/camera.cc
index 6a6da0c..bc8ee3e 100644
--- a/src/client/camera.cc
+++ b/src/client/camera.cc
@@ -20,10 +20,10 @@ Camera::Camera()
pitch_track = -15.0f;
offset_inc = 5.0f;
- yaw = 0;
+ yaw_current = 0;
yaw_target = 0;
- pitch = pitch_track * 2;
+ pitch_current = pitch_track * 2;
pitch_target = pitch_track;
distance = 0.4f;
@@ -42,23 +42,23 @@ void Camera::draw(float elapsed)
}
// adjust yaw
- float d = degreesf(yaw - yaw_target);
- yaw = degreesf( yaw - d * elapsed) ;
+ float d = degreesf(yaw_current - yaw_target);
+ yaw_current = degreesf( yaw_current - d * elapsed) ;
// adjust pitch target
- d = degreesf(pitch - pitch_target);
- pitch = degreesf( pitch - d *elapsed);
+ d = degreesf(pitch_current - pitch_target);
+ pitch_current = degreesf( pitch_current - d *elapsed);
switch (mode) {
case Free:
- gl::translate(1.0f+distance, -distance, 0.0f);
- gl::rotate(-pitch, 0, 0, 1.0f);
- gl::rotate(-yaw, 0, 1.0f, 0);
+ gl::translate(1.0f+distance, -distance/2, 0.0f);
+ gl::rotate(-pitch_current, 0, 0, 1.0f);
+ gl::rotate(-yaw_current, 0, 1.0f, 0);
break;
case Track:
gl::translate(1.0f+distance, -distance , 0.0f);
- gl::rotate(-pitch, 0, 0, 1.0f);
- gl::rotate(-yaw, 0, 1.0f, 0);
+ gl::rotate(-pitch_current, 0, 0, 1.0f);
+ gl::rotate(-yaw_current, 0, 1.0f, 0);
break;
default:
break;
@@ -101,17 +101,17 @@ void Camera::nextmode() {
// switch camera to Track mode
mode = Track;
yaw_target = game::ship.yaw;
- yaw = yaw_target;
+ yaw_current = yaw_target;
pitch_target = pitch_track;
- pitch = pitch_target;
+ pitch_current = pitch_target;
break;
case Track:
// switch camera to Free mode
mode = Free;
yaw_target = game::ship.yaw;
- yaw = yaw_target;
+ yaw_current = yaw_target;
pitch_target = pitch_track;
- pitch = pitch_target;
+ pitch_current = pitch_target;
break;
default:
break;
diff --git a/src/client/camera.h b/src/client/camera.h
index 7e189b3..c363f91 100644
--- a/src/client/camera.h
+++ b/src/client/camera.h
@@ -54,9 +54,9 @@ public:
protected:
/// current yaw, angle in XZ plane, positive is looking left
- float yaw ;
+ float yaw_current;
/// current pitch, angle in XY, positive is looking up
- float pitch;
+ float pitch_current;
/// default tracking pitch
float pitch_track;
/// default offset increment
diff --git a/src/client/input.cc b/src/client/input.cc
index fc70b37..5cafb7d 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -7,28 +7,42 @@
//project headers
#include "client.h"
#include "game/game.h"
-#include "common/functions.h"
namespace client {
void Input::init()
{
- SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
+ //condebug << "SDL_DEFAULT_REPEAT_DELAY " << SDL_DEFAULT_REPEAT_DELAY << std::endl;
+ //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
+ SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL);
}
void Input::shutdown()
{
}
-void Input::handle_keydown(SDL_keysym* keysym)
+/*
+see
+http://docs.mandragor.org/files/Common_libs_documentation/SDL/SDL_Documentation_project_en/sdlevent.html
+*/
+
+// handle key_release events
+void Input::handle_keyreleased(SDL_keysym* keysym)
{
switch( keysym->sym ) {
- case SDLK_ESCAPE:
- game::shutdown();
- break;
case SDLK_SPACE:
camera.nextmode();
break;
+ }
+}
+
+// handle pressed keys
+void Input::handle_keypressed(SDL_keysym* keysym)
+{
+ switch( keysym->sym ) {
+ case SDLK_ESCAPE:
+ game::shutdown();
+ break;
case SDLK_LEFT:
camera.rotate_left();
break;
@@ -65,10 +79,12 @@ void Input::process()
while( SDL_PollEvent( &event ) ) {
switch( event.type ) {
-// case SDL_MOUSEBUTTONUP:
case SDL_KEYDOWN:
- handle_keydown( &event.key.keysym );
- break;
+ handle_keypressed( &event.key.keysym );
+ break;
+ case SDL_KEYUP:
+ handle_keyreleased( &event.key.keysym );
+ break;
case SDL_QUIT:
game::shutdown();
break;
diff --git a/src/client/input.h b/src/client/input.h
index fa5486d..23ddd5d 100644
--- a/src/client/input.h
+++ b/src/client/input.h
@@ -22,8 +22,10 @@ public:
void process();
protected:
- /// handle keydown events
- void handle_keydown(SDL_keysym* keysym);
+ /// handle key release events
+ void handle_keyreleased(SDL_keysym* keysym);
+ /// handle key pressed events
+ void handle_keypressed(SDL_keysym* keysym);
};
} // namespace Client