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, float orientation)
 
void init_cyclic_spline (const Vector3 *controls, index_type count, EvaluationMode m, index_type cyclic_point, float orientation)
 
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}
 
float initialOrientation {0}
 

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 
54 {
55 // could be modified, affects segment length evaluation precision
56 // lesser value saves more performance in cost of lover precision
57 // minimal value is 1
58 // client's value is 20, blizzs use 2-3 steps to compute length
60 };
@ STEPS_PER_SEGMENT
Definition Spline.h:59

◆ 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 ( )
291 {
292 index_lo = 0;
293 index_hi = 0;
294 points.clear();
295 }
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
110{ 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]
104{(this->*derivative_evaluators[m_mode])(Idx, u, hermite);}
uint8 m_mode
Definition Spline.h:49
static EvaluationMethtod derivative_evaluators[ModesEnd]
Definition Spline.h:73

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)
98{(this->*evaluators[m_mode])(Idx, u, c);}
static EvaluationMethtod evaluators[ModesEnd]
Definition Spline.h:68

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
115{ 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,
float  orientation 
)
212 {
213 m_mode = m;
214 cyclic = true;
215 initialOrientation = orientation;
216
217 (this->*initializers[m_mode])(controls, count, cyclic, cyclic_point);
218 }
static InitMethtod initializers[ModesEnd]
Definition Spline.h:85
bool cyclic
Definition Spline.h:50
float initialOrientation
Definition Spline.h:51

References cyclic, initializers, initialOrientation, 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,
float  orientation 
)

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

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

References cyclic, initializers, initialOrientation, 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.

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

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
278 {
279 index_type c = count / 3u * 3u;
280 index_type t = c / 3u;
281
282 points.resize(c);
283 memcpy(&points[0], controls, sizeof(Vector3) * c);
284
285 index_lo = 0;
286 index_hi = t - 1;
287 //mov_assert(points.size() % 3 == 0);
288 }
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
241 {
242 const int real_size = count + (cyclic ? (1 + 2) : (1 + 1));
243
244 points.resize(real_size);
245
246 int lo_index = 1;
247 int high_index = lo_index + count - 1;
248
249 memcpy(&points[lo_index], controls, sizeof(Vector3) * count);
250
251 // first and last two indexes are space for special 'virtual points'
252 // these points are required for proper C_Evaluate and C_Evaluate_Derivative methtod work
253 if (cyclic)
254 {
255 if (cyclic_point == 0)
256 points[0] = controls[count - 1];
257 else
258 points[0] = controls[0] - G3D::Vector3{ std::cos(initialOrientation), std::sin(initialOrientation), 0.0f };
259
260 points[high_index + 1] = controls[cyclic_point];
261 points[high_index + 2] = controls[cyclic_point + 1];
262 }
263 else
264 {
265 if (m_mode == ModeCatmullrom)
266 points[0] = controls[0] - G3D::Vector3{ std::cos(initialOrientation), std::sin(initialOrientation), 0.0f };
267 else
268 points[0] = controls[0].lerp(controls[1], -1);
269
270 points[high_index + 1] = controls[count - 1];
271 }
272
273 index_lo = lo_index;
274 index_hi = high_index + (cyclic ? 1 : 0);
275 }

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

◆ InitLinear()

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

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

◆ isCyclic()

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

◆ last()

◆ mode()

EvaluationMode Movement::SplineBase::mode ( ) const
inline
111{ 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.

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

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
298 {
299 std::stringstream str;
300 const char* mode_str[ModesEnd] = {"Linear", "CatmullRom", "Bezier3", "Uninitialized"};
301
302 index_type count = this->points.size();
303 str << "mode: " << mode_str[mode()] << std::endl;
304 str << "points count: " << count << std::endl;
305 for (index_type i = 0; i < count; ++i)
306 str << "point " << i << " : " << points[i].toString() << std::endl;
307
308 return str.str();
309 }
EvaluationMode mode() const
Definition Spline.h:111

References mode(), ModesEnd, and points.

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

◆ UninitializedSplineEvaluationMethod()

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

References ABORT.

◆ UninitializedSplineInitMethod()

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

References ABORT.

◆ UninitializedSplineSegLenghtMethod()

float Movement::SplineBase::UninitializedSplineSegLenghtMethod ( index_type  ) const
inlineprotected
88{ 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:87

◆ 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:89
void InitBezier3(const Vector3 *, index_type, bool, index_type)
Definition Spline.cpp:277
void InitCatmullRom(const Vector3 *, index_type, bool, index_type)
Definition Spline.cpp:240

Referenced by init_cyclic_spline(), and init_spline().

◆ initialOrientation

float Movement::SplineBase::initialOrientation {0}
protected

◆ 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:88
float SegLengthCatmullRom(index_type) const
Definition Spline.cpp:159

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