2009-04-18 19:00:33 +02:00
|
|
|
/* Copyright (C) 2009 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/>.
|
|
|
|
*/
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
//Desc: Contains classes for smooth splines
|
|
|
|
//Borrowed from Game Programming Gems4. (Slightly changed to better suit our purposes
|
|
|
|
//(and compatability). Any references to external material can be found there
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_NUSPLINE
|
|
|
|
#define INCLUDED_NUSPLINE
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
#define MAX_SPLINE_NODES 40
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "Vector3D.h"
|
|
|
|
|
|
|
|
struct SplineData
|
|
|
|
{
|
|
|
|
CVector3D Position;
|
|
|
|
CVector3D Velocity;
|
2007-02-27 03:14:18 +01:00
|
|
|
CVector3D Rotation;
|
|
|
|
float Distance/*, DistanceOffset*/; //DistanceOffset is to keep track of how far into the spline this node is
|
2006-04-24 01:14:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class RNSpline
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
RNSpline() { NodeCount = 0; }
|
2006-08-22 04:24:44 +02:00
|
|
|
virtual ~RNSpline() {}
|
2007-02-27 03:14:18 +01:00
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
void AddNode(const CVector3D &pos);
|
|
|
|
void BuildSpline();
|
2006-08-22 04:24:44 +02:00
|
|
|
CVector3D GetPosition(float time) const;
|
2007-02-27 03:14:18 +01:00
|
|
|
CVector3D GetRotation(float time) const;
|
|
|
|
const std::vector<SplineData>& GetAllNodes() const { return Node; }
|
2006-07-06 05:17:44 +02:00
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
float MaxDistance;
|
|
|
|
int NodeCount;
|
|
|
|
|
|
|
|
protected:
|
2006-07-06 05:17:44 +02:00
|
|
|
std::vector<SplineData> Node;
|
2006-04-24 01:14:18 +02:00
|
|
|
CVector3D GetStartVelocity(int index);
|
|
|
|
CVector3D GetEndVelocity(int index);
|
|
|
|
};
|
|
|
|
|
|
|
|
class SNSpline : public RNSpline
|
|
|
|
{
|
|
|
|
public:
|
2006-08-22 04:24:44 +02:00
|
|
|
virtual ~SNSpline() {}
|
2006-04-24 01:14:18 +02:00
|
|
|
void BuildSpline(){ RNSpline::BuildSpline(); Smooth(); Smooth(); Smooth(); }
|
|
|
|
void Smooth();
|
|
|
|
};
|
|
|
|
|
|
|
|
class TNSpline : public SNSpline
|
|
|
|
{
|
|
|
|
public:
|
2006-08-22 04:24:44 +02:00
|
|
|
virtual ~TNSpline() {}
|
2007-02-27 03:14:18 +01:00
|
|
|
|
|
|
|
void AddNode(const CVector3D& pos, const CVector3D& rotation, float timePeriod);
|
2006-04-24 01:14:18 +02:00
|
|
|
void PushNode() { Node.push_back( SplineData() ); }
|
2007-02-27 03:14:18 +01:00
|
|
|
void InsertNode(const int index, const CVector3D &pos, const CVector3D& rotation, float timePeriod);
|
2006-04-24 01:14:18 +02:00
|
|
|
void RemoveNode(const int index);
|
2006-07-06 05:17:44 +02:00
|
|
|
void UpdateNodeTime(const int index, float time);
|
|
|
|
void UpdateNodePos(const int index, const CVector3D &pos);
|
|
|
|
|
|
|
|
void BuildSpline(){ RNSpline::BuildSpline(); Smooth(); Smooth(); Smooth(); }
|
2006-04-24 01:14:18 +02:00
|
|
|
void Smooth(){ for( int x=0; x<3; x++ ) { SNSpline::Smooth(); Constrain(); } }
|
|
|
|
void Constrain();
|
|
|
|
};
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#endif // INCLUDED_NUSPLINE
|