AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Movement::Spline< length_type > Class Template Reference

#include "Spline.h"

Inheritance diagram for Movement::Spline< length_type >:
Movement::SplineBase

Public Types

typedef length_type LengthType
 
typedef std::vector< length_type > LengthArray
 
- Public Types inherited from Movement::SplineBase
enum  EvaluationMode {
  ModeLinear ,
  ModeCatmullrom ,
  ModeBezier3_Unused ,
  UninitializedMode ,
  ModesEnd
}
 
typedef int index_type
 
typedef std::vector< Vector3 > ControlArray
 

Public Member Functions

 Spline ()=default
 
void evaluate_percent (float t, Vector3 &c) const
 
void evaluate_derivative (float t, Vector3 &hermite) const
 
void evaluate_percent (index_type Idx, float u, Vector3 &c) const
 
void evaluate_derivative (index_type Idx, float u, Vector3 &c) const
 
index_type computeIndexInBounds (float t) const
 
void computeIndex (float t, index_type &out_idx, float &out_u) const
 
void init_spline (const Vector3 *controls, index_type count, EvaluationMode m)
 
void init_cyclic_spline (const Vector3 *controls, index_type count, EvaluationMode m, index_type cyclic_point)
 
void initLengths ()
 
template<class T >
void initLengths (T &cacher)
 
length_type length () const
 
length_type length (index_type first, index_type last) const
 
length_type length (index_type Idx) const
 
void set_length (index_type i, length_type length)
 
void clear ()
 
- Public Member Functions inherited from Movement::SplineBase
 SplineBase ()=default
 
void evaluate_percent (index_type Idx, float u, Vector3 &c) const
 
void evaluate_derivative (index_type Idx, float u, Vector3 &hermite) const
 
index_type first () const
 
index_type last () const
 
bool empty () const
 
EvaluationMode mode () const
 
bool isCyclic () const
 
const ControlArraygetPoints () const
 
index_type getPointCount () const
 
const Vector3 & getPoint (index_type i) const
 
void init_spline (const Vector3 *controls, index_type count, EvaluationMode m)
 
void init_cyclic_spline (const Vector3 *controls, index_type count, EvaluationMode m, index_type cyclic_point)
 
template<class Init >
void init_spline_custom (Init &initializer)
 
void clear ()
 
float SegLength (index_type i) const
 
std::string ToString () const
 

Protected Member Functions

index_type computeIndexInBounds (length_type length) const
 
- Protected Member Functions inherited from Movement::SplineBase
void EvaluateLinear (index_type, float, Vector3 &) const
 
void EvaluateCatmullRom (index_type, float, Vector3 &) const
 
void EvaluateBezier3 (index_type, float, Vector3 &) const
 
void EvaluateDerivativeLinear (index_type, float, Vector3 &) const
 
void EvaluateDerivativeCatmullRom (index_type, float, Vector3 &) const
 
void EvaluateDerivativeBezier3 (index_type, float, Vector3 &) const
 
float SegLengthLinear (index_type) const
 
float SegLengthCatmullRom (index_type) const
 
float SegLengthBezier3 (index_type) const
 
void InitLinear (const Vector3 *, index_type, bool, index_type)
 
void InitCatmullRom (const Vector3 *, index_type, bool, index_type)
 
void InitBezier3 (const Vector3 *, index_type, bool, index_type)
 
void UninitializedSplineEvaluationMethod (index_type, float, Vector3 &) const
 
float UninitializedSplineSegLenghtMethod (index_type) const
 
void UninitializedSplineInitMethod (Vector3 const *, index_type, bool, index_type)
 

Protected Attributes

LengthArray lengths
 
- Protected Attributes inherited from Movement::SplineBase
ControlArray points
 
index_type index_lo {0}
 
index_type index_hi {0}
 
uint8 m_mode {UninitializedMode}
 
bool cyclic {false}
 

Additional Inherited Members

- Protected Types inherited from Movement::SplineBase
enum  { STEPS_PER_SEGMENT = 3 }
 
typedef void(SplineBase::* EvaluationMethtod) (index_type, float, Vector3 &) const
 
typedef float(SplineBase::* SegLenghtMethtod) (index_type) const
 
typedef void(SplineBase::* InitMethtod) (const Vector3 *, index_type, bool, index_type)
 
- Static Protected Attributes inherited from Movement::SplineBase
static EvaluationMethtod evaluators [ModesEnd]
 
