diff options
author | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
commit | 959831f4ef5a3e797f576c3de08cd65032c997ad (patch) | |
tree | e7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorFollowSpline.cpp | |
parent | Add info about changes to Irrlicht. (diff) | |
download | SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2 SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz |
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorFollowSpline.cpp')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorFollowSpline.cpp | 322 |
1 files changed, 161 insertions, 161 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorFollowSpline.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorFollowSpline.cpp index efc7493..b8e9b5b 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorFollowSpline.cpp +++ b/libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorFollowSpline.cpp | |||
@@ -1,161 +1,161 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt |
2 | // This file is part of the "Irrlicht Engine". | 2 | // This file is part of the "Irrlicht Engine". |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h |
4 | 4 | ||
5 | #include "CSceneNodeAnimatorFollowSpline.h" | 5 | #include "CSceneNodeAnimatorFollowSpline.h" |
6 | 6 | ||
7 | namespace irr | 7 | namespace irr |
8 | { | 8 | { |
9 | namespace scene | 9 | namespace scene |
10 | { | 10 | { |
11 | 11 | ||
12 | 12 | ||
13 | //! constructor | 13 | //! constructor |
14 | CSceneNodeAnimatorFollowSpline::CSceneNodeAnimatorFollowSpline(u32 time, | 14 | CSceneNodeAnimatorFollowSpline::CSceneNodeAnimatorFollowSpline(u32 time, |
15 | const core::array<core::vector3df>& points, f32 speed, | 15 | const core::array<core::vector3df>& points, f32 speed, |
16 | f32 tightness, bool loop, bool pingpong) | 16 | f32 tightness, bool loop, bool pingpong) |
17 | : ISceneNodeAnimatorFinishing(0), Points(points), Speed(speed), Tightness(tightness), StartTime(time) | 17 | : ISceneNodeAnimatorFinishing(0), Points(points), Speed(speed), Tightness(tightness), StartTime(time) |
18 | , Loop(loop), PingPong(pingpong) | 18 | , Loop(loop), PingPong(pingpong) |
19 | { | 19 | { |
20 | #ifdef _DEBUG | 20 | #ifdef _DEBUG |
21 | setDebugName("CSceneNodeAnimatorFollowSpline"); | 21 | setDebugName("CSceneNodeAnimatorFollowSpline"); |
22 | #endif | 22 | #endif |
23 | } | 23 | } |
24 | 24 | ||
25 | 25 | ||
26 | inline s32 CSceneNodeAnimatorFollowSpline::clamp(s32 idx, s32 size) | 26 | inline s32 CSceneNodeAnimatorFollowSpline::clamp(s32 idx, s32 size) |
27 | { | 27 | { |
28 | return ( idx<0 ? size+idx : ( idx>=size ? idx-size : idx ) ); | 28 | return ( idx<0 ? size+idx : ( idx>=size ? idx-size : idx ) ); |
29 | } | 29 | } |
30 | 30 | ||
31 | 31 | ||
32 | //! animates a scene node | 32 | //! animates a scene node |
33 | void CSceneNodeAnimatorFollowSpline::animateNode(ISceneNode* node, u32 timeMs) | 33 | void CSceneNodeAnimatorFollowSpline::animateNode(ISceneNode* node, u32 timeMs) |
34 | { | 34 | { |
35 | if(!node) | 35 | if(!node) |
36 | return; | 36 | return; |
37 | 37 | ||
38 | const u32 pSize = Points.size(); | 38 | const u32 pSize = Points.size(); |
39 | if (pSize==0) | 39 | if (pSize==0) |
40 | { | 40 | { |
41 | if ( !Loop ) | 41 | if ( !Loop ) |
42 | HasFinished = true; | 42 | HasFinished = true; |
43 | return; | 43 | return; |
44 | } | 44 | } |
45 | if (pSize==1) | 45 | if (pSize==1) |
46 | { | 46 | { |
47 | if ( timeMs > StartTime ) | 47 | if ( timeMs > StartTime ) |
48 | { | 48 | { |
49 | node->setPosition(Points[0]); | 49 | node->setPosition(Points[0]); |
50 | if ( !Loop ) | 50 | if ( !Loop ) |
51 | HasFinished = true; | 51 | HasFinished = true; |
52 | } | 52 | } |
53 | return; | 53 | return; |
54 | } | 54 | } |
55 | 55 | ||
56 | const f32 dt = ( (timeMs-StartTime) * Speed * 0.001f ); | 56 | const f32 dt = ( (timeMs-StartTime) * Speed * 0.001f ); |
57 | const s32 unwrappedIdx = core::floor32( dt ); | 57 | const s32 unwrappedIdx = core::floor32( dt ); |
58 | if ( !Loop && unwrappedIdx >= (s32)pSize-1 ) | 58 | if ( !Loop && unwrappedIdx >= (s32)pSize-1 ) |
59 | { | 59 | { |
60 | node->setPosition(Points[pSize-1]); | 60 | node->setPosition(Points[pSize-1]); |
61 | HasFinished = true; | 61 | HasFinished = true; |
62 | return; | 62 | return; |
63 | } | 63 | } |
64 | const bool pong = PingPong && (unwrappedIdx/(pSize-1))%2; | 64 | const bool pong = PingPong && (unwrappedIdx/(pSize-1))%2; |
65 | const f32 u = pong ? 1.f-core::fract ( dt ) : core::fract ( dt ); | 65 | const f32 u = pong ? 1.f-core::fract ( dt ) : core::fract ( dt ); |
66 | const s32 idx = pong ? (pSize-2) - (unwrappedIdx % (pSize-1)) | 66 | const s32 idx = pong ? (pSize-2) - (unwrappedIdx % (pSize-1)) |
67 | : (PingPong ? unwrappedIdx % (pSize-1) | 67 | : (PingPong ? unwrappedIdx % (pSize-1) |
68 | : unwrappedIdx % pSize); | 68 | : unwrappedIdx % pSize); |
69 | //const f32 u = 0.001f * fmodf( dt, 1000.0f ); | 69 | //const f32 u = 0.001f * fmodf( dt, 1000.0f ); |
70 | 70 | ||
71 | const core::vector3df& p0 = Points[ clamp( idx - 1, pSize ) ]; | 71 | const core::vector3df& p0 = Points[ clamp( idx - 1, pSize ) ]; |
72 | const core::vector3df& p1 = Points[ clamp( idx + 0, pSize ) ]; // starting point | 72 | const core::vector3df& p1 = Points[ clamp( idx + 0, pSize ) ]; // starting point |
73 | const core::vector3df& p2 = Points[ clamp( idx + 1, pSize ) ]; // end point | 73 | const core::vector3df& p2 = Points[ clamp( idx + 1, pSize ) ]; // end point |
74 | const core::vector3df& p3 = Points[ clamp( idx + 2, pSize ) ]; | 74 | const core::vector3df& p3 = Points[ clamp( idx + 2, pSize ) ]; |
75 | 75 | ||
76 | // hermite polynomials | 76 | // hermite polynomials |
77 | const f32 h1 = 2.0f * u * u * u - 3.0f * u * u + 1.0f; | 77 | const f32 h1 = 2.0f * u * u * u - 3.0f * u * u + 1.0f; |
78 | const f32 h2 = -2.0f * u * u * u + 3.0f * u * u; | 78 | const f32 h2 = -2.0f * u * u * u + 3.0f * u * u; |
79 | const f32 h3 = u * u * u - 2.0f * u * u + u; | 79 | const f32 h3 = u * u * u - 2.0f * u * u + u; |
80 | const f32 h4 = u * u * u - u * u; | 80 | const f32 h4 = u * u * u - u * u; |
81 | 81 | ||
82 | // tangents | 82 | // tangents |
83 | const core::vector3df t1 = ( p2 - p0 ) * Tightness; | 83 | const core::vector3df t1 = ( p2 - p0 ) * Tightness; |
84 | const core::vector3df t2 = ( p3 - p1 ) * Tightness; | 84 | const core::vector3df t2 = ( p3 - p1 ) * Tightness; |
85 | 85 | ||
86 | // interpolated point | 86 | // interpolated point |
87 | node->setPosition(p1 * h1 + p2 * h2 + t1 * h3 + t2 * h4); | 87 | node->setPosition(p1 * h1 + p2 * h2 + t1 * h3 + t2 * h4); |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
91 | //! Writes attributes of the scene node animator. | 91 | //! Writes attributes of the scene node animator. |
92 | void CSceneNodeAnimatorFollowSpline::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const | 92 | void CSceneNodeAnimatorFollowSpline::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const |
93 | { | 93 | { |
94 | out->addFloat("Speed", Speed); | 94 | out->addFloat("Speed", Speed); |
95 | out->addFloat("Tightness", Tightness); | 95 | out->addFloat("Tightness", Tightness); |
96 | out->addBool("Loop", Loop); | 96 | out->addBool("Loop", Loop); |
97 | out->addBool("PingPong", PingPong); | 97 | out->addBool("PingPong", PingPong); |
98 | 98 | ||
99 | u32 count = Points.size(); | 99 | u32 count = Points.size(); |
100 | 100 | ||
101 | if ( options && (options->Flags & io::EARWF_FOR_EDITOR)) | 101 | if ( options && (options->Flags & io::EARWF_FOR_EDITOR)) |
102 | { | 102 | { |
103 | // add one point in addition when serializing for editors | 103 | // add one point in addition when serializing for editors |
104 | // to make it easier to add points quickly | 104 | // to make it easier to add points quickly |
105 | count += 1; | 105 | count += 1; |
106 | } | 106 | } |
107 | 107 | ||
108 | for (u32 i=0; i<count; ++i) | 108 | for (u32 i=0; i<count; ++i) |
109 | { | 109 | { |
110 | core::stringc tname = "Point"; | 110 | core::stringc tname = "Point"; |
111 | tname += (int)(i+1); | 111 | tname += (int)(i+1); |
112 | 112 | ||
113 | out->addVector3d(tname.c_str(), i<Points.size() ? Points[i] : core::vector3df(0,0,0) ); | 113 | out->addVector3d(tname.c_str(), i<Points.size() ? Points[i] : core::vector3df(0,0,0) ); |
114 | } | 114 | } |
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
118 | //! Reads attributes of the scene node animator. | 118 | //! Reads attributes of the scene node animator. |
119 | void CSceneNodeAnimatorFollowSpline::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) | 119 | void CSceneNodeAnimatorFollowSpline::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) |
120 | { | 120 | { |
121 | Speed = in->getAttributeAsFloat("Speed"); | 121 | Speed = in->getAttributeAsFloat("Speed"); |
122 | Tightness = in->getAttributeAsFloat("Tightness"); | 122 | Tightness = in->getAttributeAsFloat("Tightness"); |
123 | Loop = in->getAttributeAsBool("Loop"); | 123 | Loop = in->getAttributeAsBool("Loop"); |
124 | PingPong = in->getAttributeAsBool("PingPong"); | 124 | PingPong = in->getAttributeAsBool("PingPong"); |
125 | Points.clear(); | 125 | Points.clear(); |
126 | 126 | ||
127 | for(u32 i=1; true; ++i) | 127 | for(u32 i=1; true; ++i) |
128 | { | 128 | { |
129 | core::stringc pname = "Point"; | 129 | core::stringc pname = "Point"; |
130 | pname += i; | 130 | pname += i; |
131 | 131 | ||
132 | if (in->existsAttribute(pname.c_str())) | 132 | if (in->existsAttribute(pname.c_str())) |
133 | Points.push_back(in->getAttributeAsVector3d(pname.c_str())); | 133 | Points.push_back(in->getAttributeAsVector3d(pname.c_str())); |
134 | else | 134 | else |
135 | break; | 135 | break; |
136 | } | 136 | } |
137 | 137 | ||
138 | // remove last point if double entry from editor | 138 | // remove last point if double entry from editor |
139 | if ( options && (options->Flags & io::EARWF_FOR_EDITOR) && | 139 | if ( options && (options->Flags & io::EARWF_FOR_EDITOR) && |
140 | Points.size() > 2 && Points.getLast() == core::vector3df(0,0,0)) | 140 | Points.size() > 2 && Points.getLast() == core::vector3df(0,0,0)) |
141 | { | 141 | { |
142 | Points.erase(Points.size()-1); | 142 | Points.erase(Points.size()-1); |
143 | 143 | ||
144 | if (Points.size() > 2 && Points.getLast() == core::vector3df(0,0,0)) | 144 | if (Points.size() > 2 && Points.getLast() == core::vector3df(0,0,0)) |
145 | Points.erase(Points.size()-1); | 145 | Points.erase(Points.size()-1); |
146 | } | 146 | } |
147 | } | 147 | } |
148 | 148 | ||
149 | 149 | ||
150 | ISceneNodeAnimator* CSceneNodeAnimatorFollowSpline::createClone(ISceneNode* node, ISceneManager* newManager) | 150 | ISceneNodeAnimator* CSceneNodeAnimatorFollowSpline::createClone(ISceneNode* node, ISceneManager* newManager) |
151 | { | 151 | { |
152 | CSceneNodeAnimatorFollowSpline * newAnimator = | 152 | CSceneNodeAnimatorFollowSpline * newAnimator = |
153 | new CSceneNodeAnimatorFollowSpline(StartTime, Points, Speed, Tightness); | 153 | new CSceneNodeAnimatorFollowSpline(StartTime, Points, Speed, Tightness); |
154 | 154 | ||
155 | return newAnimator; | 155 | return newAnimator; |
156 | } | 156 | } |
157 | 157 | ||
158 | 158 | ||
159 | } // end namespace scene | 159 | } // end namespace scene |
160 | } // end namespace irr | 160 | } // end namespace irr |
161 | 161 | ||