Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
SplineImpl.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6namespace Movement
7{
8 template<typename length_type> void Spline<length_type>::evaluate_percent(float t, Vector3& c) const
9 {
10 index_type Index;
11 float u;
12 computeIndex(t, Index, u);
13 evaluate_percent(Index, u, c);
14 }
15
16 template<typename length_type> void Spline<length_type>::evaluate_derivative(float t, Vector3& hermite) const
17 {
18 index_type Index;
19 float u;
20 computeIndex(t, Index, u);
21 evaluate_derivative(Index, u, hermite);
22 }
23
24 template<typename length_type> SplineBase::index_type Spline<length_type>::computeIndexInBounds(length_type length_) const
25 {
26 // Temporary disabled: causes infinite loop with t = 1.f
27 /*
28 index_type hi = index_hi;
29 index_type lo = index_lo;
30
31 index_type i = lo + (float)(hi - lo) * t;
32
33 while ((lengths[i] > length) || (lengths[i + 1] <= length))
34 {
35 if (lengths[i] > length)
36 hi = i - 1; // too big
37 else if (lengths[i + 1] <= length)
38 lo = i + 1; // too small
39
40 i = (hi + lo) / 2;
41 }*/
42
45 while (i + 1 < N && lengths[i + 1] < length_)
46 ++i;
47
48 return i;
49 }
50
51 template<typename length_type> void Spline<length_type>::computeIndex(float t, index_type& index, float& u) const
52 {
53 ASSERT(t >= 0.f && t <= 1.f);
54 length_type length_ = t * length();
55 index = computeIndexInBounds(length_);
56 ASSERT(index < index_hi);
57 u = (length_ - length(index)) / (float)length(index, index + 1);
58 }
59
60 template<typename length_type> SplineBase::index_type Spline<length_type>::computeIndexInBounds(float t) const
61 {
62 ASSERT(t >= 0.f && t <= 1.f);
63 return computeIndexInBounds(t * length());
64 }
65
66 template<typename length_type> void Spline<length_type>::initLengths()
67 {
69 length_type length = 0;
70 lengths.resize(index_hi + 1);
71 while (i < index_hi)
72 {
73 length += SegLength(i);
74 lengths[++i] = length;
75 }
76 }
77
78 template<typename length_type> void Spline<length_type>::clear()
79 {
81 lengths.clear();
82 }
83
84}
#define ASSERT
Definition Errors.h:29
float SegLength(index_type i) const
Definition Spline.h:115
index_type index_hi
Definition Spline.h:34
index_type index_lo
Definition Spline.h:33
LengthArray lengths
Definition Spline.h:128
void computeIndex(float t, index_type &out_idx, float &out_u) const
Definition SplineImpl.h:51
index_type computeIndexInBounds(length_type length) const
Definition SplineImpl.h:24
length_type length() const
Definition Spline.h:184
void evaluate_derivative(float t, Vector3 &hermite) const
Definition SplineImpl.h:16
void evaluate_percent(float t, Vector3 &c) const
Definition SplineImpl.h:8