Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CinemaTrack.h
Go to the documentation of this file.
1 /* Copyright (C) 2009 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
19 #ifndef INCLUDED_CINEMATRACK
20 #define INCLUDED_CINEMATRACK
21 
22 #include <list>
23 #include <map>
24 #include "ps/CStr.h"
25 #include "maths/NUSpline.h"
26 
27 /*
28  desc: contains various functions used for cinematic camera paths
29  See also: CinemaHandler.cpp, Cinematic.h/.cpp
30 */
31 
32 class CVector3D;
33 class CVector4D;
34 class CCamera;
35 
36 //For loading data
38 {
39 public:
41  m_Mode(0), m_Style(0), m_Timescale(1) {}
42  virtual ~CCinemaData() {}
43 
44  const CCinemaData* GetData() const { return this; }
45 
46  //Distortion variables
47  mutable float m_GrowthCount;
48  float m_Growth;
49  float m_Switch;
50  int m_Mode;
51  int m_Style;
52  float m_Timescale; //a negative timescale results in backwards play
53 
54 };
55 
56 
57 //Once the data is part of the path, it shouldn't be changeable, so use private inheritance.
58 //This class encompasses the spline and the information which determines how the path will operate
59 //and also provides the functionality for doing so
60 
61 class CCinemaPath : private CCinemaData, public TNSpline
62 {
63 public:
65  CCinemaPath(const CCinemaData& data, const TNSpline& spline);
66  ~CCinemaPath() { DistStylePtr = NULL; DistModePtr = NULL; }
67 
70 
71  //sets camera position to calculated point on spline
72  void MoveToPointAt(float t, float nodet, const CVector3D& );
73 
74  //Distortion mode functions-change how ratio is passed to distortion style functions
75  float EaseIn(float t) const;
76  float EaseOut(float t) const;
77  float EaseInOut(float t) const;
78  float EaseOutIn(float t) const;
79 
80  //Distortion style functions
81  float EaseDefault(float t) const;
82  float EaseGrowth(float t) const;
83  float EaseExpo(float t) const;
84  float EaseCircle(float t) const;
85  float EaseSine(float t) const;
86 
87  float (CCinemaPath::*DistStylePtr)(float ratio) const;
88  float (CCinemaPath::*DistModePtr)(float ratio) const;
89 
90  const CCinemaData* GetData() const { return CCinemaData::GetData(); }
91 
92 public:
93 
94  void DrawSpline(const CVector4D& RGBA, int smoothness, bool lines) const;
95 
96  inline CVector3D GetNodePosition(const int index) const { return Node[index].Position; }
97  inline float GetNodeDuration(const int index) const { return Node[index].Distance; }
98  inline float GetDuration() const { return MaxDistance; }
99 
100  inline float GetNodeFraction() const { return (m_TimeElapsed - m_PreviousNodeTime) / Node[m_CurrentNode].Distance; }
101  inline float GetElapsedTime() const { return m_TimeElapsed; }
102 
103  inline void SetTimescale(float scale) { m_Timescale = scale; }
104 
106  float m_PreviousNodeTime; //How much time has passed before the current node
107 
110 
111 public:
112 
113  /**
114  * Returns false if finished.
115  *
116  * @param deltaRealTime Elapsed real time since the last frame.
117  */
118  bool Play(const float deltaRealTime);
119  bool Validate();
120 
121  inline float GetTimescale() const { return m_Timescale; }
122 };
123 
124 //Class for in game playing of cinematics. Should only be instantiated in CGameView.
126 {
127 public:
128  CCinemaManager();
130 
131  void AddPath(CCinemaPath path, const CStrW& name);
132 
133  //Adds track to list of being played.
134  void QueuePath(const CStrW& name, bool queue);
135  void OverridePath(const CStrW& name); //clears track queue and replaces with 'name'
136 
137  /**
138  * @param deltaRealTime Elapsed real time since the last frame.
139  */
140  bool Update(const float deltaRealTime);
141 
142  //These stop track play, and accept time, not ratio of time
143  void MoveToPointAt(float time);
144 
145  inline void StopPlaying() { m_PathQueue.clear(); }
146  void DrawSpline() const;
147 
148  inline bool IsPlaying() const { return !m_PathQueue.empty(); }
149  bool HasTrack(const CStrW& name) const;
150  inline bool IsActive() const { return m_Active; }
151  inline void SetActive(bool active) { m_Active=active; }
152 
153  inline const std::map<CStrW, CCinemaPath>& GetAllPaths() { return m_Paths; }
154  void SetAllPaths( const std::map<CStrW, CCinemaPath>& tracks);
155  void SetCurrentPath(const CStrW& name, bool current, bool lines);
156 
157 private:
158 
160  std::map<CStrW, CCinemaPath>::iterator m_CurrentPath;
161  std::map<CStrW, CCinemaPath> m_Paths;
162  std::list<CCinemaPath> m_PathQueue;
163 };
164 
165 #endif
virtual ~CCinemaData()
Definition: CinemaTrack.h:42
float m_Timescale
Definition: CinemaTrack.h:52
float EaseOutIn(float t) const
float EaseCircle(float t) const
float GetNodeDuration(const int index) const
Definition: CinemaTrack.h:97
float m_Switch
Definition: CinemaTrack.h:49
float m_Growth
Definition: CinemaTrack.h:48
std::map< CStrW, CCinemaPath > m_Paths
Definition: CinemaTrack.h:161
bool Play(const float deltaRealTime)
Returns false if finished.
bool HasTrack(const CStrW &name) const
void QueuePath(const CStrW &name, bool queue)
float MaxDistance
Definition: NUSpline.h:50
float EaseGrowth(float t) const
bool m_DrawCurrentSpline
Definition: CinemaTrack.h:159
float(CCinemaPath::* DistStylePtr)(float ratio) const
Definition: CinemaTrack.h:87
Definition: wnuma.cpp:46
void SetCurrentPath(const CStrW &name, bool current, bool lines)
void DrawSpline() const
void SetAllPaths(const std::map< CStrW, CCinemaPath > &tracks)
void MoveToPointAt(float t, float nodet, const CVector3D &)
float EaseDefault(float t) const
float EaseSine(float t) const
bool IsPlaying() const
Definition: CinemaTrack.h:148
size_t m_CurrentNode
Definition: CinemaTrack.h:108
std::list< CCinemaPath > m_PathQueue
Definition: CinemaTrack.h:162
CVector3D m_PreviousRotation
Definition: CinemaTrack.h:109
void SetActive(bool active)
Definition: CinemaTrack.h:151
float GetNodeFraction() const
Definition: CinemaTrack.h:100
bool Update(const float deltaRealTime)
float EaseOut(float t) const
float EaseInOut(float t) const
CVector3D GetNodePosition(const int index) const
Definition: CinemaTrack.h:96
void DrawSpline(const CVector4D &RGBA, int smoothness, bool lines) const
Definition: CinemaTrack.cpp:84
Definition: Camera.h:39
const std::map< CStrW, CCinemaPath > & GetAllPaths()
Definition: CinemaTrack.h:153
float GetElapsedTime() const
Definition: CinemaTrack.h:101
std::map< CStrW, CCinemaPath >::iterator m_CurrentPath
Definition: CinemaTrack.h:160
float m_PreviousNodeTime
Definition: CinemaTrack.h:106
float(CCinemaPath::* DistModePtr)(float ratio) const
Definition: CinemaTrack.h:88
void AddPath(CCinemaPath path, const CStrW &name)
const CCinemaData * GetData() const
Definition: CinemaTrack.h:44
void StopPlaying()
Definition: CinemaTrack.h:145
float GetTimescale() const
Definition: CinemaTrack.h:121
float EaseIn(float t) const
void SetTimescale(float scale)
Definition: CinemaTrack.h:103
void OverridePath(const CStrW &name)
void MoveToPointAt(float time)
float GetDuration() const
Definition: CinemaTrack.h:98
float m_GrowthCount
Definition: CinemaTrack.h:47
float m_TimeElapsed
Definition: CinemaTrack.h:105
bool IsActive() const
Definition: CinemaTrack.h:150
const CCinemaData * GetData() const
Definition: CinemaTrack.h:90
bool Validate()
float EaseExpo(float t) const