19 #ifndef TRINITYSERVER_SPLINE_H
20 #define TRINITYSERVER_SPLINE_H
59 static_assert(
STEPS_PER_SEGMENT > 0,
"STEPS_PER_SEGMENT shouldn't be lesser than 1");
62 void EvaluateLinear(index_type,
float,
Vector3&)
const;
63 void EvaluateCatmullRom(index_type,
float,
Vector3&)
const;
64 void EvaluateBezier3(index_type,
float,
Vector3&)
const;
66 static EvaluationMethtod evaluators[
ModesEnd];
68 void EvaluateDerivativeLinear(index_type,
float,
Vector3&)
const;
69 void EvaluateDerivativeCatmullRom(index_type,
float,
Vector3&)
const;
70 void EvaluateDerivativeBezier3(index_type,
float,
Vector3&)
const;
71 static EvaluationMethtod derivative_evaluators[
ModesEnd];
73 float SegLengthLinear(index_type)
const;
74 float SegLengthCatmullRom(index_type)
const;
75 float SegLengthBezier3(index_type)
const;
77 static SegLenghtMethtod seglengths[
ModesEnd];
79 void InitLinear(
const Vector3*, index_type, index_type);
80 void InitCatmullRom(
const Vector3*, index_type, index_type);
81 void InitBezier3(
const Vector3*, index_type, index_type);
83 static InitMethtod initializers[
ModesEnd];
85 void UninitializedSpline()
const {
ABORT();}
95 void evaluate_percent(index_type Idx,
float u, Vector3& c)
const {(this->*evaluators[
m_mode])(Idx, u, c);}
101 void evaluate_derivative(index_type Idx,
float u, Vector3& hermite)
const {(this->*derivative_evaluators[
m_mode])(Idx, u, hermite);}
104 index_type first()
const {
return index_lo;}
105 index_type last()
const {
return index_hi;}
107 bool empty()
const {
return index_lo ==
index_hi;}
109 bool isCyclic()
const {
return cyclic;}
111 const ControlArray& getPoints()
const {
return points; }
112 index_type getPointCount()
const {
return index_type(points.size()); }
113 const Vector3& getPoint(index_type i)
const {
return points[i]; }
116 void init_spline(
const Vector3 * controls, index_type count,
EvaluationMode m);
117 void init_cyclic_spline(
const Vector3 * controls, index_type count,
EvaluationMode m, index_type cyclic_point);
121 template<
class Init>
inline void init_spline_custom(Init& initializer)
123 initializer(m_mode, cyclic, points, index_lo, index_hi);
129 float SegLength(index_type i)
const {
return (this->*seglengths[m_mode])(i);}
134 template<
typename length_type>
160 void evaluate_percent(index_type Idx,
float u, Vector3& c)
const { SplineBase::evaluate_percent(Idx, u, c);}
165 void evaluate_derivative(index_type Idx,
float u, Vector3& c)
const { SplineBase::evaluate_derivative(Idx, u, c);}
169 void computeIndex(
float t, index_type& out_idx,
float& out_u)
const;
173 void init_cyclic_spline(
const Vector3 * controls, index_type count,
EvaluationMode m, index_type cyclic_point) { SplineBase::init_cyclic_spline(controls, count, m, cyclic_point);}
183 lengths.resize(index_hi+1);
184 length_type prev_length = 0, new_length = 0;
187 new_length = cacher(*
this, i);
191 lengths[++i] = new_length;
193 ASSERT(prev_length <= new_length);
194 prev_length = new_length;
201 length_type
length(index_type first, index_type last)
const {
return lengths[last]-lengths[first];}
202 length_type
length(index_type Idx)
const {
return lengths[Idx];}
212 #endif // TRINITYSERVER_SPLINE_H
length_type length(index_type first, index_type last) const
Definition: Spline.h:201
void init_spline(const Vector3 *controls, index_type count, EvaluationMode m)
Definition: Spline.h:172
void initLengths()
Definition: SplineImpl.h:79
void evaluate_percent(float t, Vector3 &c) const
Definition: SplineImpl.h:21
EvaluationMode
Definition: Spline.h:34
length_type LengthType
Definition: Spline.h:138
void computeIndex(float t, index_type &out_idx, float &out_u) const
Definition: SplineImpl.h:64
#define false
Definition: CascPort.h:18
void initLengths(T &cacher)
Definition: Spline.h:180
uint8 m_mode
Definition: Spline.h:49
T max(const T &x, const T &y)
Definition: g3dmath.h:320
std::vector< Vector3 > ControlArray
Definition: Spline.h:32
LengthArray lengths
Definition: Spline.h:142
void evaluate_derivative(index_type Idx, float u, Vector3 &c) const
Definition: Spline.h:165
string ToString(int i)
Definition: strutil.h:491
length_type length() const
Definition: Spline.h:199
void evaluate_percent(index_type Idx, float u, Vector3 &c) const
Definition: Spline.h:160
void init_cyclic_spline(const Vector3 *controls, index_type count, EvaluationMode m, index_type cyclic_point)
Definition: Spline.h:173
Spline()
Definition: Spline.h:147
int index_type
Definition: Spline.h:31
index_type index_lo
Definition: Spline.h:46
ControlArray points
Definition: Spline.h:44
length_type length(index_type Idx) const
Definition: Spline.h:202
bool cyclic
Definition: Spline.h:50
index_type index_hi
Definition: Spline.h:47
void set_length(index_type i, length_type length)
Definition: Spline.h:204
#define ABORT
Definition: Errors.h:56
uint8_t uint8
Definition: Define.h:152
#define ASSERT
Definition: Errors.h:55
void clear()
Definition: SplineImpl.h:91
index_type computeIndexInBounds(length_type length) const
Definition: SplineImpl.h:37
std::vector< length_type > LengthArray
Definition: Spline.h:139
void evaluate_derivative(float t, Vector3 &hermite) const
Definition: SplineImpl.h:29