Pyrogenesis  trunk
CinemaPath.h
Go to the documentation of this file.
1 /* Copyright (C) 2017 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 #ifndef INCLUDED_CINEMAPATH
19 #define INCLUDED_CINEMAPATH
20 
21 #include "maths/NUSpline.h"
22 #include "ps/CStr.h"
23 
24 class CVector3D;
25 class CCamera;
26 
28 {
29 public:
30  CCinemaData() : m_LookAtTarget(false), m_GrowthCount(0), m_Growth(1), m_Switch(1), m_Timescale(fixed::FromInt(1)) {}
31  virtual ~CCinemaData() {}
32 
33  const CCinemaData* GetData() const { return this; }
34 
35  CStrW m_Name;
37  CStrW m_Mode;
38  CStrW m_Style;
39 
41 
42  fixed m_Timescale; // a negative timescale results in backwards play
43 
44  // Distortion variables
45  mutable float m_GrowthCount;
46  float m_Growth;
47  float m_Switch;
48 };
49 
50 
51 // Once the data is part of the path, it shouldn't be changeable, so use private inheritance.
52 // This class encompasses the spline and the information which determines how the path will operate
53 // and also provides the functionality for doing so
54 
55 class CCinemaPath : private CCinemaData, public TNSpline
56 {
57 public:
58  CCinemaPath() : m_TimeElapsed(0), m_PreviousNodeTime(0) {}
59  CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline);
60 
61  // Sets camera position to calculated point on spline
62  void MoveToPointAt(float t, float nodet, const CVector3D& startRotation, CCamera* camera) const;
63 
64  // Distortion mode functions-change how ratio is passed to distortion style functions
65  float EaseIn(float t) const;
66  float EaseOut(float t) const;
67  float EaseInOut(float t) const;
68  float EaseOutIn(float t) const;
69 
70  // Distortion style functions
71  float EaseDefault(float t) const;
72  float EaseGrowth(float t) const;
73  float EaseExpo(float t) const;
74  float EaseCircle(float t) const;
75  float EaseSine(float t) const;
76 
77  float (CCinemaPath::*DistStylePtr)(float ratio) const;
78  float (CCinemaPath::*DistModePtr)(float ratio) const;
79 
80  const CCinemaData* GetData() const;
81 
82 public:
83 
84  CVector3D GetNodePosition(const int index) const;
85  fixed GetNodeDuration(const int index) const;
86  fixed GetDuration() const;
87 
88  float GetNodeFraction() const;
89  float GetElapsedTime() const;
90 
91  const CStrW& GetName() const;
92 
93  void SetTimescale(fixed scale);
94 
96  float m_PreviousNodeTime; // How much time has passed before the current node
97 
98  size_t m_CurrentNode;
100 
101 public:
102 
103  /**
104  * Returns false if finished.
105  * @param deltaRealTime Elapsed real time since the last frame.
106  * @param camera An affected camera
107  */
108  bool Play(const float deltaRealTime, CCamera* camera);
109 
110  /**
111  * Validate the path
112  * @return true if the path is valid
113  */
114  bool Validate();
115 
116  /**
117  * Returns true if path doesn't contain nodes
118  */
119  bool Empty() const;
120 
121  /**
122  * Resets the path state
123  */
124  void Reset();
125 
126  fixed GetTimescale() const;
127 
128  const TNSpline& GetTargetSpline() const;
129 
130 private:
131 
133 };
134 
135 #endif // INCLUDED_CINEMAPATH
virtual ~CCinemaData()
Definition: CinemaPath.h:31
A simple fixed-point number class.
Definition: Fixed.h:119
CStrW m_Style
Definition: CinemaPath.h:38
float m_Switch
Definition: CinemaPath.h:47
float m_Growth
Definition: CinemaPath.h:46
Definition: CinemaPath.h:55
Definition: Vector3D.h:30
CStrW m_Mode
Definition: CinemaPath.h:37
bool m_LookAtTarget
Definition: CinemaPath.h:40
Definition: CinemaPath.h:27
Timed Nonuniform Spline for paths with different time intervals between nodes.
Definition: NUSpline.h:93
size_t m_CurrentNode
Definition: CinemaPath.h:98
CVector3D m_PreviousRotation
Definition: CinemaPath.h:99
CStrW m_Orientation
Definition: CinemaPath.h:36
const CCinemaData * GetData() const
Definition: CinemaPath.h:33
CCinemaData()
Definition: CinemaPath.h:30
Definition: Camera.h:41
CCinemaPath()
Definition: CinemaPath.h:58
float m_PreviousNodeTime
Definition: CinemaPath.h:96
fixed m_Timescale
Definition: CinemaPath.h:42
CStrW m_Name
Definition: CinemaPath.h:35
TNSpline m_TargetSpline
Definition: CinemaPath.h:132
float m_GrowthCount
Definition: CinemaPath.h:45
float m_TimeElapsed
Definition: CinemaPath.h:95