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"
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; }
44 fixed m_Timescale
; // a negative timescale results in backwards play
46 // Distortion variables
47 mutable float m_GrowthCount
;
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
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;
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
);
98 float m_PreviousNodeTime
; // How much time has passed before the current node
100 size_t m_CurrentNode
;
101 CVector3D m_PreviousRotation
;
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
);
114 * @return true if the path is valid
119 * Returns true if path doesn't contain nodes
124 * Resets the path state
128 fixed
GetTimescale() const;
130 const TNSpline
& GetTargetSpline() const;
134 TNSpline m_TargetSpline
;
137 #endif // INCLUDED_CINEMAPATH