AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Movement::SplineBase Class Reference

#include "Spline.h"

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

Public Types

enum  EvaluationMode {
  ModeLinear ,
  ModeCatmullrom ,
  ModeBezier3_Unused ,
  UninitializedMode ,
  ModesEnd
}
 
typedef int index_type
 
typedef std::vector< Vector3 > ControlArray
 

Public Member Functions

 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 Types

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)
 

Protected Member Functions

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

ControlArray points
 
index_type index_lo {0}
 
index_type index_hi {0}
 
uint8 m_mode {UninitializedMode}
 
bool cyclic {false}
 

Static Protected Attributes

static EvaluationMethtod evaluators [ModesEnd]
 
static EvaluationMethtod derivative_evaluators [ModesEnd]
 
static SegLenghtMethtod seglengths [ModesEnd]
 
static InitMethtod initializers [ModesEnd]
 

Detailed Description

Member Typedef Documentation

◆ ControlArray

typedef std::vector<Vector3> Movement::SplineBase::ControlArray

◆ EvaluationMethtod

typedef void(SplineBase::* Movement::SplineBase::EvaluationMethtod) (index_type, float, Vector3 &) const
protected

◆ index_type

◆ InitMethtod

typedef void(SplineBase::* Movement::SplineBase::InitMethtod) (const Vector3 *, index_type, bool, index_type)
protected

◆ SegLenghtMethtod

typedef float(SplineBase::* Movement::SplineBase::SegLenghtMethtod) (index_type) const
protected

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected
Enumerator
STEPS_PER_SEGMENT 
53 {
54 // could be modified, affects segment length evaluation precision
55 // lesser value saves more performance in cost of lover precision
56 // minimal value is 1
57 // client's value is 20, blizzs use 2-3 steps to compute length
59 };
@ STEPS_PER_SEGMENT
Definition: Spline.h:58

◆ EvaluationMode

Enumerator
ModeLinear 
ModeCatmullrom 
ModeBezier3_Unused 
UninitializedMode 
ModesEnd 
35 {
41 };
@ ModeCatmullrom
Definition: Spline.h:37
@ ModesEnd
Definition: Spline.h:40
@ ModeBezier3_Unused
Definition: Spline.h:38
@ UninitializedMode
Definition: Spline.h:39
@ ModeLinear
Definition: Spline.h:36

Constructor & Destructor Documentation

◆ SplineBase()

Movement::SplineBase::SplineBase ( )
explicitdefault

Member Function Documentation

◆ clear()

void Movement::SplineBase::clear ( )
285 {
286 index_lo = 0;
287 index_hi = 0;
288 points.clear();
289 }
ControlArray points
Definition: Spline.h:44
index_type index_hi
Definition: Spline.h:47
index_type index_lo
Definition: Spline.h:46

References index_hi, index_lo, and points.

Referenced by Movement::Spline< length_type >::clear().

◆ empty()

bool Movement::SplineBase::empty ( ) const
inline
109{ return index_lo == index_hi;}

References index_hi, and index_lo.

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

◆ evaluate_derivative()

void Movement::SplineBase::evaluate_derivative ( index_type  Idx,
float  u,
Vector3 &  hermite 
) const
inline

Caclulates derivation in 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]
103{(this->*derivative_evaluators[m_mode])(Idx, u, hermite);}
uint8 m_mode
Definition: Spline.h:49
static EvaluationMethtod derivative_evaluators[ModesEnd]
Definition: Spline.h:72

References m_mode.

Referenced by Movement::Spline< length_type >::evaluate_derivative().

◆ evaluate_percent()

void Movement::SplineBase::evaluate_percent ( index_type  Idx,
float  u,
Vector3 &  c 
) const
inline

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

Parameters
t- percent of segment length, assumes that t in range [0, 1]
Idx- spline segment index, should be in range [first, last)
97{(this->*evaluators[m_mode])(Idx, u, c);}
static EvaluationMethtod evaluators[ModesEnd]
Definition: Spline.h:67

References m_mode.

Referenced by Movement::Spline< length_type >::evaluate_percent().

◆ EvaluateBezier3()

void Movement::SplineBase::EvaluateBezier3 ( index_type  index,
float  t,
Vector3 &  result 
) const
protected
128 {
129 index *= 3u;
130 ASSERT(index >= index_lo && index < index_hi);
131 C_Evaluate(&points[index], t, s_Bezier3Coeffs, result);
132 }
#define ASSERT
Definition: Errors.h:68
void C_Evaluate(const Vector3 *vertice, float t, const Matrix4 &matr, Vector3 &result)
Definition: Spline.cpp:97
static const Matrix4 s_Bezier3Coeffs(-1.f, 3.f, -3.f, 1.f, 3.f, -6.f, 3.f, 0.f, -3.f, 3.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f)