static EvaluationMethtod derivative_evaluators [ModesEnd]
 
static SegLenghtMethtod seglengths [ModesEnd]
 
static InitMethtod initializers [ModesEnd]
 

Detailed Description

template<typename length_type>
class Movement::Spline< length_type >

Member Typedef Documentation

◆ LengthArray

template<typename length_type >
typedef std::vector<length_type> Movement::Spline< length_type >::LengthArray

◆ LengthType

template<typename length_type >
typedef length_type Movement::Spline< length_type >::LengthType

Constructor & Destructor Documentation

◆ Spline()

template<typename length_type >
Movement::Spline< length_type >::Spline ( )
explicitdefault

Member Function Documentation

◆ clear()

template<typename length_type >
void Movement::Spline< length_type >::clear
91 {
93 lengths.clear();
94 }
void clear()
Definition: Spline.cpp:284
LengthArray lengths
Definition: Spline.h:144

References Movement::SplineBase::clear().

Referenced by Movement::MoveSpline::Initialize().

◆ computeIndex()

template<typename length_type >
void Movement::Spline< length_type >::computeIndex ( float  t,
index_type out_idx,
float &  out_u 
) const
64 {
65 ASSERT(t >= 0.f && t <= 1.f);
66 length_type length_ = t * length();
67 index = computeIndexInBounds(length_);
68 ASSERT(index < index_hi);
69 u = (length_ - length(index)) / (float)length(index, index + 1);
70 }
#define ASSERT
Definition: Errors.h:68
index_type index_hi
Definition: Spline.h:47
index_type computeIndexInBounds(length_type length) const
Definition: SplineImpl.h:36
length_type length() const
Definition: Spline.h:200

References ASSERT.

◆ computeIndexInBounds() [1/2]

template<typename length_type >
SplineBase::index_type Movement::Spline< length_type >::computeIndexInBounds ( float  t) const
73 {
74 ASSERT(t >= 0.f && t <= 1.f);
75 return computeIndexInBounds(t * length());
76 }

References ASSERT.

◆ computeIndexInBounds() [2/2]

template<typename length_type >
SplineBase::index_type Movement::Spline< length_type >::computeIndexInBounds ( length_type  length) const
protected
37 {
38 // Temporary disabled: causes infinite loop with t = 1.f
39 /*
40 index_type hi = index_hi;
41 index_type lo = index_lo;
42
43 index_type i = lo + (float)(hi - lo) * t;
44
45 while ((lengths[i] > length) || (lengths[i + 1] <= length))
46 {
47 if (lengths[i] > length)
48 hi = i - 1; // too big
49 else if (lengths[i + 1] <= length)
50 lo = i + 1; // too small
51
52 i = (hi + lo) / 2;
53 }*/
54
57 while (i + 1 < N && lengths[i + 1] < length_)
58 ++i;
59
60 return i;
61 }
int index_type
Definition: Spline.h:31
index_type index_lo
Definition: Spline.h:46

◆ evaluate_derivative() [1/2]

template<typename length_type >
void Movement::Spline< length_type >::evaluate_derivative ( float  t,
Vector3 &  hermite 
) const

Calculates derivation for given t

Parameters
t- percent of spline's length, assumes that t in range [0, 1].
29 {
30 index_type Index;
31 float u;
32 computeIndex(t, Index, u);
33 evaluate_derivative(Index, u, hermite);
34 }
void computeIndex(float t, index_type &out_idx, float &out_u) const
Definition: SplineImpl.h:63
void evaluate_derivative(float t, Vector3 &hermite) const
Definition: SplineImpl.h:28

Referenced by Movement::MoveSpline::ComputePosition(), and TransportMgr::GeneratePath().

◆ evaluate_derivative() [2/2]

template<typename length_type >
void Movement::Spline< length_type >::evaluate_derivative ( index_type  Idx,
float  u,
Vector3 &  c 
) const
inline

Caclulates derivation for index Idx, and percent of segment length t

Parameters
Idx- spline segment index, should be in range [first, last)
t- percent of spline segment length, assumes that t in range [0, 1].
void evaluate_derivative(index_type Idx, float u, Vector3 &hermite) const
Definition: Spline.h:103

References Movement::SplineBase::evaluate_derivative().

◆ evaluate_percent() [1/2]

template<typename length_type >
void Movement::Spline< length_type >::evaluate_percent ( float  t,
Vector3 &  c 
) const

