From d3afb677b6ea5942c042b8a83aa5d9ace1dec787 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 10 May 2008 13:51:34 +0000 Subject: client-side roll interpolation --- src/core/gameinterface.cc | 65 ++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc index c3df020..5e2d428 100644 --- a/src/core/gameinterface.cc +++ b/src/core/gameinterface.cc @@ -148,10 +148,35 @@ void GameInterface::update_clientstate(float seconds) math::Vector3f n; math::Vector3f p; + // clientstate axis: pitch + + // project entity->axis().up() into the plane with entity->state()->axis()->left() normal + n = entity->state()->axis().left(); + 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; + + side = entity->state()->axis().forward().x * p.x + + entity->state()->axis().forward().y * p.y + + entity->state()->axis().forward().z * p.z; + + 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()); + + entity->state()->state_axis.change_pitch(-angle); + } + } + // clientstate axis: direction // project entity->axis().forward() into the plane with entity->state()->axis().up() normal n = entity->state()->axis().up(); + 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; @@ -170,47 +195,29 @@ void GameInterface::update_clientstate(float seconds) } } - // clientstate axis: pitch + // clientstate axis: roll - // project entity->axis().up() into the plane with entity->state()->axis()->left() normal - n = entity->state()->axis().left(); + // project entity->axis().up() into the plane with entity->state()->axis().forward() normal + n = entity->state()->axis().forward(); + 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; - - side = entity->state()->axis().forward().x * p.x + - entity->state()->axis().forward().y * p.y + - entity->state()->axis().forward().z * p.z; + + 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().up()); - - if (fabs(cosangle) < 0.99995f) { - angle = acos(cosangle) * 180.0f / M_PI; + angle = acos(cosangle) * 180.0f / M_PI; + if (fabs(cosangle) < 0.99995f) { angle = math::sgnf(side) * angle * seconds / (core::game()->serverframetime() - core::game()->clientframetime()); - entity->state()->state_axis.change_pitch(-angle); + entity->state()->state_axis.change_roll(angle); } } - - /* - // clientstate axis: roll - side = entity->state()->axis().left().x * entity->axis().up().x + - entity->state()->axis().left().y * entity->axis().up().y + - entity->state()->axis().left().z * entity->axis().up().z; - - if (fabs(side) < 0.9999) { - float cosangle = math::dotproduct(entity->axis().up(), 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 (angle > 0.001) - entity->state()->state_axis.change_roll(-angle); - } - */ - } } -- cgit v1.2.3