References ASSERT, Movement::C_Evaluate(), index_hi, index_lo, points, and Movement::s_Bezier3Coeffs().

◆ EvaluateCatmullRom()

void Movement::SplineBase::EvaluateCatmullRom ( index_type  index,
float  t,
Vector3 &  result 
) const
protected
122 {
123 ASSERT(index >= index_lo && index < index_hi);
124 C_Evaluate(&points[index - 1], t, s_catmullRomCoeffs, result);
125 }
static const Matrix4 s_catmullRomCoeffs(-0.5f, 1.5f, -1.5f, 0.5f, 1.f, -2.5f, 2.f, -0.5f, -0.5f, 0.f, 0.5f, 0.f, 0.f, 1.f, 0.f, 0.f)

References ASSERT, Movement::C_Evaluate(), index_hi, index_lo, points, and Movement::s_catmullRomCoeffs().

◆ EvaluateDerivativeBezier3()

void Movement::SplineBase::EvaluateDerivativeBezier3 ( index_type  index,
float  t,
Vector3 &  result 
) const
protected
147 {
148 index *= 3u;
149 ASSERT(index >= index_lo && index < index_hi);
150 C_Evaluate_Derivative(&points[index], t, s_Bezier3Coeffs, result);
151 }
void C_Evaluate_Derivative(const Vector3 *vertice, float t, const Matrix4 &matr, Vector3 &result)
Definition: Spline.cpp:106

References ASSERT, Movement::C_Evaluate_Derivative(), index_hi, index_lo, points, and Movement::s_Bezier3Coeffs().

◆ EvaluateDerivativeCatmullRom()

void Movement::SplineBase::EvaluateDerivativeCatmullRom ( index_type  index,
float  t,
Vector3 &  result 
) const
protected

◆ EvaluateDerivativeLinear()

void Movement::SplineBase::EvaluateDerivativeLinear ( index_type  index,
float  ,
Vector3 &  result 
) const
protected
135 {
136 ASSERT(index >= index_lo && index < index_hi);
137 result = points[index + 1] - points[index];
138 }

References ASSERT, index_hi, index_lo, and points.

◆ EvaluateLinear()

void Movement::SplineBase::EvaluateLinear ( index_type  index,
float  u,
Vector3 &  result 
) const
protected
116 {
117 ASSERT(index >= index_lo && index < index_hi);
118 result = points[index] + (points[index + 1] - points[index]) * u;
119 }

References ASSERT, index_hi, index_lo, and points.

◆ first()

◆ getPoint()

◆ getPointCount()

index_type Movement::SplineBase::getPointCount ( ) const
inline

◆ getPoints()

const ControlArray & Movement::SplineBase::getPoints ( ) const
inline
114{ return points;}

References points.

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

◆ init_cyclic_spline()

void Movement::SplineBase::init_cyclic_spline ( const Vector3 *  controls,
index_type  count,
EvaluationMode  m,
index_type  cyclic_point 
)
211 {
212 m_mode = m;
213 cyclic = true;
214
215 (this->*initializers[m_mode])(controls, count, cyclic, cyclic_point);
216 }
static InitMethtod initializers[ModesEnd]
Definition: Spline.h:84
bool cyclic
Definition: Spline.h:50

References cyclic, initializers, and m_mode.

Referenced by Movement::Spline< length_type >::init_cyclic_spline().

◆ init_spline()

void Movement::SplineBase::init_spline ( const Vector3 *  controls,
index_type  count,
EvaluationMode  m 
)

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

203 {
204 m_mode = m;
205 cyclic = false;
206
207 (this->*initializers[m_mode])(controls, count, cyclic, 0);
208 }

References cyclic, initializers, and m_mode.

Referenced by Movement::Spline< length_type >::init_spline().

◆ init_spline_custom()

template<class Init >
void Movement::SplineBase::init_spline_custom ( Init &  initializer)
inline

As i can see there are a lot of ways how spline can be initialized would be no harm to have some custom initializers.

125 {
126 initializer(m_mode, cyclic, points, index_lo, index_hi);
127 }

References cyclic, index_hi, index_lo, m_mode, and points.

Referenced by TransportMgr::GeneratePath().

◆ InitBezier3()

