From 2b3dc3c6687de059c4a2bf634ba56ba20a4c2253 Mon Sep 17 00:00:00 2001 From: stevo14 Date: Tue, 12 May 2009 20:23:27 +0000 Subject: [PATCH] Implemented CM_REVERSE camera mode for looking backwards. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3480 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/graphics/camera.cpp | 16 +++++++++++++++- src/graphics/camera.hpp | 3 ++- src/karts/player_kart.cpp | 9 +++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index 06c742149..10f72022c 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -166,6 +166,20 @@ void Camera::update(float dt) m_position *= m_distance; m_position += m_target; + break; + case CM_REVERSE: // Same as CM_NORMAL except it looks backwards + m_angle_around = m_kart->getHPR().getX() - m_rotation_range * m_kart->getSteerPercent() * m_kart->getSkidding(); + m_angle_up = m_kart->getHPR().getY() + DEGREE_TO_RAD(30.0f); + + m_target = m_kart->getXYZ(); + m_target.setZ(m_target.getZ()+0.75f); + + m_position.setX(-sin(m_angle_around)); + m_position.setY( cos(m_angle_around)); + m_position.setZ( sin(m_angle_up)); + m_position *= m_distance * 2.0f; + m_position += m_target; + break; case CM_CLOSEUP: // Lower to the ground and closer to the kart m_angle_around = m_kart->getHPR().getX() + m_rotation_range * m_kart->getSteerPercent() * m_kart->getSkidding(); @@ -177,7 +191,7 @@ void Camera::update(float dt) m_position.setX( sin(m_angle_around)); m_position.setY(-cos(m_angle_around)); m_position.setZ(-sin(m_angle_up)); - m_position *= m_distance * 0.75f; + m_position *= m_distance * 0.5f; m_position += m_target; break; diff --git a/src/graphics/camera.hpp b/src/graphics/camera.hpp index 31df02644..905e7106d 100644 --- a/src/graphics/camera.hpp +++ b/src/graphics/camera.hpp @@ -36,7 +36,8 @@ class Camera public: enum Mode { CM_NORMAL, // Normal camera mode - CM_CLOSEUP, // Normal camera, closer to kart + CM_CLOSEUP, // Closer to kart + CM_REVERSE, // Looking backwards CM_LEADER_MODE, // for deleted player karts in follow the leader CM_FINAL, // Final camera to show the end of the race CM_SIMPLE_REPLAY diff --git a/src/karts/player_kart.cpp b/src/karts/player_kart.cpp index b1f7009de..d73134408 100644 --- a/src/karts/player_kart.cpp +++ b/src/karts/player_kart.cpp @@ -256,6 +256,15 @@ void PlayerKart::update(float dt) Kart::beep(); } + if(m_controls.m_look_back) + { + m_camera->setMode(Camera::CM_REVERSE); + } + else + { + m_camera->setMode(Camera::CM_NORMAL); + } + // We can't restrict rescue to fulfil isOnGround() (which would be more like // MK), since e.g. in the City track it is possible for the kart to end // up sitting on a brick wall, with all wheels in the air :((