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
parenta4b36e6d1e20b5036d1ed7cf9f61a48dbbf77812 (diff)
more 3D changes
-rw-r--r--src/client/camera.cc135
-rw-r--r--src/client/input.cc76
-rw-r--r--src/client/view.cc2
-rw-r--r--src/core/entity.cc4
-rw-r--r--src/core/entity.h2
-rw-r--r--src/game/ship.cc20
-rw-r--r--src/math/axis.cc12
-rw-r--r--src/math/vector3f.cc9
-rw-r--r--src/math/vector3f.h3
-rw-r--r--src/render/draw.cc2
-rw-r--r--src/render/draw.h2
-rw-r--r--src/render/render.h3
12 files changed, 130 insertions, 140 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;
}
}
diff --git a/src/client/input.cc b/src/client/input.cc
index 994e38b..99fe638 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -24,12 +24,10 @@ core::Cvar *cl_mousecontrol = 0;
namespace input
{
-// local offset to make turns
+// local controls
float local_turn = 0.0f;
-// local offset to change pitch
float local_pitch = 0.0f;
-
-// local thrust setting
+float local_roll = 0.0f;
float local_thrust = 0.0f;
// last controlled entity
@@ -38,6 +36,7 @@ unsigned int last_control = 0;
// mouse cursor position
int mouse_x = 0;
int mouse_y = 0;
+
// true if the mouse is in the deadzone
bool mouse_deadzone = false;
@@ -165,6 +164,7 @@ void frame(float seconds)
{
if (core::localcontrol() && (last_control != core::localcontrol()->id())) {
local_turn = 0.0f;
+ local_pitch = 0.0f;
local_thrust = core::localcontrol()->thrust();
last_control = core::localcontrol()->id();
}
@@ -233,41 +233,49 @@ void frame(float seconds)
else if (local_thrust < -2.0 * thruster_offset)
local_thrust = -2.0 * thruster_offset;
- if (camera::mode == camera::Track && cl_mousecontrol->value()) {
- // mouse control when camera is in tracking mode
- int deadzone_size = 24;
- mouse_deadzone = true;
-
- // direction
- int l = mouse_x - (video::width >> 1);
+ if (camera::mode == camera::Track) {
+ if (cl_mousecontrol->value()) {
+ // mouse control when camera is in tracking mode
+ int deadzone_size = 24;
+ mouse_deadzone = true;
+
+ // direction
+ int l = mouse_x - (video::width >> 1);
+
+ if (abs(l) < ( deadzone_size >> 1 )) {
+ // dead zone
+ local_turn = 0;
+ } else {
+ l = (mouse_x - deadzone_size) - ((video::width - deadzone_size) >> 1);
+ local_turn = float (-l) / (float) ((video::width - deadzone_size) >> 1);
+ mouse_deadzone = false;
+ }
+
+ // pitch
+ int h = mouse_y - (video::height >> 1);
+
+ if (abs(h) < ( deadzone_size >> 1 )) {
+ // dead zone
+ local_pitch = 0;
+ } else {
+ h = (mouse_y - deadzone_size) - ((video::height - deadzone_size) >> 1);
+ local_pitch = float (-h) / (float) ((video::height - deadzone_size) >> 1);
+ mouse_deadzone = false;
+ }
- if (abs(l) < ( deadzone_size >> 1 )) {
- // dead zone
- local_turn = 0;
} else {
- l = (mouse_x - deadzone_size) - ((video::width - deadzone_size) >> 1);
- local_turn = float (-l) / (float) ((video::width - deadzone_size) >> 1);
- mouse_deadzone = false;
- }
+ if (local_turn > 1.0f)
+ local_turn = 1.0f;
+ else if (local_turn < -1.0f)
+ local_turn = -1.0f;
- // pitch
- int h = mouse_y - (video::height >> 1);
+ if (local_pitch > 1.0f)
+ local_pitch = 1.0f;
+ else if (local_pitch < -1.0f)
+ local_pitch = -1.0f;
- if (abs(h) < ( deadzone_size >> 1 )) {
- // dead zone
- local_pitch = 0;
- } else {
- h = (mouse_y - deadzone_size) - ((video::height - deadzone_size) >> 1);
- local_pitch = float (-h) / (float) ((video::height - deadzone_size) >> 1);
mouse_deadzone = false;
- }
-
- } else {
- if (local_turn > 1.0f)
- local_turn = 1.0f;
- else if (local_turn < -1.0f)
- local_turn = -1.0f;
- mouse_deadzone = false;
+ }
}
core::localcontrol()->set_thrust(local_thrust);
diff --git a/src/client/view.cc b/src/client/view.cc
index 39cd351..e8ec5e8 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -268,7 +268,7 @@ void frame(float seconds)
camera::draw(seconds); // draw the current camera transformation
- render::draw(camera::eye, camera::target, seconds); // draw the world
+ render::draw(camera::target, seconds); // draw the world
}
diff --git a/src/core/entity.cc b/src/core/entity.cc
index b3d58a3..475af39 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -101,6 +101,8 @@ Entity::Entity(unsigned int flags) :
entity_modelname.clear();
entity_name.clear();
+ entity_renderstate = 0;
+
add(this);
}
@@ -137,6 +139,8 @@ Entity::Entity(std::istream & is)
entity_destroyed = false;
entity_dirty = false;
+ entity_renderstate = 0;
+
add(this, entity_id);
}
diff --git a/src/core/entity.h b/src/core/entity.h
index 86b5ab3..46dd36c 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -146,6 +146,8 @@ public:
bool entity_created;
bool entity_destroyed;
+ unsigned int entity_renderstate;
+
private:
/// add an entity to the registry
static void add(Entity *ent);
diff --git a/src/game/ship.cc b/src/game/ship.cc
index af10525..c9e2266 100644
--- a/src/game/ship.cc
+++ b/src/game/ship.cc
@@ -42,16 +42,6 @@ void Ship::frame(float seconds)
else if(entity_thrust > 1.0f)
entity_thrust = 1.0f;
- // update direction
- if (target_direction > 1.0f)
- target_direction = 1.0f;
- else if (target_direction < -1.0f)
- target_direction = -1.0f;
-
- float direction_offset = ship_shipmodel->turnspeed() * seconds * target_direction;
- if (direction_offset)
- entity_axis.change_direction(360.0f * direction_offset);
-
// update pitch
if (target_pitch > 1.0f)
target_pitch = 1.0f;
@@ -62,6 +52,16 @@ void Ship::frame(float seconds)
if (pitch_offset)
entity_axis.change_pitch(360.0f * pitch_offset);
+ // update direction
+ if (target_direction > 1.0f)
+ target_direction = 1.0f;
+ else if (target_direction < -1.0f)
+ target_direction = -1.0f;
+
+ float direction_offset = ship_shipmodel->turnspeed() * seconds * target_direction;
+ if (direction_offset)
+ entity_axis.change_direction(360.0f * direction_offset);
+
// update speed
if (entity_speed < entity_thrust * ship_shipmodel->maxspeed()) {
entity_speed += ship_shipmodel->acceleration() * seconds;
diff --git a/src/math/axis.cc b/src/math/axis.cc
index cbca99b..6f9710b 100644
--- a/src/math/axis.cc
+++ b/src/math/axis.cc
@@ -74,6 +74,18 @@ void Axis::change_roll(const float angle) {
axis_vector[1].assign(up);
}
+/*
+Axis const Axis::transpose()
+{
+ Axis` t;
+
+ for (size_t i = 0; i < 3; i++)
+ for (size_t j = 0; j < 3; j++)
+ t.axis_vector[j][i] = axis_vector[j][i];
+ return t;
+}
+*/
+
// write an axis to a std::ostream
std::ostream &operator<<(std::ostream & os, Axis const & axis)
{
diff --git a/src/math/vector3f.cc b/src/math/vector3f.cc
index 51d0385..d5173bb 100644
--- a/src/math/vector3f.cc
+++ b/src/math/vector3f.cc
@@ -14,9 +14,9 @@ namespace math
{
Vector3f::Vector3f() :
- x(coord[0]), y(coord[1]), z(coord[2])
+ x(coord[0]), y(coord[1]), z(coord[2])
{
- assign(0,0,0);
+ clear();
}
Vector3f::Vector3f(const Vector3f &other) :
@@ -35,6 +35,11 @@ Vector3f::~Vector3f()
{
}
+void Vector3f::clear()
+{
+ memset(coord, 0, sizeof(coord));
+}
+
void Vector3f::assign(const float vx, const float vy, const float vz)
{
coord[0] = vx;
diff --git a/src/math/vector3f.h b/src/math/vector3f.h
index ddb9e38..1b4028f 100644
--- a/src/math/vector3f.h
+++ b/src/math/vector3f.h
@@ -44,6 +44,9 @@ public:
~Vector3f();
/* -- Assignment operators -- */
+ /// assign (0, 0, 0)
+ void clear();
+
/// assignment
void assign(const float x, const float y, const float z);
diff --git a/src/render/draw.cc b/src/render/draw.cc
index e9976b6..5b64497 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -483,7 +483,7 @@ void draw_local_axis()
}
/* ----- Main draw routine ----------------------------------------- */
-void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds)
+void draw(math::Vector3f const &target, float seconds)
{
Stats::clear();
diff --git a/src/render/draw.h b/src/render/draw.h
index b423aad..6db1c9b 100644
--- a/src/render/draw.h
+++ b/src/render/draw.h
@@ -13,7 +13,7 @@ namespace render
{
/// draw the world
-void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds);
+void draw(math::Vector3f const &target, float seconds);
class Stats {
public:
diff --git a/src/render/render.h b/src/render/render.h
index 00b4672..ce638bb 100644
--- a/src/render/render.h
+++ b/src/render/render.h
@@ -19,9 +19,6 @@ namespace render {
/// shutdown the render subsystem
void shutdown();
- /// draw the game world
- void draw(float elapsed);
-
extern GLuint textures[32];
extern core::Cvar *r_radius;