TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Movement::Spline< length_type > Class Template Reference

#include <Spline.h>

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< Vector3ControlArray
 

Public Member Functions

 Spline ()
 
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 ()
 

Protected Member Functions

index_type computeIndexInBounds (length_type length) const
 

Protected Attributes

LengthArray lengths
 
- Protected Attributes inherited from Movement::SplineBase
ControlArray points
 
index_type index_lo
 
index_type index_hi
 
uint8 m_mode
 
bool cyclic
 

Additional Inherited Members

- Protected Types inherited from Movement::SplineBase
enum  { STEPS_PER_SEGMENT = 3 }
 

Member Typedef Documentation

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

Constructor & Destructor Documentation

template<typename length_type>
Movement::Spline< length_type >::Spline ( )
inlineexplicit
147 { }

Member Function Documentation

template<typename length_type >
void Movement::Spline< length_type >::clear ( )
92 {
93  SplineBase::clear();
94  lengths.clear();
95 }
LengthArray lengths
Definition: Spline.h:142

+ Here is the caller graph for this function:

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

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

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].
30 {
31  index_type Index;
32  float u;
33  computeIndex(t, Index, u);
34  evaluate_derivative(Index, u, hermite);
35 }
void computeIndex(float t, index_type &out_idx, float &out_u) const
Definition: SplineImpl.h:64
int index_type
Definition: Spline.h:31
void evaluate_derivative(float t, Vector3 &hermite) const
Definition: SplineImpl.h:29

+ Here is the caller graph for this function:

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].
165 { SplineBase::evaluate_derivative(Idx, u, c);}
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].
22 {
23  index_type Index;
24  float u;
25  computeIndex(t, Index, u);
26  evaluate_percent(Index, u, c);
27 }
void evaluate_percent(float t, Vector3 &c) const
Definition: SplineImpl.h:21
void computeIndex(float t, index_type &out_idx, float &out_u) const
Definition: SplineImpl.h:64
int index_type
Definition: Spline.h:31

+ Here is the caller graph for this function:

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).
160 { SplineBase::evaluate_percent(Idx, u, c);}
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
173 { SplineBase::init_cyclic_spline(controls, count, m, cyclic_point);}

+ Here is the caller graph for this function:

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.

172 { SplineBase::init_spline(controls, count, m);}

+ Here is the caller graph for this function:

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

Initializes lengths with SplineBase::SegLength method.

80 {
81  index_type i = index_lo;
82  length_type length = 0;
83  lengths.resize(index_hi+1);
84  while (i < index_hi)
85  {
86  length += SegLength(i);
87  lengths[++i] = length;
88  }
89 }
LengthArray lengths
Definition: Spline.h:142
length_type length() const
Definition: Spline.h:199
int index_type
Definition: Spline.h:31
index_type index_lo
Definition: Spline.h:46
index_type index_hi
Definition: Spline.h:47

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

181  {
182  index_type i = index_lo;
183  lengths.resize(index_hi+1);
184  length_type prev_length = 0, new_length = 0;
185  while (i < index_hi)
186  {
187  new_length = cacher(*this, i);
188  // length overflowed, assign to max positive value
189  if (new_length < 0)
191  lengths[++i] = new_length;
192 
193  ASSERT(prev_length <= new_length);
194  prev_length = new_length;
195  }
196  }
T max(const T &x, const T &y)
Definition: g3dmath.h:320
LengthArray lengths
Definition: Spline.h:142
int index_type
Definition: Spline.h:31
index_type index_lo
Definition: Spline.h:46
index_type index_hi
Definition: Spline.h:47
#define ASSERT
Definition: Errors.h:55
template<typename length_type>
length_type Movement::Spline< length_type >::length ( ) const
inline

Returns length of the whole spline.

199 { return lengths[index_hi];}
LengthArray lengths
Definition: Spline.h:142
index_type index_hi
Definition: Spline.h:47

+ Here is the caller graph for this function:

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

Returns length between given nodes.

201 { return lengths[last]-lengths[first];}
LengthArray lengths
Definition: Spline.h:142
template<typename length_type>
length_type Movement::Spline< length_type >::length ( index_type  Idx) const
inline
202 { return lengths[Idx];}
LengthArray lengths
Definition: Spline.h:142
template<typename length_type>
void Movement::Spline< length_type >::set_length ( index_type  i,
length_type  length 
)
inline
204 { lengths[i] = length;}
LengthArray lengths
Definition: Spline.h:142
length_type length() const
Definition: Spline.h:199

+ Here is the caller graph for this function:

Member Data Documentation

template<typename length_type>
LengthArray Movement::Spline< length_type >::lengths
protected

The documentation for this class was generated from the following files: