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-10 12:32:05 +0000
committerStijn Buys <ingar@osirion.org>2008-05-10 12:32:05 +0000
commit58fa27476e4be965d78782a971439e430032d6b0 (patch)
tree28e2cb520331662122bb6cfeff32a6613f5cfd5d
parent6d9b90ccce41c183e11eab0e70e7204ba8580dff (diff)
more interpolation issues
-rw-r--r--src/client/view.cc2
-rw-r--r--src/core/gameinterface.cc67
-rw-r--r--src/game/ship.cc12
-rw-r--r--src/math/functions.h5
4 files changed, 48 insertions, 38 deletions
diff --git a/src/client/view.cc b/src/client/view.cc
index 695f478..3524403 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -258,7 +258,7 @@ void frame(float seconds)
// Clear the color and depth buffers.
gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- if (core::application()->connected()) {
+ if (core::application()->connected() && core::game()->serverframetime()) {
// Change to the projection matrix and set our viewing volume.
gl::matrixmode(GL_PROJECTION);
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index 99f884d..c3df020 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -140,50 +140,57 @@ void GameInterface::update_clientstate(float seconds)
if (core::game()->clientframetime() < core::game()->serverframetime()) {
// http://local.wasp.uwa.edu.au/~pbourke/geometry/planeline/
+ float cosangle;
+ float angle;
float side;
float u;
+ math::Vector3f n;
+ math::Vector3f p;
+
// clientstate axis: direction
-
- side = entity->state()->axis().left().x * entity->axis().forward().x +
- entity->state()->axis().left().y * entity->axis().forward().y +
- entity->state()->axis().left().z * entity->axis().forward().z;
- if (fabs(side) < 0.9999) {
- // project entity->axis().forward() into the plane with entity->state()->axis().up() normal
- math::Vector3f const & n = entity->state()->axis().up();
- math::Vector3f p(entity->axis().forward());
- u = p[0]*n[0] + p[1]*n[1] + p[2]*n[2] / (-n[0]*n[0] - n[1]*n[1] - n[2] * n[2]);
- p = entity->axis().forward() + u * n;
+ // project entity->axis().forward() into the plane with entity->state()->axis().up() normal
+ n = entity->state()->axis().up();
+ u = p[0]*n[0] + p[1]*n[1] + p[2]*n[2] / (-n[0]*n[0] - n[1]*n[1] - n[2] * n[2]);
+ p = entity->axis().forward() + u * n;
+
+ side = entity->state()->axis().left().x * p.x +
+ entity->state()->axis().left().y * p.y +
+ entity->state()->axis().left().z * p.z;
+
+ if (fabs(side) > 0.00005f) {
+ cosangle = math::dotproduct(p, entity->state()->axis().forward());
+ if (fabs(cosangle) < 0.99995f) {
+ angle = acos(cosangle) * 180.0f / M_PI;
+ angle = math::sgnf(side) * angle * seconds /
+ (core::game()->serverframetime() - core::game()->clientframetime());
- float cosangle = math::dotproduct(p, entity->state()->axis().forward());
- float angle = acos(cosangle) * 180.0f / M_PI;
- angle = math::sgnf(side) * angle * seconds /
- (core::game()->serverframetime() - core::game()->clientframetime());
-
- if (angle > 0.001)
entity->state()->state_axis.change_direction(angle);
+ }
}
// clientstate axis: pitch
- side = entity->state()->axis().forward().x * entity->axis().up().x +
- entity->state()->axis().forward().y * entity->axis().up().y +
- entity->state()->axis().forward().z * entity->axis().up().z;
- if (fabs(side) < 0.9999) {
- // project entity->axis().up() into the plane with entity->state()->axis()->left() normal
- math::Vector3f const & n = entity->state()->axis().left();
- math::Vector3f p(entity->axis().up());
- u = p[0]*n[0] + p[1]*n[1] + p[2]*n[2] / (-n[0]*n[0] - n[1]*n[1] - n[2] * n[2]);
- p = entity->axis().up() + u * n;
+ // project entity->axis().up() into the plane with entity->state()->axis()->left() normal
+ n = entity->state()->axis().left();
+ u = p[0]*n[0] + p[1]*n[1] + p[2]*n[2] / (-n[0]*n[0] - n[1]*n[1] - n[2] * n[2]);
+ p = entity->axis().up() + u * n;
+
+ side = entity->state()->axis().forward().x * p.x +
+ entity->state()->axis().forward().y * p.y +
+ entity->state()->axis().forward().z * p.z;
- float cosangle = math::dotproduct(p, entity->state()->axis().up());
- float angle = acos(cosangle) * 180.0f / M_PI;
- angle = math::sgnf(side) * angle * seconds /
- (core::game()->serverframetime() - core::game()->clientframetime());
+ if (fabs(side) > 0.00005f) {
+ cosangle = math::dotproduct(p, entity->state()->axis().up());
+
+ if (fabs(cosangle) < 0.99995f) {
+ angle = acos(cosangle) * 180.0f / M_PI;
+ angle = math::sgnf(side) * angle * seconds /
+ (core::game()->serverframetime() - core::game()->clientframetime());
- if (angle > 0.001)
entity->state()->state_axis.change_pitch(-angle);
+ }
}
diff --git a/src/game/ship.cc b/src/game/ship.cc
index a1d4531..525bf71 100644
--- a/src/game/ship.cc
+++ b/src/game/ship.cc
@@ -47,9 +47,9 @@ void Ship::frame(float seconds)
// update pitch
math::clamp(target_pitch, -1.0f, 1.0f);
- if (current_target_pitch < target_pitch) {
+ if (current_target_pitch - target_pitch < 0) {
current_target_pitch += direction_change_speed * seconds;
- } else if (current_target_pitch > target_pitch) {
+ } else if (current_target_pitch - target_pitch > 0) {
current_target_pitch -= direction_change_speed * seconds;
}
if (fabs(current_target_pitch) < direction_change_speed * seconds) {
@@ -62,9 +62,9 @@ void Ship::frame(float seconds)
// update direction
math::clamp(target_direction, -1.0f, 1.0f);
- if (current_target_direction < target_direction) {
+ if (current_target_direction - target_direction < 0) {
current_target_direction += direction_change_speed * seconds;
- } else if (current_target_direction > target_direction) {
+ } else if (current_target_direction - target_direction > 0) {
current_target_direction -= direction_change_speed * seconds;
}
if (fabs(current_target_direction) < direction_change_speed * seconds) {
@@ -77,9 +77,9 @@ void Ship::frame(float seconds)
// update roll
math::clamp(target_roll, -1.0f, 1.0f);
- if (current_target_roll < target_roll) {
+ if (current_target_roll - target_roll < 0) {
current_target_roll += direction_change_speed * seconds;
- } else if (current_target_roll > target_roll) {
+ } else if (current_target_roll - target_roll > 0) {
current_target_roll -= direction_change_speed * seconds;
}
if (fabs(current_target_roll) < direction_change_speed * seconds) {
diff --git a/src/math/functions.h b/src/math/functions.h
index 16de778..d84fe05 100644
--- a/src/math/functions.h
+++ b/src/math/functions.h
@@ -58,7 +58,10 @@ inline void clamp(float &value, float min=0.0f, float max=1.0f)
/// return the absolute value of a float
inline float absf(float f)
{
- if (f >0) return f; else return -f;
+ if (f < 0)
+ return -f;
+ else
+ return f;
}
} // namespace math