Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
NUSpline.h
Go to the documentation of this file.
1/* Copyright (C) 2020 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 * Contains classes for smooth splines
20 * Borrowed from Game Programming Gems 4. (Slightly changed to better suit our purposes
21 * and compatability. Any references to external material can be found there.
22 */
23
24#ifndef INCLUDED_NUSPLINE
25#define INCLUDED_NUSPLINE
26
27#define MAX_SPLINE_NODES 128
28
29#include "FixedVector3D.h"
30#include "Vector3D.h"
31
32#include <vector>
33
34/**
35 * Describes a node of the spline
36 */
38{
39 // Should be fixed, because used in the simulation
42 // TODO: make rotation as other spline
44 // Time interval to the previous node, should be 0 for the first node
46};
47
48
49/**
50 * Rounded Nonuniform Spline for describing spatial curves or paths with constant speed
51 */
53{
54public:
55
56 RNSpline();
57 virtual ~RNSpline();
58
59 void AddNode(const CFixedVector3D& pos);
60 void BuildSpline();
61 CVector3D GetPosition(float time) const;
62 CVector3D GetRotation(float time) const;
63 const std::vector<SplineData>& GetAllNodes() const;
64
67
68protected:
69
70 std::vector<SplineData> Node;
71 CVector3D GetStartVelocity(int index);
72 CVector3D GetEndVelocity(int index);
73};
74
75
76/**
77 * Smooth Nonuniform Spline for describing paths with smooth acceleration and deceleration,
78 * but without turning
79 */
80class SNSpline : public RNSpline
81{
82public:
83 virtual ~SNSpline();
84
85 void BuildSpline();
86 void Smooth();
87};
88
89
90/**
91 * Timed Nonuniform Spline for paths with different time intervals between nodes
92 */
93class TNSpline : public SNSpline
94{
95public:
96 virtual ~TNSpline();
97
98 void AddNode(const CFixedVector3D& pos, const CFixedVector3D& rotation, fixed timePeriod);
99 void InsertNode(const int index, const CFixedVector3D& pos, const CFixedVector3D& rotation, fixed timePeriod);
100 void RemoveNode(const int index);
101 void UpdateNodePos(const int index, const CFixedVector3D& pos);
102 void UpdateNodeTime(const int index, fixed time);
103
104 void BuildSpline();
105 void Smooth();
106 void Constrain();
107};
108
109#endif // INCLUDED_NUSPLINE
Definition: FixedVector3D.h:25
A simple fixed-point number class.
Definition: Fixed.h:120
Definition: Vector3D.h:31
Rounded Nonuniform Spline for describing spatial curves or paths with constant speed.
Definition: NUSpline.h:53
CVector3D GetPosition(float time) const
Definition: NUSpline.cpp:105
CVector3D GetRotation(float time) const
virtual ~RNSpline()
std::vector< SplineData > Node
Definition: NUSpline.h:70
fixed MaxDistance
Definition: NUSpline.h:65
const std::vector< SplineData > & GetAllNodes() const
Definition: NUSpline.cpp:137
CVector3D GetEndVelocity(int index)
Definition: NUSpline.cpp:152
void BuildSpline()
Definition: NUSpline.cpp:77
RNSpline()
Definition: NUSpline.cpp:50
CVector3D GetStartVelocity(int index)
Definition: NUSpline.cpp:143
void AddNode(const CFixedVector3D &pos)
Definition: NUSpline.cpp:58
int NodeCount
Definition: NUSpline.h:66
Smooth Nonuniform Spline for describing paths with smooth acceleration and deceleration,...
Definition: NUSpline.h:81
void BuildSpline()
Definition: NUSpline.cpp:164
virtual ~SNSpline()
void Smooth()
Definition: NUSpline.cpp:172
Timed Nonuniform Spline for paths with different time intervals between nodes.
Definition: NUSpline.h:94
void UpdateNodeTime(const int index, fixed time)
Definition: NUSpline.cpp:252
void RemoveNode(const int index)
Definition: NUSpline.cpp:242
void UpdateNodePos(const int index, const CFixedVector3D &pos)
Definition: NUSpline.cpp:260
void AddNode(const CFixedVector3D &pos, const CFixedVector3D &rotation, fixed timePeriod)
Definition: NUSpline.cpp:197
void Constrain()
Definition: NUSpline.cpp:284
void BuildSpline()
Definition: NUSpline.cpp:268
void InsertNode(const int index, const CFixedVector3D &pos, const CFixedVector3D &rotation, fixed timePeriod)
Definition: NUSpline.cpp:222
void Smooth()
Definition: NUSpline.cpp:275
virtual ~TNSpline()
Describes a node of the spline.
Definition: NUSpline.h:38
fixed Distance
Definition: NUSpline.h:45
CFixedVector3D Rotation
Definition: NUSpline.h:43
CVector3D Velocity
Definition: NUSpline.h:41
CFixedVector3D Position
Definition: NUSpline.h:40