Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/camera.cc39
-rw-r--r--src/client/camera.h3
-rw-r--r--src/client/draw.cc4
-rw-r--r--src/client/input.cc9
4 files changed, 53 insertions, 2 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);
diff --git a/src/client/camera.h b/src/client/camera.h
index 93b44d1..08adfaa 100644
--- a/src/client/camera.h
+++ b/src/client/camera.h
@@ -44,6 +44,9 @@ namespace camera
/// gameworld coordinates of the camera target
extern math::Vector3f target;
+ /// gameworld coordinates of the camera eye
+ extern math::Vector3f eye;
+
} // namespace camera
} // namespace client
diff --git a/src/client/draw.cc b/src/client/draw.cc
index 91032a8..1ea315b 100644
--- a/src/client/draw.cc
+++ b/src/client/draw.cc
@@ -148,7 +148,7 @@ void draw_entity_default(core::Entity *entity)
render::gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f );
if (model) {
- model->draw(entity);
+ model->draw(entity, camera::eye);
} else {
switch(entity->shape()) {
case core::Entity::Sphere:
@@ -182,7 +182,7 @@ void draw_entity_controlable(core::EntityControlable *entity)
render::gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f );
if (model) {
- model->draw(entity);
+ model->draw(entity, camera::eye);
} else {
draw_ship(entity);
}
diff --git a/src/client/input.cc b/src/client/input.cc
index eda13fd..3b2db09 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -24,6 +24,8 @@ namespace input
float local_turn;
// local thrust setting
float local_thrust;
+// last controlled entity
+unsigned int last_control = 0;
void init()
{
@@ -103,6 +105,12 @@ void keypressed(const SDL_keysym &keysym)
void frame(float seconds)
{
+ if (core::localcontrol() && (last_control != core::localcontrol()->id())) {
+ local_turn = core::localcontrol()->direction();
+ local_thrust = core::localcontrol()->thrust();
+ last_control = core::localcontrol()->id();
+ }
+
SDL_Event event;
while (SDL_PollEvent(&event)) {
@@ -117,6 +125,7 @@ void frame(float seconds)
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym == '`' || event.key.keysym.sym == '~') {
+ last_control = 0;
console::toggle();
setkeyboardmode(console::visible());
if (console::visible() && chat::visible())