fix request-attack broken by rP19247
[0ad.git] / source / graphics / CinemaPath.h
blob4807aecc5002b4c75e750c70c71fa956295d8d96
1 /* Copyright (C) 2017 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
18 #ifndef INCLUDED_CINEMAPATH
19 #define INCLUDED_CINEMAPATH
21 #include "maths/NUSpline.h"
22 #include "ps/CStr.h"
24 class CVector3D;
25 class CVector4D;
26 class CCamera;
28 // For loading data
29 class CCinemaData
31 public:
32 CCinemaData() : m_LookAtTarget(false), m_GrowthCount(0), m_Growth(1), m_Switch(1), m_Timescale(fixed::FromInt(1)) {}
33 virtual ~CCinemaData() {}
35 const CCinemaData* GetData() const { return this; }
37 CStrW m_Name;
38 CStrW m_Orientation;
39 CStrW m_Mode;
40 CStrW m_Style;
42 bool m_LookAtTarget;
44 fixed m_Timescale; // a negative timescale results in backwards play
46 // Distortion variables
47 mutable float m_GrowthCount;
48 float m_Growth;
49 float m_Switch;
53 // Once the data is part of the path, it shouldn't be changeable, so use private inheritance.
54 // This class encompasses the spline and the information which determines how the path will operate
55 // and also provides the functionality for doing so
57 class CCinemaPath : private CCinemaData, public TNSpline
59 public:
60 CCinemaPath() : m_TimeElapsed(0), m_PreviousNodeTime(0) {}
61 CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline);
63 // Sets camera position to calculated point on spline
64 void MoveToPointAt(float t, float nodet, const CVector3D& startRotation, CCamera* camera) const;
66 // Distortion mode functions-change how ratio is passed to distortion style functions
67 float EaseIn(float t) const;
68 float EaseOut(float t) const;
69 float EaseInOut(float t) const;
70 float EaseOutIn(float t) const;
72 // Distortion style functions
73 float EaseDefault(float t) const;
74 float EaseGrowth(float t) const;
75 float EaseExpo(float t) const;
76 float EaseCircle(float t) const;
77 float EaseSine(float t) const;
79 float (CCinemaPath::*DistStylePtr)(float ratio) const;
80 float (CCinemaPath::*DistModePtr)(float ratio) const;
82 const CCinemaData* GetData() const;
84 public:
86 CVector3D GetNodePosition(const int index) const;
87 fixed GetNodeDuration(const int index) const;
88 fixed GetDuration() const;
90 float GetNodeFraction() const;
91 float GetElapsedTime() const;
93 const CStrW& GetName() const;
95 void SetTimescale(fixed scale);
97 float m_TimeElapsed;
98 float m_PreviousNodeTime; // How much time has passed before the current node
100 size_t m_CurrentNode;
101 CVector3D m_PreviousRotation;
103 public:
106 * Returns false if finished.
107 * @param deltaRealTime Elapsed real time since the last frame.
108 * @param camera An affected camera
110 bool Play(const float deltaRealTime, CCamera* camera);
113 * Validate the path
114 * @return true if the path is valid
116 bool Validate();
119 * Returns true if path doesn't contain nodes
121 bool Empty() const;
124 * Resets the path state
126 void Reset();
128 fixed GetTimescale() const;
130 const TNSpline& GetTargetSpline() const;
132 private:
134 TNSpline m_TargetSpline;
137 #endif // INCLUDED_CINEMAPATH