void Movement::SplineBase::InitBezier3 ( const Vector3 *  controls,
index_type  count,
bool  ,
index_type   
)
protected
272 {
273 index_type c = count / 3u * 3u;
274 index_type t = c / 3u;
275
276 points.resize(c);
277 memcpy(&points[0], controls, sizeof(Vector3) * c);
278
279 index_lo = 0;
280 index_hi = t - 1;
281 //mov_assert(points.size() % 3 == 0);
282 }
int index_type
Definition: Spline.h:31

References index_hi, index_lo, and points.

◆ InitCatmullRom()

void Movement::SplineBase::InitCatmullRom ( const Vector3 *  controls,
index_type  count,
bool  cyclic,
index_type  cyclic_point 
)
protected
239 {
240 const int real_size = count + (cyclic ? (1 + 2) : (1 + 1));
241
242 points.resize(real_size);
243
244 int lo_index = 1;
245 int high_index = lo_index + count - 1;
246
247 memcpy(&points[lo_index], controls, sizeof(Vector3) * count);
248
249 // first and last two indexes are space for special 'virtual points'
250 // these points are required for proper C_Evaluate and C_Evaluate_Derivative methtod work
251 if (cyclic)
252 {
253 if (cyclic_point == 0)
254 points[0] = controls[count - 1];
255 else
256 points[0] = controls[0].lerp(controls[1], -1);
257
258 points[high_index + 1] = controls[cyclic_point];
259 points[high_index + 2] = controls[cyclic_point + 1];
260 }
261 else
262 {
263 points[0] = controls[0].lerp(controls[1], -1);
264 points[high_index + 1] = controls[count - 1];
265 }
266
267 index_lo = lo_index;
268 index_hi = high_index + (cyclic ? 1 : 0);
269 }

References cyclic, index_hi, index_lo, and points.

◆ InitLinear()

void Movement::SplineBase::InitLinear ( const Vector3 *  controls,
index_type  count,
bool  cyclic,
index_type  cyclic_point 
)
protected
219 {
220 ASSERT(count >= 2);
221 const int real_size = count + 1;
222
223 points.resize(real_size);
224
225 memcpy(&points[0], controls, sizeof(Vector3) * count);
226
227 // first and last two indexes are space for special 'virtual points'
228 // these points are required for proper C_Evaluate and C_Evaluate_Derivative methtod work
229 if (cyclic)
230 points[count] = controls[cyclic_point];
231 else
232 points[count] = controls[count - 1];
233
234 index_lo = 0;
235 index_hi = cyclic ? count : (count - 1);
236 }

References ASSERT, cyclic, index_hi, index_lo, and points.

◆ isCyclic()

bool Movement::SplineBase::isCyclic ( ) const
inline

◆ last()

◆ mode()

EvaluationMode Movement::SplineBase::mode ( ) const
inline
110{ return (EvaluationMode)m_mode;}
EvaluationMode
Definition: Spline.h:35

References m_mode.

Referenced by ToString(), and Movement::PacketBuilder::WriteCreate().

◆ SegLength()

float Movement::SplineBase::SegLength ( index_type  i) const
inline

Calculates distance between [i; i+1] points, assumes that index i is in bounds.

132{ return (this->*seglengths[m_mode])(i);}
static SegLenghtMethtod seglengths[ModesEnd]
Definition: Spline.h:78

References m_mode.

Referenced by Movement::CommonInitializer::operator()().

◆ SegLengthBezier3()

float Movement::SplineBase::SegLengthBezier3 ( index_type  index) const
protected
180 {
181 index *= 3u;
182 ASSERT(index >= index_lo && index < index_hi);
183
184 Vector3 curPos, nextPos;
185 const Vector3* p = &points[index];
186
187 C_Evaluate(p, 0.f, s_Bezier3Coeffs, nextPos);
188 curPos = nextPos;
189
190 index_type i = 1;
191 double length = 0;
192 while (i <= STEPS_PER_SEGMENT)
193 {
194 C_Evaluate(p, float(i) / float(STEPS_PER_SEGMENT), s_Bezier3Coeffs, nextPos);
195 length += (nextPos - curPos).length();
196 curPos = nextPos;
197 ++i;
198 }
199 return length;
200 }

References ASSERT, Movement::C_Evaluate(), index_hi, index_lo, points, Movement::s_Bezier3Coeffs(), and STEPS_PER_SEGMENT.

◆ SegLengthCatmullRom()

