File: CinemaPath.h

package info (click to toggle)
0ad 0.0.23.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 78,292 kB
  • sloc: cpp: 245,166; ansic: 200,249; python: 13,754; sh: 6,104; perl: 4,620; makefile: 977; xml: 810; java: 533; ruby: 229; erlang: 46; pascal: 30; sql: 21; tcl: 4
file content (135 lines) | stat: -rw-r--r-- 3,510 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* Copyright (C) 2017 Wildfire Games.
 * This file is part of 0 A.D.
 *
 * 0 A.D. is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * 0 A.D. is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef INCLUDED_CINEMAPATH
#define INCLUDED_CINEMAPATH

#include "maths/NUSpline.h"
#include "ps/CStr.h"

class CVector3D;
class CCamera;

class CCinemaData
{
public:
	CCinemaData() : m_LookAtTarget(false), m_GrowthCount(0), m_Growth(1), m_Switch(1), m_Timescale(fixed::FromInt(1)) {}
	virtual ~CCinemaData() {}

	const CCinemaData* GetData() const { return this; }

	CStrW m_Name;
	CStrW m_Orientation;
	CStrW m_Mode;
	CStrW m_Style;

	bool m_LookAtTarget;

	fixed m_Timescale; // a negative timescale results in backwards play

	// Distortion variables
	mutable float m_GrowthCount;
	float m_Growth;
	float m_Switch;
};


// Once the data is part of the path, it shouldn't be changeable, so use private inheritance.
// This class encompasses the spline and the information which determines how the path will operate
// and also provides the functionality for doing so

class CCinemaPath : private CCinemaData, public TNSpline
{
public:
	CCinemaPath() : m_TimeElapsed(0), m_PreviousNodeTime(0) {}
	CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline);

	// Sets camera position to calculated point on spline
	void MoveToPointAt(float t, float nodet, const CVector3D& startRotation, CCamera* camera) const;

	// Distortion mode functions-change how ratio is passed to distortion style functions
	float EaseIn(float t) const;
	float EaseOut(float t) const;
	float EaseInOut(float t) const;
	float EaseOutIn(float t) const;

	// Distortion style functions
	float EaseDefault(float t) const;
	float EaseGrowth(float t) const;
	float EaseExpo(float t) const;
	float EaseCircle(float t) const;
	float EaseSine(float t) const;

	float (CCinemaPath::*DistStylePtr)(float ratio) const;
	float (CCinemaPath::*DistModePtr)(float ratio) const;

	const CCinemaData* GetData() const;

public:

	CVector3D GetNodePosition(const int index) const;
	fixed GetNodeDuration(const int index) const;
	fixed GetDuration() const;

	float GetNodeFraction() const;
	float GetElapsedTime() const;

	const CStrW& GetName() const;

	void SetTimescale(fixed scale);

	float m_TimeElapsed;
	float m_PreviousNodeTime; // How much time has passed before the current node

	size_t m_CurrentNode;
	CVector3D m_PreviousRotation;

public:

	/**
	 * Returns false if finished.
	 * @param deltaRealTime Elapsed real time since the last frame.
	 * @param camera An affected camera
	 */
	bool Play(const float deltaRealTime, CCamera* camera);

	/**
	 * Validate the path
	 * @return true if the path is valid
	 */
	bool Validate();

	/**
	 * Returns true if path doesn't contain nodes
	 */
	bool Empty() const;

	/**
	 * Resets the path state
	 */
	void Reset();

	fixed GetTimescale() const;

	const TNSpline& GetTargetSpline() const;

private:

	TNSpline m_TargetSpline;
};

#endif // INCLUDED_CINEMAPATH