From ba3497bb81f69a70a45f8e8f2d09f9913143a00d Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 25 Jul 2016 17:45:24 +1000 Subject: [PATCH] Properly set the camera type in the constructor (which previously was always 'CM_TYPE_NORMAL'). Fixes #2576. --- src/graphics/camera.cpp | 8 +++++--- src/graphics/camera.hpp | 4 ++-- src/graphics/camera_debug.cpp | 2 +- src/graphics/camera_end.cpp | 2 +- src/graphics/camera_fps.cpp | 2 +- src/graphics/camera_normal.cpp | 13 +++++++++++-- src/graphics/camera_normal.hpp | 3 ++- 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index 3e6073eb0..e374c282b 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -73,7 +73,8 @@ Camera* Camera::createCamera(unsigned int index, CameraType type, Camera *camera = NULL; switch (type) { - case CM_TYPE_NORMAL: camera = new CameraNormal(index, kart); break; + case CM_TYPE_NORMAL: camera = new CameraNormal(CM_TYPE_NORMAL, index, kart); + break; case CM_TYPE_DEBUG: camera = new CameraDebug (index, kart); break; case CM_TYPE_FPS: camera = new CameraFPS (index, kart); break; case CM_TYPE_END: camera = new CameraEnd (index, kart); break; @@ -112,10 +113,11 @@ void Camera::resetAllCameras() } // resetAllCameras // ---------------------------------------------------------------------------- -Camera::Camera(int camera_index, AbstractKart* kart) : m_kart(NULL) +Camera::Camera(CameraType type, int camera_index, AbstractKart* kart) + : m_kart(NULL) { m_mode = CM_NORMAL; - m_type = CameraType::CM_TYPE_NORMAL; + m_type = type; m_index = camera_index; m_original_kart = kart; m_camera = irr_driver->addCameraSceneNode(); diff --git a/src/graphics/camera.hpp b/src/graphics/camera.hpp index 502918ef0..27f117557 100644 --- a/src/graphics/camera.hpp +++ b/src/graphics/camera.hpp @@ -126,9 +126,9 @@ protected: AbstractKart *m_kart; static Camera* createCamera(unsigned int index, CameraType type, - AbstractKart* kart); + AbstractKart* kart); - Camera(int camera_index, AbstractKart* kart); + Camera(CameraType type, int camera_index, AbstractKart* kart); virtual ~Camera(); virtual void reset(); public: diff --git a/src/graphics/camera_debug.cpp b/src/graphics/camera_debug.cpp index ea0009b35..6069a6be7 100644 --- a/src/graphics/camera_debug.cpp +++ b/src/graphics/camera_debug.cpp @@ -32,7 +32,7 @@ CameraDebug::CameraDebugType CameraDebug::m_default_debug_Type = // ============================================================================ CameraDebug::CameraDebug(int camera_index, AbstractKart* kart) - : CameraNormal(camera_index, kart) + : CameraNormal(Camera::CM_TYPE_DEBUG, camera_index, kart) { reset(); } // Camera diff --git a/src/graphics/camera_end.cpp b/src/graphics/camera_end.cpp index d5f868747..971daaa79 100644 --- a/src/graphics/camera_end.cpp +++ b/src/graphics/camera_end.cpp @@ -27,7 +27,7 @@ AlignedArray CameraEnd::m_end_cameras; // ============================================================================ CameraEnd::CameraEnd(int camera_index, AbstractKart* kart) - : CameraNormal(camera_index, kart) + : CameraNormal(Camera::CM_TYPE_END, camera_index, kart) { reset(); if(m_end_cameras.size()>0) diff --git a/src/graphics/camera_fps.cpp b/src/graphics/camera_fps.cpp index 477e17d90..f66278a60 100644 --- a/src/graphics/camera_fps.cpp +++ b/src/graphics/camera_fps.cpp @@ -30,7 +30,7 @@ using namespace irr; // ============================================================================ CameraFPS::CameraFPS(int camera_index, AbstractKart* kart) - : Camera(camera_index, kart) + : Camera(Camera::CM_TYPE_FPS, camera_index, kart) { m_attached = false; diff --git a/src/graphics/camera_normal.cpp b/src/graphics/camera_normal.cpp index cc5231bb2..ea0bf098a 100644 --- a/src/graphics/camera_normal.cpp +++ b/src/graphics/camera_normal.cpp @@ -28,8 +28,17 @@ #include "tracks/track.hpp" // ============================================================================ -CameraNormal::CameraNormal(int camera_index, AbstractKart* kart) - : Camera(camera_index, kart) +/** Constructor for the normal camera. This is the only camera constructor + * except for the base class that takes a camera type as parameter. This is + * because debug and end camera use the normal camera as their base class. + * \param type The type of the camera that is created (can be CM_TYPE_END + * or CM_TYPE_DEBUG). + * \param camera_index Index of this camera. + * \param Kart Pointer to the kart for which this camera is used. + */ +CameraNormal::CameraNormal(Camera::CameraType type, int camera_index, + AbstractKart* kart) + : Camera(type, camera_index, kart) { m_distance = kart ? kart->getKartProperties()->getCameraDistance() : 1000.0f; m_ambient_light = World::getWorld()->getTrack()->getDefaultAmbientColor(); diff --git a/src/graphics/camera_normal.hpp b/src/graphics/camera_normal.hpp index 24edea3bc..742b3aeae 100644 --- a/src/graphics/camera_normal.hpp +++ b/src/graphics/camera_normal.hpp @@ -61,7 +61,8 @@ private: friend class Camera; friend class CameraDebug; friend class CameraEnd; - CameraNormal(int camera_index, AbstractKart* kart); + CameraNormal(Camera::CameraType type, int camera_index, + AbstractKart* kart); virtual ~CameraNormal() {} public: bool isDebug() { return false; }