SuperTuxKart
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 
40 class AbstractKart;
41 
48 class Camera : public NoCopy
49 {
50 public:
53  {
54  CM_TYPE_NORMAL,
58  }; // CameraType
59 
60  /* Only used for the normal camera. */
61  enum Mode
62  {
67  CM_SIMPLE_REPLAY,
68  CM_FALLING
69  }; // Mode
70 
71 
72 private:
73  static Camera* s_active_camera;
74 
76  core::matrix4 m_previous_pv_matrix;
77 
80 
83 
87 
90  unsigned int m_index;
91 
93  video::SColor m_ambient_light;
94 
99 
101  core::recti m_viewport;
102 
104  core::vector2df m_scaling;
105 
107  float m_fov;
108 
110  float m_aspect;
111 
112 
114  static std::vector<Camera*> m_all_cameras;
115 
116  void setupCamera();
117 
118 protected:
120  scene::ICameraSceneNode *m_camera;
121 
127 
128  static Camera* createCamera(unsigned int index, CameraType type,
129  AbstractKart* kart);
130 
131  Camera(CameraType type, int camera_index, AbstractKart* kart);
132  virtual ~Camera();
133  virtual void reset();
134 public:
135  LEAK_CHECK()
136 
137  // ========================================================================
138  // Static functions
139  static Camera* createCamera(AbstractKart* kart, const int index);
140  static void resetAllCameras();
141  static void changeCamera(unsigned int camera_index, CameraType type);
142 
143  // ------------------------------------------------------------------------
146  static void setDefaultCameraType(CameraType type) { m_default_type = type;}
147  // ------------------------------------------------------------------------
151  // ------------------------------------------------------------------------
153  static unsigned int getNumCameras()
154  {
155  return (unsigned int)m_all_cameras.size();
156  } // getNumCameras
157  // ------------------------------------------------------------------------
159  static Camera *getCamera(unsigned int n) { return m_all_cameras[n]; }
160  // ------------------------------------------------------------------------
162  static Camera* getActiveCamera() { return s_active_camera; }
163  // ------------------------------------------------------------------------
165  static void removeAllCameras()
166  {
167  for(unsigned int i=0; i<m_all_cameras.size(); i++)
168  delete m_all_cameras[i];
169  m_all_cameras.clear();
170  } // removeAllCameras
171 
172  // ========================================================================
173 
174  void setMode(Mode mode);
175  Mode getMode();
176  void setKart(AbstractKart *new_kart);
177  virtual void setInitialTransform();
178  virtual void activate(bool alsoActivateInIrrlicht=true);
179  virtual void update(float dt);
180  // ------------------------------------------------------------------------
182  CameraType getType() { return m_type; }
183  // ------------------------------------------------------------------------
185  void setFoV() { m_camera->setFOV(m_fov); }
186  // ------------------------------------------------------------------------
188  int getIndex() const {return m_index;}
189  // ------------------------------------------------------------------------
191  core::matrix4 getPreviousPVMatrix() const { return m_previous_pv_matrix; }
192 
193  // ------------------------------------------------------------------------
195  void setPreviousPVMatrix(core::matrix4 mat) { m_previous_pv_matrix = mat; }
196 
197  // ------------------------------------------------------------------------
199  const AbstractKart* getKart() const { return m_kart; }
200 
201  // ------------------------------------------------------------------------
203  AbstractKart* getKart() { return m_kart; }
204 
205  // ------------------------------------------------------------------------
207  void setAmbientLight(const video::SColor &color) { m_ambient_light=color; }
208 
209  // ------------------------------------------------------------------------
211  const video::SColor &getAmbientLight() const {return m_ambient_light; }
212 
213  // ------------------------------------------------------------------------
215  const core::recti& getViewport() const {return m_viewport; }
216 
217  // ------------------------------------------------------------------------
219  const core::vector2df& getScaling() const {return m_scaling; }
220 
221  // ------------------------------------------------------------------------
223  scene::ICameraSceneNode *getCameraSceneNode() { return m_camera; }
224  // ------------------------------------------------------------------------
226  Vec3 getXYZ() { return Vec3(m_camera->getPosition()); }
227 }; // class Camera
228 
229 #endif
230 
231 /* EOF */
core::recti m_viewport
The viewport for this camera (portion of the game window covered by this camera)
Definition: camera.hpp:101
CameraType getType()
Returns the type of this camera.
Definition: camera.hpp:182
core::matrix4 getPreviousPVMatrix() const
Returns the project-view matrix of the previous frame.
Definition: camera.hpp:191
core::matrix4 m_previous_pv_matrix
The project-view matrix of the previous frame, used for the blur shader.
Definition: camera.hpp:76
End camera.
Definition: camera.hpp:57
static CameraType m_default_type
The default type for any newly created camera.
Definition: camera.hpp:86
float m_aspect
Aspect ratio for camera.
Definition: camera.hpp:110
static Camera * getCamera(unsigned int n)
Returns a camera.
Definition: camera.hpp:159
video::SColor m_ambient_light
Current ambient light for this camera.
Definition: camera.hpp:93
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:34
const video::SColor & getAmbientLight() const
Returns the current ambient light.
Definition: camera.hpp:211
const core::vector2df & getScaling() const
Returns the scaling in x/y direction for this camera.
Definition: camera.hpp:219
Vec3 getXYZ()
Returs the absolute position of the camera.
Definition: camera.hpp:226
Mode
Definition: camera.hpp:61
Closer to kart.
Definition: camera.hpp:64
const core::recti & getViewport() const
Returns the viewport of this camera.
Definition: camera.hpp:215
FPS Camera.
Definition: camera.hpp:56
Looking backwards.
Definition: camera.hpp:65
CameraType
The different camera types that can be used.
Definition: camera.hpp:52
int getIndex() const
Returns the camera index (or player kart index, which is the same).
Definition: camera.hpp:188
scene::ICameraSceneNode * m_camera
The camera scene node.
Definition: camera.hpp:120
static void removeAllCameras()
Remove all cameras.
Definition: camera.hpp:165
core::vector2df m_scaling
The scaling necessary for each axis.
Definition: camera.hpp:104
void setAmbientLight(const video::SColor &color)
Sets the ambient light for this camera.
Definition: camera.hpp:207
static CameraType getDefaultCameraType()
Returns the default type for each camera that will be created.
Definition: camera.hpp:150
Normal camera mode.
Definition: camera.hpp:63
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 * getKart()
Returns the kart to which this camera is attached.
Definition: camera.hpp:203
void setMode(Mode mode)
Sets the mode of the camera.
Definition: camera.cpp:191
const AbstractKart * getKart() const
Returns the kart to which this camera is attached.
Definition: camera.hpp:199
virtual void setInitialTransform()
Saves the current kart position as initial starting position for the camera.
Definition: camera.cpp:235
virtual void reset()
Reset is called when a new race starts.
Definition: camera.cpp:222
virtual void update(float dt)
Called once per time frame to move the camera to the right position.
Definition: camera.cpp:259
float m_fov
Field of view for the camera.
Definition: camera.hpp:107
Mode getMode()
Set the camera to the given mode.
Definition: camera.cpp:213
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:25
AbstractKart * m_original_kart
A pointer to the original kart the camera was pointing at when it was created.
Definition: camera.hpp:98
static void setDefaultCameraType(CameraType type)
Sets the default type for each camera that will be created.
Definition: camera.hpp:146
scene::ICameraSceneNode * getCameraSceneNode()
Returns the camera scene node.
Definition: camera.hpp:223
for deleted player karts in follow the leader
Definition: camera.hpp:66
CameraType m_type
The type of the camera.
Definition: camera.hpp:82
Mode m_mode
Camera's mode.
Definition: camera.hpp:79
static unsigned int getNumCameras()
Returns the number of cameras used.
Definition: camera.hpp:153
void setFoV()
Sets the field of view for the irrlicht camera.
Definition: camera.hpp:185
void setupCamera()
Sets up the viewport, aspect ratio, field of view, and scaling for this camera.
Definition: camera.cpp:169
unsigned int m_index
The index of this camera which is the index of the kart it is attached to.
Definition: camera.hpp:90
static Camera * getActiveCamera()
Returns the currently active camera.
Definition: camera.hpp:162
A debug camera.
Definition: camera.hpp:55
virtual void activate(bool alsoActivateInIrrlicht=true)
Sets viewport etc.
Definition: camera.cpp:287
void setKart(AbstractKart *new_kart)
Changes the owner of this camera to the new kart.
Definition: camera.cpp:154
void setPreviousPVMatrix(core::matrix4 mat)
Returns the project-view matrix of the previous frame.
Definition: camera.hpp:195
This is the base class for all cameras.
Definition: camera.hpp:48
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:61
AbstractKart * m_kart
The kart that the camera follows.
Definition: camera.hpp:126
static std::vector< Camera * > m_all_cameras
List of all cameras.
Definition: camera.hpp:114
virtual ~Camera()
Removes the camera scene node from the scene.
Definition: camera.cpp:142