TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SplineImpl.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18 
19 namespace Movement
20 {
21 template<typename length_type> void Spline<length_type>::evaluate_percent( float t, Vector3 & c ) const
22 {
23  index_type Index;
24  float u;
25  computeIndex(t, Index, u);
26  evaluate_percent(Index, u, c);
27 }
28 
29 template<typename length_type> void Spline<length_type>::evaluate_derivative(float t, Vector3& hermite) const
30 {
31  index_type Index;
32  float u;
33  computeIndex(t, Index, u);
34  evaluate_derivative(Index, u, hermite);
35 }
36 
37 template<typename length_type> SplineBase::index_type Spline<length_type>::computeIndexInBounds(length_type length_) const
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 }
63 
64 template<typename length_type> void Spline<length_type>::computeIndex(float t, index_type& index, float& 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 }
72 
73 template<typename length_type> SplineBase::index_type Spline<length_type>::computeIndexInBounds( float t ) const
74 {
75  ASSERT(t >= 0.f && t <= 1.f);
76  return computeIndexInBounds(t * length());
77 }
78 
79 template<typename length_type> void Spline<length_type>::initLengths()
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 }
90 
91 template<typename length_type> void Spline<length_type>::clear()
92 {
93  SplineBase::clear();
94  lengths.clear();
95 }
96 
97 }
void initLengths()
Definition: SplineImpl.h:79
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
Definition: Vector3.h:58
Definition: Unit.h:409
int index_type
Definition: Spline.h:31
float length(float v)
Definition: vectorMath.h:208
#define ASSERT
Definition: Errors.h:55
void clear()
Definition: SplineImpl.h:91
index_type computeIndexInBounds(length_type length) const
Definition: SplineImpl.h:37
void evaluate_derivative(float t, Vector3 &hermite) const
Definition: SplineImpl.h:29