Pyrogenesis  trunk
NUSpline.h
Go to the documentation of this file.
1 /* Copyright (C) 2016 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 /**
33  * Describes a node of the spline
34  */
35 struct SplineData
36 {
37  // Should be fixed, because used in the simulation
40  // TODO: make rotation as other spline
42  // Time interval to the previous node, should be 0 for the first node
44 };
45 
46 
47 /**
48  * Rounded Nonuniform Spline for describing spatial curves or paths with constant speed
49  */
50 class RNSpline
51 {
52 public:
53 
54  RNSpline();
55  virtual ~RNSpline();
56 
57  void AddNode(const CFixedVector3D& pos);
58  void BuildSpline();
59  CVector3D GetPosition(float time) const;
60  CVector3D GetRotation(float time) const;
61  const std::vector<SplineData>& GetAllNodes() const;
62 
64  int NodeCount;
65 
66 protected:
67 
68  std::vector<SplineData> Node;
69  CVector3D GetStartVelocity(int index);
70  CVector3D GetEndVelocity(int index);
71 };
72 
73 
74 /**
75  * Smooth Nonuniform Spline for describing paths with smooth acceleration and deceleration,
76  * but without turning
77  */
78 class SNSpline : public RNSpline
79 {
80 public:
81  virtual ~SNSpline();
82 
83  void BuildSpline();
84  void Smooth();
85 };
86 
87 
88 /**
89  * Timed Nonuniform Spline for paths with different time intervals between nodes
90  */
91 class TNSpline : public SNSpline
92 {
93 public:
94  virtual ~TNSpline();
95 
96  void AddNode(const CFixedVector3D& pos, const CFixedVector3D& rotation, fixed timePeriod);
97  void InsertNode(const int index, const CFixedVector3D& pos, const CFixedVector3D& rotation, fixed timePeriod);
98  void RemoveNode(const int index);
99  void UpdateNodePos(const int index, const CFixedVector3D& pos);
100  void UpdateNodeTime(const int index, fixed time);
101 
102  void BuildSpline();
103  void Smooth();
104  void Constrain();
105 };
106 
107 #endif // INCLUDED_NUSPLINE
A simple fixed-point number class.
Definition: Fixed.h:115
Describes a node of the spline.
Definition: NUSpline.h:35
fixed Distance
Definition: NUSpline.h:43
Rounded Nonuniform Spline for describing spatial curves or paths with constant speed.
Definition: NUSpline.h:50
Definition: Vector3D.h:28
CVector3D Velocity
Definition: NUSpline.h:39
CFixedVector3D Position
Definition: NUSpline.h:38
int NodeCount
Definition: NUSpline.h:64
Timed Nonuniform Spline for paths with different time intervals between nodes.
Definition: NUSpline.h:91
CFixedVector3D Rotation
Definition: NUSpline.h:41
Definition: FixedVector3D.h:24
Smooth Nonuniform Spline for describing paths with smooth acceleration and deceleration, but without turning.
Definition: NUSpline.h:78
fixed MaxDistance
Definition: NUSpline.h:63
std::vector< SplineData > Node
Definition: NUSpline.h:68
static SVec3 GetPosition(const SMikkTSpaceContext *pContext, const int index)
Definition: mikktspace.cpp:897
static Node * AddNode()
Definition: wnuma.cpp:59