SuperTuxKart
camera_end.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_END_HPP
22 #define HEADER_CAMERA_END_HPP
23 
24 #include "graphics/camera_normal.hpp"
25 
26 #include "utils/cpp2011.hpp"
27 
33 class CameraEnd : public CameraNormal
34 {
35 private:
39  {
40  public:
47  typedef enum {EC_STATIC_FOLLOW_KART,
48  EC_AHEAD_OF_KART} EndCameraType;
49  EndCameraType m_type;
50 
53 
55  float m_distance2;
56 
60  bool readXML(const XMLNode &node)
61  {
62  std::string s;
63  node.get("type", &s);
64  if(s=="static_follow_kart")
65  m_type = EC_STATIC_FOLLOW_KART;
66  else if(s=="ahead_of_kart")
67  m_type = EC_AHEAD_OF_KART;
68  else
69  {
70  Log::warn("Camera", "Invalid camera type '%s' - camera is ignored.",
71  s.c_str());
72  return false;
73  }
74  node.get("xyz", &m_position);
75  node.get("distance", &m_distance2);
76  // Store the squared value
78  return true;
79  } // readXML
80  // --------------------------------------------------------------------
86  bool isReached(const Vec3 &xyz)
87  { return (xyz-m_position).length2() < m_distance2; }
88  }; // EndCameraInformation
89  // ------------------------------------------------------------------------
90 
93  static AlignedArray<EndCameraInformation> m_end_cameras;
94 
96  unsigned int m_current_end_camera;
97 
99  unsigned int m_next_end_camera;
100 
101  void handleEndCamera(float dt);
102 
103  friend class Camera; // Give Camera access to constructor
104  CameraEnd(int camera_index, AbstractKart* kart);
105  virtual ~CameraEnd() {}
106 public:
107 
108  static void readEndCamera(const XMLNode &root);
109  static void clearEndCameras();
110  virtual void update(float dt) OVERRIDE;
111 }; // class CameraEnd
112 
113 #endif
114 
115 /* EOF */
A class that stores information about the different end cameras which can be specified in the scene....
Definition: camera_end.hpp:38
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:34
static void readEndCamera(const XMLNode &root)
Reads the information about the end camera.
Definition: camera_end.cpp:58
static void clearEndCameras()
This function clears all end camera data structure.
Definition: camera_end.cpp:48
bool isReached(const Vec3 &xyz)
Returns true if the specified position is close enough to this camera, so that this camera should bec...
Definition: camera_end.hpp:86
Vec3 m_position
Position of the end camera.
Definition: camera_end.hpp:52
Handles the normal racing camera.
Definition: camera_normal.hpp:32
float m_distance2
Distance to kart by which this camera is activated.
Definition: camera_end.hpp:55
unsigned int m_current_end_camera
Index of the current end camera.
Definition: camera_end.hpp:96
int get(const std::string &attribute, std::string *value) const
If 'attribute' was defined, set 'value' to the value of the attribute and return 1,...
Definition: xml_node.cpp:176
Handles the end race camera.
Definition: camera_end.hpp:33
utility class used to parse XML files
Definition: xml_node.hpp:47
virtual void update(float dt) OVERRIDE
Called once per time frame to move the camera to the right position.
Definition: camera_end.cpp:85
This is the base class for all cameras.
Definition: camera.hpp:48
bool readXML(const XMLNode &node)
Reads end camera information from XML.
Definition: camera_end.hpp:60
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:61
static AlignedArray< EndCameraInformation > m_end_cameras
List of all end camera information.
Definition: camera_end.hpp:93
unsigned int m_next_end_camera
The next end camera to be activated.
Definition: camera_end.hpp:99
EndCameraType
The camera type: EC_STATIC_FOLLOW_KART A static camera that always points at the kart.
Definition: camera_end.hpp:47