float Movement::SplineBase::SegLengthCatmullRom ( index_type  index) const
protected
160 {
161 ASSERT(index >= index_lo && index < index_hi);
162
163 Vector3 curPos, nextPos;
164 const Vector3* p = &points[index - 1];
165 curPos = nextPos = p[1];
166
167 index_type i = 1;
168 double length = 0;
169 while (i <= STEPS_PER_SEGMENT)
170 {
171 C_Evaluate(p, float(i) / float(STEPS_PER_SEGMENT), s_catmullRomCoeffs, nextPos);
172 length += (nextPos - curPos).length();
173 curPos = nextPos;
174 ++i;
175 }
176 return length;
177 }

References ASSERT, Movement::C_Evaluate(), index_hi, index_lo, points, Movement::s_catmullRomCoeffs(), and STEPS_PER_SEGMENT.

◆ SegLengthLinear()

float Movement::SplineBase::SegLengthLinear ( index_type  index) const
protected
154 {
155 ASSERT(index >= index_lo && index < index_hi);
156 return (points[index] - points[index + 1]).length();
157 }

References ASSERT, index_hi, index_lo, and points.

◆ ToString()

std::string Movement::SplineBase::ToString ( ) const
292 {
293 std::stringstream str;
294 const char* mode_str[ModesEnd] = {"Linear", "CatmullRom", "Bezier3", "Uninitialized"};
295
296 index_type count = this->points.size();
297 str << "mode: " << mode_str[mode()] << std::endl;
298 str << "points count: " << count << std::endl;
299 for (index_type i = 0; i < count; ++i)
300 str << "point " << i << " : " << points[i].toString() << std::endl;
301
302 return str.str();
303 }
EvaluationMode mode() const
Definition: Spline.h:110

References mode(), ModesEnd, and points.

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

◆ UninitializedSplineEvaluationMethod()

void Movement::SplineBase::UninitializedSplineEvaluationMethod ( index_type  ,
float  ,
Vector3 &   
) const
inlineprotected
86{ ABORT(); }
#define ABORT
Definition: Errors.h:76

References ABORT.

◆ UninitializedSplineInitMethod()

void Movement::SplineBase::UninitializedSplineInitMethod ( Vector3 const *  ,
index_type  ,
bool  ,
index_type   
)
inlineprotected
88{ ABORT(); }

References ABORT.

◆ UninitializedSplineSegLenghtMethod()

float Movement::SplineBase::UninitializedSplineSegLenghtMethod ( index_type  ) const
inlineprotected
87{ ABORT(); }

References ABORT.

Member Data Documentation

◆ cyclic

bool Movement::SplineBase::cyclic {false}
protected

◆ derivative_evaluators

SplineBase::EvaluationMethtod Movement::SplineBase::derivative_evaluators
staticprotected
Initial value:
=
{
}
void EvaluateDerivativeCatmullRom(index_type, float, Vector3 &) const
Definition: Spline.cpp:140
void EvaluateDerivativeBezier3(index_type, float, Vector3 &) const
Definition: Spline.cpp:146
void EvaluateDerivativeLinear(index_type, float, Vector3 &) const
Definition: Spline.cpp:134
void UninitializedSplineEvaluationMethod(index_type, float, Vector3 &) const
Definition: Spline.h:86

◆ evaluators

SplineBase::EvaluationMethtod Movement::SplineBase::evaluators
staticprotected
Initial value:
=
{
}
void EvaluateCatmullRom(index_type, float, Vector3 &) const
Definition: Spline.cpp:121
void EvaluateBezier3(index_type, float, Vector3 &) const
Definition: Spline.cpp:127
void EvaluateLinear(index_type, float, Vector3 &) const
Definition: Spline.cpp:115

◆ index_hi

◆ index_lo

◆ initializers

SplineBase::InitMethtod Movement::SplineBase::initializers
staticprotected
Initial value:
=
{
}
void UninitializedSplineInitMethod(Vector3 const *, index_type, bool, index_type)
Definition: Spline.h:88
void InitBezier3(const Vector3 *, index_type, bool, index_type)
Definition: Spline.cpp:271
void InitCatmullRom(const Vector3 *, index_type, bool, index_type)
Definition: Spline.cpp:238

Referenced by init_cyclic_spline(), and init_spline().

◆ m_mode

◆ points

◆ seglengths

SplineBase::SegLenghtMethtod Movement::SplineBase::seglengths
staticprotected
Initial value:
=
{
}
float SegLengthLinear(index_type) const
Definition: Spline.cpp:153
float SegLengthBezier3(index_type) const
Definition: Spline.cpp:179
float UninitializedSplineSegLenghtMethod(index_type) const
Definition: Spline.h:87
float SegLengthCatmullRom(index_type) const
Definition: Spline.cpp:159