Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
NUSpline.h
Go to the documentation of this file.
1/* Copyright (C) 2026 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 "maths/Fixed.h"
30#include "maths/FixedVector3D.h"
31#include "maths/Vector3D.h"
32
33#include <vector>
34
35/**
36 * Describes a node of the spline
37 */
39{
40 // Should be fixed, because used in the simulation
43 // TODO: make rotation as other spline
45 // Time interval to the previous node, should be 0 for the first node
47};
48
49
50/**
51 * Rounded Nonuniform Spline for describing spatial curves or paths with constant speed
52 */
54{
55public:
56
58 virtual ~RNSpline();
59
60 void AddNode(const CFixedVector3D& pos);
61 void BuildSpline();
62 CVector3D GetPosition(float time) const;
63 CVector3D GetRotation(float time) const;
64 const std::vector<SplineData>& GetAllNodes() const;
65
67
68protected:
71 std::vector<SplineData> m_Nodes;
72 CVector3D GetStartVelocity(int index);
73 CVector3D GetEndVelocity(int index);
74};
75
76
77/**
78 * Smooth Nonuniform Spline for describing paths with smooth acceleration and deceleration,
79 * but without turning
80 */
81class SNSpline : public RNSpline
82{
83public:
84 virtual ~SNSpline();
85
86 void BuildSpline();
87 void Smooth();
88};
89
90
91/**
92 * Timed Nonuniform Spline for paths with different time intervals between nodes
93 */
94class TNSpline : public SNSpline
95{
96public:
97 virtual ~TNSpline();
98
99 void AddNode(const CFixedVector3D& pos, const CFixedVector3D& rotation, fixed timePeriod);
100 void InsertNode(const int index, const CFixedVector3D& pos, const CFixedVector3D& rotation, fixed timePeriod);
101 void RemoveNode(const int index);
102 void UpdateNodePos(const int index, const CFixedVector3D& pos);
103 void UpdateNodeTime(const int index, fixed time);
104
105 void BuildSpline();
106 void Smooth();
107 void Constrain();
108};
109
110#endif // INCLUDED_NUSPLINE
Definition: FixedVector3D.h:25
A simple fixed-point number class.
Definition: Fixed.h:129
Definition: Vector3D.h:32
Rounded Nonuniform Spline for describing spatial curves or paths with constant speed.
Definition: NUSpline.h:54
fixed GetMaxDistance() const
Definition: NUSpline.h:66
CVector3D GetPosition(float time) const
Definition: NUSpline.cpp:107
CVector3D GetRotation(float time) const
virtual ~RNSpline()
const std::vector< SplineData > & GetAllNodes() const
Definition: NUSpline.cpp:139
CVector3D GetEndVelocity(int index)
Definition: NUSpline.cpp:154
std::vector< SplineData > m_Nodes
Definition: NUSpline.h:71
int m_NodeCount
Definition: NUSpline.h:70
void BuildSpline()
Definition: NUSpline.cpp:79
fixed m_MaxDistance
Definition: NUSpline.h:69
CVector3D GetStartVelocity(int index)
Definition: NUSpline.cpp:145
void AddNode(const CFixedVector3D &pos)
Definition: NUSpline.cpp:60
Smooth Nonuniform Spline for describing paths with smooth acceleration and deceleration,...
Definition: NUSpline.h:82
void BuildSpline()
Definition: NUSpline.cpp:166
virtual ~SNSpline()
void Smooth()
Definition: NUSpline.cpp:174
Timed Nonuniform Spline for paths with different time intervals between nodes.
Definition: NUSpline.h:95
void UpdateNodeTime(const int index, fixed time)
Definition: NUSpline.cpp:257
void RemoveNode(const int index)
Definition: NUSpline.cpp:245
void UpdateNodePos(const int index, const CFixedVector3D &pos)
Definition: NUSpline.cpp:265
void AddNode(const CFixedVector3D &pos, const CFixedVector3D &rotation, fixed timePeriod)
Definition: NUSpline.cpp:199
void Constrain()
Definition: NUSpline.cpp:289
void BuildSpline()
Definition: NUSpline.cpp:273
void InsertNode(const int index, const CFixedVector3D &pos, const CFixedVector3D &rotation, fixed timePeriod)
Definition: NUSpline.cpp:224
void Smooth()
Definition: NUSpline.cpp:280
virtual ~TNSpline()
Describes a node of the spline.
Definition: NUSpline.h:39
fixed Distance
Definition: NUSpline.h:46
CFixedVector3D Rotation
Definition: NUSpline.h:44
CVector3D Velocity
Definition: NUSpline.h:42
CFixedVector3D Position
Definition: NUSpline.h:41