SuperTuxKart
Loading...
Searching...
No Matches
camera.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2004-2015 Steve Baker <sjbaker1@airmail.net>
4// Copyright (C) 2006-2015 SuperTuxKart-Team, Steve Baker
5//
6// This program is free software; you can redistribute it and/or
7// modify it under the terms of the GNU General Public License
8// as published by the Free Software Foundation; either version 3
9// of the License, or (at your option) any later version.
10//
11
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21#ifndef HEADER_CAMERA_HPP
22#define HEADER_CAMERA_HPP
23
24#include "io/xml_node.hpp"
25#include "utils/no_copy.hpp"
26#include "utils/aligned_array.hpp"
27#include "utils/leak_check.hpp"
28#include "utils/log.hpp"
29#include "utils/vec3.hpp"
30
31#include "matrix4.h"
32#include "rect.h"
33#include "SColor.h"
34#include "vector2d.h"
35
36#include <vector>
37
38#include "ICameraSceneNode.h"
39
40class AbstractKart;
41
48class Camera : public NoCopy
49{
50public:
53 {
54 CM_TYPE_NORMAL,
58 }; // CameraType
59
60 /* Only used for the normal camera. */
61 enum Mode
62 {
69 CM_SIMPLE_REPLAY,
70 CM_FALLING
71 }; // Mode
72
73
74private:
75 static Camera* s_active_camera;
76
78 core::matrix4 m_previous_pv_matrix;
79
82 Mode m_previous_mode;
83
86
90
93 unsigned int m_index;
94
96 video::SColor m_ambient_light;
97
102
104 core::recti m_viewport;
105
107 core::vector2df m_scaling;
108
110 float m_fov;
111
113 float m_aspect;
114
115
117 static std::vector<Camera*> m_all_cameras;
118
119protected:
121 scene::ICameraSceneNode *m_camera;
122
128
129 static Camera* createCamera(unsigned int index, CameraType type,
130 AbstractKart* kart);
131
132 Camera(CameraType type, int camera_index, AbstractKart* kart);
133 virtual ~Camera();
134 virtual void reset();
135public:
136 LEAK_CHECK()
137
138 // ========================================================================
139 // Static functions
140 static Camera* createCamera(AbstractKart* kart, const int index);
141 static void resetAllCameras();
142 static void changeCamera(unsigned int camera_index, CameraType type);
143
144 // ------------------------------------------------------------------------
147 static void setDefaultCameraType(CameraType type) { m_default_type = type;}
148 // ------------------------------------------------------------------------
152 // ------------------------------------------------------------------------
154 static unsigned int getNumCameras()
155 {
156 return (unsigned int)m_all_cameras.size();
157 } // getNumCameras
158 // ------------------------------------------------------------------------
160 static Camera *getCamera(unsigned int n) { return m_all_cameras[n]; }
161 // ------------------------------------------------------------------------
163 static Camera* getActiveCamera() { return s_active_camera; }
164 // ------------------------------------------------------------------------
166 static void removeAllCameras()
167 {
168 for(unsigned int i=0; i<m_all_cameras.size(); i++)
169 delete m_all_cameras[i];
170 m_all_cameras.clear();
171 } // removeAllCameras
172
173 // ========================================================================
174
175 void setMode(Mode mode);
176 Mode getMode();
178 bool isSpectatorMode();
180 void setKart(AbstractKart *new_kart);
181 virtual void setInitialTransform();
182 virtual void activate(bool alsoActivateInIrrlicht=true);
183 virtual void update(float dt);
184 // ------------------------------------------------------------------------
187 // ------------------------------------------------------------------------
189 void setFoV() { m_camera->setFOV(m_fov); }
190 // ------------------------------------------------------------------------
192 int getIndex() const {return m_index;}
193 // ------------------------------------------------------------------------
195 core::matrix4 getPreviousPVMatrix() const { return m_previous_pv_matrix; }
196
197 // ------------------------------------------------------------------------
199 void setPreviousPVMatrix(core::matrix4 mat) { m_previous_pv_matrix = mat; }
200
201 // ------------------------------------------------------------------------
203 const AbstractKart* getKart() const { return m_kart; }
204
205 // ------------------------------------------------------------------------
208
209 // ------------------------------------------------------------------------
211 void setAmbientLight(const video::SColor &color) { m_ambient_light=color; }
212
213 // ------------------------------------------------------------------------
215 const video::SColor &getAmbientLight() const {return m_ambient_light; }
216
217 // ------------------------------------------------------------------------
219 const core::recti& getViewport() const {return m_viewport; }
220
221 // ------------------------------------------------------------------------
223 const core::vector2df& getScaling() const {return m_scaling; }
224
225 // ------------------------------------------------------------------------
227 scene::ICameraSceneNode *getCameraSceneNode() { return m_camera; }
228 // ------------------------------------------------------------------------
230 Vec3 getXYZ() { return Vec3(m_camera->getPosition()); }
231 // ------------------------------------------------------------------------
232 void setupCamera();
233}; // class Camera
234
235#endif
236
237/* EOF */
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
This is the base class for all cameras.
Definition: camera.hpp:49
static Camera * getActiveCamera()
Returns the currently active camera.
Definition: camera.hpp:163
virtual void reset()
Reset is called when a new race starts.
Definition: camera.cpp:256
CameraType m_type
The type of the camera.
Definition: camera.hpp:85
core::recti m_viewport
The viewport for this camera (portion of the game window covered by this camera)
Definition: camera.hpp:104
void setPreviousPVMatrix(core::matrix4 mat)
Returns the project-view matrix of the previous frame.
Definition: camera.hpp:199
AbstractKart * m_original_kart
A pointer to the original kart the camera was pointing at when it was created.
Definition: camera.hpp:101
core::matrix4 getPreviousPVMatrix() const
Returns the project-view matrix of the previous frame.
Definition: camera.hpp:195
core::matrix4 m_previous_pv_matrix
The project-view matrix of the previous frame, used for the blur shader.
Definition: camera.hpp:78
unsigned int m_index
The index of this camera which is the index of the kart it is attached to.
Definition: camera.hpp:93
CameraType getType()
Returns the type of this camera.
Definition: camera.hpp:186
virtual void update(float dt)
Called once per time frame to move the camera to the right position.
Definition: camera.cpp:293
virtual void activate(bool alsoActivateInIrrlicht=true)
Sets viewport etc.
Definition: camera.cpp:321
static std::vector< Camera * > m_all_cameras
List of all cameras.
Definition: camera.hpp:117
Vec3 getXYZ()
Returs the absolute position of the camera.
Definition: camera.hpp:230
AbstractKart * getKart()
Returns the kart to which this camera is attached.
Definition: camera.hpp:207
static unsigned int getNumCameras()
Returns the number of cameras used.
Definition: camera.hpp:154
static Camera * createCamera(unsigned int index, CameraType type, AbstractKart *kart)
Creates a camera of the specified type, but does not add it to the list of all cameras.
Definition: camera.cpp:76
AbstractKart * m_kart
The kart that the camera follows.
Definition: camera.hpp:127
void setFoV()
Sets the field of view for the irrlicht camera.
Definition: camera.hpp:189
const core::vector2df & getScaling() const
Returns the scaling in x/y direction for this camera.
Definition: camera.hpp:223
void setAmbientLight(const video::SColor &color)
Sets the ambient light for this camera.
Definition: camera.hpp:211
void setMode(Mode mode)
Sets the mode of the camera.
Definition: camera.cpp:197
const core::recti & getViewport() const
Returns the viewport of this camera.
Definition: camera.hpp:219
static CameraType m_default_type
The default type for any newly created camera.
Definition: camera.hpp:89
bool isSpectatorMode()
Returns true if camera is a spectator camera.
Definition: camera.cpp:237
Mode getPreviousMode()
Returns the last known mode of the camera.
Definition: camera.cpp:229
const AbstractKart * getKart() const
Returns the kart to which this camera is attached.
Definition: camera.hpp:203
scene::ICameraSceneNode * m_camera
The camera scene node.
Definition: camera.hpp:121
static void setDefaultCameraType(CameraType type)
Sets the default type for each camera that will be created.
Definition: camera.hpp:147
float m_fov
Field of view for the camera.
Definition: camera.hpp:110
video::SColor m_ambient_light
Current ambient light for this camera.
Definition: camera.hpp:96
static CameraType getDefaultCameraType()
Returns the default type for each camera that will be created.
Definition: camera.hpp:151
core::vector2df m_scaling
The scaling necessary for each axis.
Definition: camera.hpp:107
int getIndex() const
Returns the camera index (or player kart index, which is the same).
Definition: camera.hpp:192
scene::ICameraSceneNode * getCameraSceneNode()
Returns the camera scene node.
Definition: camera.hpp:227
float m_aspect
Aspect ratio for camera.
Definition: camera.hpp:113
void setupCamera()
Sets up the viewport, aspect ratio, field of view, and scaling for this camera.
Definition: camera.cpp:169
static void removeAllCameras()
Remove all cameras.
Definition: camera.hpp:166
virtual ~Camera()
Removes the camera scene node from the scene.
Definition: camera.cpp:142
Mode getMode()
Set the camera to the given mode.
Definition: camera.cpp:221
void setKart(AbstractKart *new_kart)
Changes the owner of this camera to the new kart.
Definition: camera.cpp:154
virtual void setInitialTransform()
Saves the current kart position as the initial starting position for the camera.
Definition: camera.cpp:269
static Camera * getCamera(unsigned int n)
Returns a camera.
Definition: camera.hpp:160
CameraType
The different camera types that can be used.
Definition: camera.hpp:53
@ CM_TYPE_FPS
FPS Camera.
Definition: camera.hpp:56
@ CM_TYPE_END
End camera.
Definition: camera.hpp:57
@ CM_TYPE_DEBUG
A debug camera.
Definition: camera.hpp:55
Mode m_mode
Camera's mode.
Definition: camera.hpp:81
Mode
Definition: camera.hpp:62
@ CM_NORMAL
Normal camera mode.
Definition: camera.hpp:63
@ CM_LEADER_MODE
for deleted player karts in follow the leader
Definition: camera.hpp:66
@ CM_CLOSEUP
Closer to kart.
Definition: camera.hpp:64
@ CM_REVERSE
Looking backwards.
Definition: camera.hpp:65
@ CM_SPECTATOR_TOP_VIEW
for spectator (top view on ball if soccer or top view on kart)
Definition: camera.hpp:68
@ CM_SPECTATOR_SOCCER
for spectator (in soccer mode)
Definition: camera.hpp:67
const video::SColor & getAmbientLight() const
Returns the current ambient light.
Definition: camera.hpp:215
void setNextSpectatorMode()
Switch to next spectator mode (a -> soccer -> top view -> a)
Definition: camera.cpp:245
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35