From 58fa27476e4be965d78782a971439e430032d6b0 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 10 May 2008 12:32:05 +0000 Subject: more interpolation issues --- src/client/view.cc | 2 +- src/core/gameinterface.cc | 67 ++++++++++++++++++++++++++--------------------- src/game/ship.cc | 12 ++++----- src/math/functions.h | 5 +++- 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 -- cgit v1.2.3