From d49f00921319a906e66bebf05b587bc858d8c210 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Sun, 1 Feb 2009 22:54:00 +0000 Subject: [PATCH] Removed the camera jump which happens on some tracks (e.g. snow mountain) at the start of a race. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@3088 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/graphics/camera.cpp | 22 +++++++++++++++++----- src/graphics/camera.hpp | 21 +++++++++++---------- src/graphics/scene.cpp | 8 ++++---- src/modes/world.cpp | 3 ++- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index 19f1e42dc..2c7043024 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -149,12 +149,25 @@ Camera::Mode Camera::getMode() void Camera::reset() { setMode(CM_NORMAL); - m_last_pitch = 0.0f; - m_xyz = m_kart->getXYZ(); - m_hpr = Vec3(0,0,0); - sound_manager->positionListener(m_xyz, m_xyz); + // m_xyz etc are set when the worlds has computed the right starting + // position of all karts and calls setInitialTransform for each camera. + } // reset +//----------------------------------------------------------------------------- +/** Saves the current kart position as initial starting position for the + * camera. + */ +void Camera::setInitialTransform() +{ + btTransform t = m_kart->getBody()->getCenterOfMassTransform(); + m_xyz = t.getOrigin(); + Coord c(t); + m_hpr = c.getHPR(); + m_last_pitch = m_hpr.getPitch(); + sound_manager->positionListener(m_xyz, m_xyz); +} // updateKartPosition + //----------------------------------------------------------------------------- void Camera::update (float dt) { @@ -202,7 +215,6 @@ void Camera::update (float dt) // Set the camera rotation // ----------------------- float sign = reverse ? 1.0f : -1.0f; - //const int num_players = race_manager->getNumLocalPlayers(); float pitch; if(m_mode!=CM_CLOSEUP) pitch = race_manager->getNumLocalPlayers()>1 ? sign * DEGREE_TO_RAD(10.0f) diff --git a/src/graphics/camera.hpp b/src/graphics/camera.hpp index c9fde3226..842052b26 100644 --- a/src/graphics/camera.hpp +++ b/src/graphics/camera.hpp @@ -19,8 +19,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifndef HEADER_CAMERA_H -#define HEADER_CAMERA_H +#ifndef HEADER_CAMERA_HPP +#define HEADER_CAMERA_HPP #include "utils/vec3.hpp" @@ -54,16 +54,17 @@ protected: float m_final_time; // time when final camera mode started private: - void finalCamera (float dt); // handle the final camera + void finalCamera (float dt); // handle the final camera public: - Camera (int camera_index, const Kart* kart); - ~Camera (); - void setMode (Mode mode_); /** Set the camera to the given mode */ + Camera (int camera_index, const Kart* kart); + ~Camera (); + void setMode (Mode mode_); /** Set the camera to the given mode */ Mode getMode(); - void setScreenPosition(int pos); - void reset (); - void update (float dt); - void apply (); + void setScreenPosition (int pos); + void reset (); + void setInitialTransform(); + void update (float dt); + void apply (); } ; #endif diff --git a/src/graphics/scene.cpp b/src/graphics/scene.cpp index f76757da7..8e0ad6eeb 100644 --- a/src/graphics/scene.cpp +++ b/src/graphics/scene.cpp @@ -88,11 +88,11 @@ void Scene::remove(ssgEntity *kid) //----------------------------------------------------------------------------- void Scene::reset() { - for (Cameras::iterator i = m_cameras.begin(); i != m_cameras.end(); ++i) - { - (*i)->reset(); - } + /** Note: the cameras are reset in player_kart. This is necessary since + * the camera needs the correct starting position and rotation of the + * kart (to avoid that the camera jumps in the first frame). */ } // reset + //----------------------------------------------------------------------------- void Scene::draw(float dt) { diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 6e98784ce..2b2c3e4e7 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -260,7 +260,8 @@ void World::resetAllKarts() // so that the karts can visualise the suspension. for ( Karts::iterator i=m_kart.begin(); i!=m_kart.end(); i++) (*i)->setSuspensionLength(); - + for(unsigned int i=0; igetCamera()->setInitialTransform(); } // resetAllKarts //-----------------------------------------------------------------------------