From d1f611197f17ec77c19746a3d6a2e4b6d412d5e8 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 19 Apr 2016 09:40:14 +1000 Subject: [PATCH] Fixed reset of cameras, and switching to debug views. --- src/graphics/camera.cpp | 12 +++++++++++- src/graphics/camera.hpp | 29 ++++++++++++++++++----------- src/graphics/camera_debug.cpp | 4 ++-- src/modes/world.cpp | 5 +---- src/utils/debug.cpp | 4 ++++ 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index 630f108e0..f47ac6490 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -97,10 +97,20 @@ void Camera::changeCamera(unsigned int camera_index, CameraType type) // Replace the previous camera m_all_cameras[camera_index] = new_camera; if(s_active_camera == old_camera) - s_active_camera == new_camera; + s_active_camera = new_camera; delete old_camera; } // changeCamera +// ---------------------------------------------------------------------------- +void Camera::resetAllCameras() +{ + for (unsigned int i = 0; i < Camera::getNumCameras(); i++) + { + changeCamera(i, m_default_type); + getCamera(i)->reset(); + } +} // resetAllCameras + // ---------------------------------------------------------------------------- Camera::Camera(int camera_index, AbstractKart* kart) : m_kart(NULL) { diff --git a/src/graphics/camera.hpp b/src/graphics/camera.hpp index 73a64d72e..502918ef0 100644 --- a/src/graphics/camera.hpp +++ b/src/graphics/camera.hpp @@ -40,13 +40,26 @@ class AbstractKart; /** - * \brief Handles the game camera + * \brief This is the base class for all cameras. It also includes some + * static functios to keep track of all cameras (e.g. a static function to + * create a camera, get a camera with a specified index). * \ingroup graphics */ class Camera : public NoCopy { public: - enum Mode { + /** The different camera types that can be used. */ + enum CameraType + { + CM_TYPE_NORMAL, + CM_TYPE_DEBUG, //!< A debug camera. + CM_TYPE_FPS, //!< FPS Camera + CM_TYPE_END //!< End camera + }; // CameraType + + /* Only used for the normal camera. */ + enum Mode + { CM_NORMAL, //!< Normal camera mode CM_CLOSEUP, //!< Closer to kart CM_REVERSE, //!< Looking backwards @@ -55,13 +68,6 @@ public: CM_FALLING }; // Mode - enum CameraType { - CM_TYPE_NORMAL, - CM_TYPE_DEBUG, //!< A debug camera. - CM_TYPE_FPS, //!< FPS Camera - CM_TYPE_END //!< End camera - }; // CameraType - private: static Camera* s_active_camera; @@ -124,12 +130,14 @@ protected: Camera(int camera_index, AbstractKart* kart); virtual ~Camera(); + virtual void reset(); public: LEAK_CHECK() // ======================================================================== // Static functions static Camera* createCamera(AbstractKart* kart); + static void resetAllCameras(); static void changeCamera(unsigned int camera_index, CameraType type); // ------------------------------------------------------------------------ @@ -166,7 +174,6 @@ public: void setMode(Mode mode); /** Set the camera to the given mode */ Mode getMode(); void setKart(AbstractKart *new_kart); - virtual void reset(); virtual void setInitialTransform(); virtual void activate(bool alsoActivateInIrrlicht=true); virtual void update(float dt); @@ -217,7 +224,7 @@ public: // ------------------------------------------------------------------------ /** Returs the absolute position of the camera. */ Vec3 getXYZ() { return Vec3(m_camera->getPosition()); } -} ; +}; // class Camera #endif diff --git a/src/graphics/camera_debug.cpp b/src/graphics/camera_debug.cpp index 35dfcdc9a..4e19036b1 100644 --- a/src/graphics/camera_debug.cpp +++ b/src/graphics/camera_debug.cpp @@ -119,7 +119,6 @@ void CameraDebug::update(float dt) m_camera->setTarget(xyz); m_camera->setPosition(offset.toIrrVector()); } - // Update the first person camera // If an explosion is happening, stop moving the camera, // but keep it target on the kart. else if (dynamic_cast(m_kart->getKartAnimation())) @@ -132,7 +131,8 @@ void CameraDebug::update(float dt) // above the kart). // Note: this code is replicated from smoothMoveCamera so that // the camera keeps on pointing to the same spot. - core::vector3df current_target = (m_kart->getXYZ().toIrrVector()+core::vector3df(0, above_kart, 0)); + core::vector3df current_target = (m_kart->getXYZ().toIrrVector() + +core::vector3df(0, above_kart, 0)); m_camera->setTarget(current_target); } else diff --git a/src/modes/world.cpp b/src/modes/world.cpp index cc0fc830c..c6fc594be 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -253,10 +253,7 @@ void World::reset() (*i)->reset(); } - for(unsigned int i=0; ireset(); - } + Camera::resetAllCameras(); if(race_manager->hasGhostKarts()) ReplayPlay::get()->reset(); diff --git a/src/utils/debug.cpp b/src/utils/debug.cpp index 17e3025ec..b6b50e241 100644 --- a/src/utils/debug.cpp +++ b/src/utils/debug.cpp @@ -442,21 +442,25 @@ bool handleContextMenuAction(s32 cmdID) else if (cmdID == DEBUG_GUI_CAM_TOP) { CameraDebug::setDebugType(CameraDebug::CM_DEBUG_TOP_OF_KART); + Camera::changeCamera(0, Camera::CM_TYPE_DEBUG); irr_driver->getDevice()->getCursorControl()->setVisible(true); } else if (cmdID == DEBUG_GUI_CAM_WHEEL) { CameraDebug::setDebugType(CameraDebug::CM_DEBUG_GROUND); + Camera::changeCamera(0, Camera::CM_TYPE_DEBUG); irr_driver->getDevice()->getCursorControl()->setVisible(true); } else if (cmdID == DEBUG_GUI_CAM_BEHIND_KART) { CameraDebug::setDebugType(CameraDebug::CM_DEBUG_BEHIND_KART); + Camera::changeCamera(0, Camera::CM_TYPE_DEBUG); irr_driver->getDevice()->getCursorControl()->setVisible(true); } else if (cmdID == DEBUG_GUI_CAM_SIDE_OF_KART) { CameraDebug::setDebugType(CameraDebug::CM_DEBUG_SIDE_OF_KART); + Camera::changeCamera(0, Camera::CM_TYPE_DEBUG); irr_driver->getDevice()->getCursorControl()->setVisible(true); } else if (cmdID == DEBUG_GUI_CAM_FREE)