From 803db6bfb6cc4dd47435868315fc5efc6064d2c3 Mon Sep 17 00:00:00 2001 From: hiker Date: Thu, 14 Jun 2007 22:34:15 +0000 Subject: [PATCH] Fixed camera handling (pitch) on steep declines. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1152 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/camera.cpp | 16 ++++++++++++++-- src/camera.hpp | 3 ++- src/game_manager.cpp | 2 +- src/scene.cpp | 4 ++-- src/scene.hpp | 2 +- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/camera.cpp b/src/camera.cpp index 1c4895f05..6f0a2f7a6 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -62,6 +62,7 @@ Camera::setScreenPosition ( int numPlayers, int pos ) break; } } + m_LastPitch = 0.0f; } //----------------------------------------------------------------------------- @@ -90,7 +91,7 @@ Camera::setMode(Mode mode_) } //----------------------------------------------------------------------------- -void Camera::update () +void Camera::update (float dt) { // Update the camera if ( m_which_kart >= int(world->getNumKarts()) || m_which_kart < 0 ) m_which_kart = 0 ; @@ -99,7 +100,18 @@ void Camera::update () sgCopyCoord(&kartcoord, world->getPlayerKart(m_which_kart)->getCoord()); kartcoord.hpr[2] = 0; - kartcoord.hpr[1] = 0; + + // If the car angle is 'significantly' different from the camera angle, + // start adjusting the camera. This helps with steep declines, where + // otherwise the track is not visible anymore. + if(fabsf(kartcoord.hpr[1]-m_LastPitch)>1.0f) { + kartcoord.hpr[1] = m_LastPitch + (kartcoord.hpr[1]-m_LastPitch)*2.0f*dt; + } + else + { + kartcoord.hpr[1]=m_LastPitch; + } + m_LastPitch = kartcoord.hpr[1]; if (m_mode == CM_SIMPLE_REPLAY) kartcoord.hpr[0] = 0; diff --git a/src/camera.hpp b/src/camera.hpp index 546163511..e2f6bf9cb 100644 --- a/src/camera.hpp +++ b/src/camera.hpp @@ -40,6 +40,7 @@ protected: Mode m_mode; float m_last_steer_offset; float m_x, m_y, m_w, m_h ; + float m_LastPitch; public: Camera ( int numPlayers, int id ) ; @@ -49,7 +50,7 @@ public: void setScreenPosition ( int numPlayers, int pos ) ; - void update () ; + void update (float dt) ; void apply () ; } ; diff --git a/src/game_manager.cpp b/src/game_manager.cpp index 6c9e74205..8af15705e 100644 --- a/src/game_manager.cpp +++ b/src/game_manager.cpp @@ -76,7 +76,7 @@ void GameManager::run() if (race_manager->raceIsActive()) { - scene->draw(); + scene->draw((m_curr_time - m_prev_time ) * 0.001); if ( world->getPhase() != World::LIMBO_PHASE) { world->update((m_curr_time - m_prev_time ) * 0.001); diff --git a/src/scene.cpp b/src/scene.cpp index 4e5537b2e..b09fe39a7 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -83,7 +83,7 @@ void Scene::remove(ssgEntity *kid) } //----------------------------------------------------------------------------- -void Scene::draw() +void Scene::draw(float dt) { glEnable ( GL_DEPTH_TEST ) ; @@ -124,7 +124,7 @@ void Scene::draw() for (Cameras::iterator i = m_cameras.begin(); i != m_cameras.end(); ++i) { - (*i)->update(); + (*i)->update(dt); (*i) -> apply () ; #ifdef BULLET diff --git a/src/scene.hpp b/src/scene.hpp index 6987e110c..957badf49 100644 --- a/src/scene.hpp +++ b/src/scene.hpp @@ -41,7 +41,7 @@ public: void add(ssgEntity *kid); void remove(ssgEntity *kid); - void draw(); + void draw(float dt); void set_race_cameras(int num_players); //TODO: add camera