TrinityCore
SplineImpl.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18namespace Movement
19{
20template<typename length_type> void Spline<length_type>::evaluate_percent( float t, Vector3 & c ) const
21{
22 index_type Index;
23 float u;
24 computeIndex(t, Index, u);
25 evaluate_percent(Index, u, c);
26}
27
28template<typename length_type> void Spline<length_type>::evaluate_derivative(float t, Vector3& hermite) const
29{
30 index_type Index;
31 float u;
32 computeIndex(t, Index, u);
33 evaluate_derivative(Index, u, hermite);
34}
35
36template<typename length_type> SplineBase::index_type Spline<length_type>::computeIndexInBounds(length_type length_) const
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
55 index_type i = index_lo;
56 index_type N = index_hi;
57 while (i+1 < N && lengths[i+1] < length_)
58 ++i;
59
60 return i;
61}
62
63template<typename length_type> void 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 out_idx = computeIndexInBounds(length_);
68 ASSERT(out_idx < index_hi);
69 out_u = (length_ - length(out_idx)) / (float)length(out_idx, out_idx+1);
70}
71
72template<typename length_type> SplineBase::index_type Spline<length_type>::computeIndexInBounds( float t ) const
73{
74 ASSERT(t >= 0.f && t <= 1.f);
75 return computeIndexInBounds(t * length());
76}
77
78template<typename length_type> void Spline<length_type>::initLengths()
79{
80 index_type i = index_lo;
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}
89
90template<typename length_type> void Spline<length_type>::clear()
91{
93 lengths.clear();
94}
95
96}
#define ASSERT
Definition: Errors.h:68
virtual void clear()
Definition: Spline.cpp:291
void computeIndex(float t, index_type &out_idx, float &out_u) const
Definition: SplineImpl.h:63
void clear() override
Definition: SplineImpl.h:90
index_type computeIndexInBounds(length_type length) const
Definition: SplineImpl.h:36
void initLengths()
Definition: SplineImpl.h:78
void evaluate_derivative(float t, Vector3 &hermite) const
Definition: SplineImpl.h:28
void evaluate_percent(float t, Vector3 &c) const
Definition: SplineImpl.h:20