Calculates the position for given t

Parameters
t- percent of spline's length, assumes that t in range [0, 1].
21 {
22 index_type Index;
23 float u;
24 computeIndex(t, Index, u);
25 evaluate_percent(Index, u, c);
26 }
void evaluate_percent(float t, Vector3 &c) const
Definition: SplineImpl.h:20

Referenced by Movement::MoveSpline::ComputePosition().

◆ evaluate_percent() [2/2]

template<typename length_type >
void Movement::Spline< length_type >::evaluate_percent ( index_type  Idx,
float  u,
Vector3 &  c 
) const
inline

Calculates the position for given segment Idx, and percent of segment length t

Parameters
t= partial_segment_length / whole_segment_length
Idx- spline segment index, should be in range [first, last).
161{ SplineBase::evaluate_percent(Idx, u, c);}
void evaluate_percent(index_type Idx, float u, Vector3 &c) const
Definition: Spline.h:97

References Movement::SplineBase::evaluate_percent().

◆ init_cyclic_spline()

template<typename length_type >
void Movement::Spline< length_type >::init_cyclic_spline ( const Vector3 *  controls,
index_type  count,
EvaluationMode  m,
index_type  cyclic_point 
)
inline
174{ SplineBase::init_cyclic_spline(controls, count, m, cyclic_point);}
void init_cyclic_spline(const Vector3 *controls, index_type count, EvaluationMode m, index_type cyclic_point)
Definition: Spline.cpp:210

References Movement::SplineBase::init_cyclic_spline().

Referenced by Movement::MoveSpline::init_spline().

◆ init_spline()

template<typename length_type >
void Movement::Spline< length_type >::init_spline ( const Vector3 *  controls,
index_type  count,
EvaluationMode  m 
)
inline

Initializes spline. Don't call other methods while spline not initialized.

173{ SplineBase::init_spline(controls, count, m);}
void init_spline(const Vector3 *controls, index_type count, EvaluationMode m)
Definition: Spline.cpp:202

References Movement::SplineBase::init_spline().

Referenced by TransportMgr::GeneratePath(), and Movement::MoveSpline::init_spline().

◆ initLengths() [1/2]

template<typename length_type >
void Movement::Spline< length_type >::initLengths

Initializes lengths with SplineBase::SegLength method.

79 {
81 length_type length = 0;
82 lengths.resize(index_hi + 1);
83 while (i < index_hi)
84 {
85 length += SegLength(i);
86 lengths[++i] = length;
87 }
88 }
float SegLength(index_type i) const
Definition: Spline.h:132

Referenced by TransportMgr::GeneratePath(), and Movement::MoveSpline::init_spline().

◆ initLengths() [2/2]

template<typename length_type >
template<class T >
void Movement::Spline< length_type >::initLengths ( T &  cacher)
inline

Initializes lengths in some custom way Note that value returned by cacher must be greater or equal to previous value.

182 {
184 lengths.resize(index_hi + 1);
185 length_type prev_length = 0, new_length = 0;
186 while (i < index_hi)
187 {
188 new_length = cacher(*this, i);
189 // length overflowed, assign to max positive value
190 if (new_length < 0)
191 new_length = std::numeric_limits<length_type>::max();
192 lengths[++i] = new_length;
193
194 ASSERT(prev_length <= new_length);
195 prev_length = new_length;
196 }
197 }

References ASSERT, Movement::SplineBase::index_hi, Movement::SplineBase::index_lo, and Movement::Spline< length_type >::lengths.

◆ length() [1/3]

◆ length() [2/3]

template<typename length_type >
length_type Movement::Spline< length_type >::length ( index_type  first,
index_type  last 
) const
inline

Returns length between given nodes.

202{ return lengths[last] - lengths[first];}
index_type first() const
Definition: Spline.h:106
index_type last() const
Definition: Spline.h:107

References Movement::SplineBase::first(), Movement::SplineBase::last(), and Movement::Spline< length_type >::lengths.

◆ length() [3/3]

template<typename length_type >
length_type Movement::Spline< length_type >::length ( index_type  Idx) const
inline
203{ return lengths[Idx];}

References Movement::Spline< length_type >::lengths.

◆ set_length()

template<typename length_type >
void Movement::Spline< length_type >::set_length ( index_type  i,
length_type  length 
)
inline

Member Data Documentation

◆ lengths