Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NUSpline.h
Go to the documentation of this file.
1 /* Copyright (C) 2009 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 //Desc: Contains classes for smooth splines
19 //Borrowed from Game Programming Gems4. (Slightly changed to better suit our purposes
20 //(and compatability). Any references to external material can be found there
21 
22 #ifndef INCLUDED_NUSPLINE
23 #define INCLUDED_NUSPLINE
24 
25 #define MAX_SPLINE_NODES 40
26 #include <stdlib.h>
27 #include "Vector3D.h"
28 
29 struct SplineData
30 {
34  float Distance/*, DistanceOffset*/; //DistanceOffset is to keep track of how far into the spline this node is
35 };
36 
37 class RNSpline
38 {
39 public:
40 
41  RNSpline() { NodeCount = 0; }
42  virtual ~RNSpline() {}
43 
44  void AddNode(const CVector3D &pos);
45  void BuildSpline();
46  CVector3D GetPosition(float time) const;
47  CVector3D GetRotation(float time) const;
48  const std::vector<SplineData>& GetAllNodes() const { return Node; }
49 
50  float MaxDistance;
51  int NodeCount;
52 
53 protected:
54  std::vector<SplineData> Node;
55  CVector3D GetStartVelocity(int index);
56  CVector3D GetEndVelocity(int index);
57 };
58 
59 class SNSpline : public RNSpline
60 {
61 public:
62  virtual ~SNSpline() {}
64  void Smooth();
65 };
66 
67 class TNSpline : public SNSpline
68 {
69 public:
70  virtual ~TNSpline() {}
71 
72  void AddNode(const CVector3D& pos, const CVector3D& rotation, float timePeriod);
73  void PushNode() { Node.push_back( SplineData() ); }
74  void InsertNode(const int index, const CVector3D &pos, const CVector3D& rotation, float timePeriod);
75  void RemoveNode(const int index);
76  void UpdateNodeTime(const int index, float time);
77  void UpdateNodePos(const int index, const CVector3D &pos);
78 
80  void Smooth(){ for( int x=0; x<3; x++ ) { SNSpline::Smooth(); Constrain(); } }
81  void Constrain();
82 };
83 
84 #endif // INCLUDED_NUSPLINE
void Smooth()
Definition: NUSpline.h:80
CVector3D GetPosition(float time) const
Definition: NUSpline.cpp:96
CVector3D Position
Definition: NUSpline.h:31
float MaxDistance
Definition: NUSpline.h:50
void BuildSpline()
Definition: NUSpline.h:79
void InsertNode(const int index, const CVector3D &pos, const CVector3D &rotation, float timePeriod)
Definition: NUSpline.cpp:190
void UpdateNodePos(const int index, const CVector3D &pos)
Definition: NUSpline.cpp:231
Definition: wnuma.cpp:46
CVector3D Velocity
Definition: NUSpline.h:32
void RemoveNode(const int index)
Definition: NUSpline.cpp:208
CVector3D GetStartVelocity(int index)
Definition: NUSpline.cpp:123
float Distance
Definition: NUSpline.h:34
int NodeCount
Definition: NUSpline.h:51
virtual ~TNSpline()
Definition: NUSpline.h:70
const std::vector< SplineData > & GetAllNodes() const
Definition: NUSpline.h:48
void UpdateNodeTime(const int index, float time)
Definition: NUSpline.cpp:223
void Smooth()
Definition: NUSpline.cpp:143
CVector3D GetEndVelocity(int index)
Definition: NUSpline.cpp:132
CVector3D GetRotation(float time) const
virtual ~SNSpline()
Definition: NUSpline.h:62
void BuildSpline()
Definition: NUSpline.h:63
void PushNode()
Definition: NUSpline.h:73
void Constrain()
Definition: NUSpline.cpp:239
void AddNode(const CVector3D &pos, const CVector3D &rotation, float timePeriod)
Definition: NUSpline.cpp:166
std::vector< SplineData > Node
Definition: NUSpline.h:54
virtual ~RNSpline()
Definition: NUSpline.h:42
void BuildSpline()
Definition: NUSpline.cpp:68
void AddNode(const CVector3D &pos)
Definition: NUSpline.cpp:49
RNSpline()
Definition: NUSpline.h:41
CVector3D Rotation
Definition: NUSpline.h:33