Fixed reset of cameras, and switching to debug views.

This commit is contained in:
hiker 2016-04-19 09:40:14 +10:00
parent d65dd6c199
commit d1f611197f
5 changed files with 36 additions and 18 deletions

View File

@ -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)
{

View File

@ -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

View File

@ -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<ExplosionAnimation*>(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

View File

@ -253,10 +253,7 @@ void World::reset()
(*i)->reset();
}
for(unsigned int i=0; i<Camera::getNumCameras(); i++)
{
Camera::getCamera(i)->reset();
}
Camera::resetAllCameras();
if(race_manager->hasGhostKarts())
ReplayPlay::get()->reset();

View File

@ -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)