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/CSceneNodeAnimatorCollisionResponse.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/CSceneNodeAnimatorCollisionResponse.cpp')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorCollisionResponse.cpp | 606 |
1 files changed, 303 insertions, 303 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorCollisionResponse.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorCollisionResponse.cpp index 432d2ac..74437fd 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorCollisionResponse.cpp +++ b/libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorCollisionResponse.cpp | |||
@@ -1,303 +1,303 @@ | |||
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 "CSceneNodeAnimatorCollisionResponse.h" | 5 | #include "CSceneNodeAnimatorCollisionResponse.h" |
6 | #include "ISceneCollisionManager.h" | 6 | #include "ISceneCollisionManager.h" |
7 | #include "ISceneManager.h" | 7 | #include "ISceneManager.h" |
8 | #include "ICameraSceneNode.h" | 8 | #include "ICameraSceneNode.h" |
9 | #include "os.h" | 9 | #include "os.h" |
10 | 10 | ||
11 | namespace irr | 11 | namespace irr |
12 | { | 12 | { |
13 | namespace scene | 13 | namespace scene |
14 | { | 14 | { |
15 | 15 | ||
16 | //! constructor | 16 | //! constructor |
17 | CSceneNodeAnimatorCollisionResponse::CSceneNodeAnimatorCollisionResponse( | 17 | CSceneNodeAnimatorCollisionResponse::CSceneNodeAnimatorCollisionResponse( |
18 | ISceneManager* scenemanager, | 18 | ISceneManager* scenemanager, |
19 | ITriangleSelector* world, ISceneNode* object, | 19 | ITriangleSelector* world, ISceneNode* object, |
20 | const core::vector3df& ellipsoidRadius, | 20 | const core::vector3df& ellipsoidRadius, |
21 | const core::vector3df& gravityPerSecond, | 21 | const core::vector3df& gravityPerSecond, |
22 | const core::vector3df& ellipsoidTranslation, | 22 | const core::vector3df& ellipsoidTranslation, |
23 | f32 slidingSpeed) | 23 | f32 slidingSpeed) |
24 | : Radius(ellipsoidRadius), Gravity(gravityPerSecond), Translation(ellipsoidTranslation), | 24 | : Radius(ellipsoidRadius), Gravity(gravityPerSecond), Translation(ellipsoidTranslation), |
25 | World(world), Object(object), SceneManager(scenemanager), LastTime(0), | 25 | World(world), Object(object), SceneManager(scenemanager), LastTime(0), |
26 | SlidingSpeed(slidingSpeed), CollisionNode(0), CollisionCallback(0), | 26 | SlidingSpeed(slidingSpeed), CollisionNode(0), CollisionCallback(0), |
27 | Falling(false), IsCamera(false), AnimateCameraTarget(true), CollisionOccurred(false), | 27 | Falling(false), IsCamera(false), AnimateCameraTarget(true), CollisionOccurred(false), |
28 | FirstUpdate(true) | 28 | FirstUpdate(true) |
29 | { | 29 | { |
30 | #ifdef _DEBUG | 30 | #ifdef _DEBUG |
31 | setDebugName("CSceneNodeAnimatorCollisionResponse"); | 31 | setDebugName("CSceneNodeAnimatorCollisionResponse"); |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | if (World) | 34 | if (World) |
35 | World->grab(); | 35 | World->grab(); |
36 | 36 | ||
37 | setNode(Object); | 37 | setNode(Object); |
38 | } | 38 | } |
39 | 39 | ||
40 | 40 | ||
41 | //! destructor | 41 | //! destructor |
42 | CSceneNodeAnimatorCollisionResponse::~CSceneNodeAnimatorCollisionResponse() | 42 | CSceneNodeAnimatorCollisionResponse::~CSceneNodeAnimatorCollisionResponse() |
43 | { | 43 | { |
44 | if (World) | 44 | if (World) |
45 | World->drop(); | 45 | World->drop(); |
46 | 46 | ||
47 | if (CollisionCallback) | 47 | if (CollisionCallback) |
48 | CollisionCallback->drop(); | 48 | CollisionCallback->drop(); |
49 | } | 49 | } |
50 | 50 | ||
51 | 51 | ||
52 | //! Returns if the attached scene node is falling, which means that | 52 | //! Returns if the attached scene node is falling, which means that |
53 | //! there is no blocking wall from the scene node in the direction of | 53 | //! there is no blocking wall from the scene node in the direction of |
54 | //! the gravity. | 54 | //! the gravity. |
55 | bool CSceneNodeAnimatorCollisionResponse::isFalling() const | 55 | bool CSceneNodeAnimatorCollisionResponse::isFalling() const |
56 | { | 56 | { |
57 | _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; | 57 | _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; |
58 | return Falling; | 58 | return Falling; |
59 | } | 59 | } |
60 | 60 | ||
61 | 61 | ||
62 | //! Sets the radius of the ellipsoid with which collision detection and | 62 | //! Sets the radius of the ellipsoid with which collision detection and |
63 | //! response is done. | 63 | //! response is done. |
64 | void CSceneNodeAnimatorCollisionResponse::setEllipsoidRadius( | 64 | void CSceneNodeAnimatorCollisionResponse::setEllipsoidRadius( |
65 | const core::vector3df& radius) | 65 | const core::vector3df& radius) |
66 | { | 66 | { |
67 | Radius = radius; | 67 | Radius = radius; |
68 | FirstUpdate = true; | 68 | FirstUpdate = true; |
69 | } | 69 | } |
70 | 70 | ||
71 | 71 | ||
72 | //! Returns the radius of the ellipsoid with wich the collision detection and | 72 | //! Returns the radius of the ellipsoid with wich the collision detection and |
73 | //! response is done. | 73 | //! response is done. |
74 | core::vector3df CSceneNodeAnimatorCollisionResponse::getEllipsoidRadius() const | 74 | core::vector3df CSceneNodeAnimatorCollisionResponse::getEllipsoidRadius() const |
75 | { | 75 | { |
76 | return Radius; | 76 | return Radius; |
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
80 | //! Sets the gravity of the environment. | 80 | //! Sets the gravity of the environment. |
81 | void CSceneNodeAnimatorCollisionResponse::setGravity(const core::vector3df& gravity) | 81 | void CSceneNodeAnimatorCollisionResponse::setGravity(const core::vector3df& gravity) |
82 | { | 82 | { |
83 | Gravity = gravity; | 83 | Gravity = gravity; |
84 | FirstUpdate = true; | 84 | FirstUpdate = true; |
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
88 | //! Returns current vector of gravity. | 88 | //! Returns current vector of gravity. |
89 | core::vector3df CSceneNodeAnimatorCollisionResponse::getGravity() const | 89 | core::vector3df CSceneNodeAnimatorCollisionResponse::getGravity() const |
90 | { | 90 | { |
91 | return Gravity; | 91 | return Gravity; |
92 | } | 92 | } |
93 | 93 | ||
94 | 94 | ||
95 | //! 'Jump' the animator, by adding a jump speed opposite to its gravity | 95 | //! 'Jump' the animator, by adding a jump speed opposite to its gravity |
96 | void CSceneNodeAnimatorCollisionResponse::jump(f32 jumpSpeed) | 96 | void CSceneNodeAnimatorCollisionResponse::jump(f32 jumpSpeed) |
97 | { | 97 | { |
98 | FallingVelocity -= (core::vector3df(Gravity).normalize()) * jumpSpeed; | 98 | FallingVelocity -= (core::vector3df(Gravity).normalize()) * jumpSpeed; |
99 | Falling = true; | 99 | Falling = true; |
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ||
103 | //! Sets the translation of the ellipsoid for collision detection. | 103 | //! Sets the translation of the ellipsoid for collision detection. |
104 | void CSceneNodeAnimatorCollisionResponse::setEllipsoidTranslation(const core::vector3df &translation) | 104 | void CSceneNodeAnimatorCollisionResponse::setEllipsoidTranslation(const core::vector3df &translation) |
105 | { | 105 | { |
106 | Translation = translation; | 106 | Translation = translation; |
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | //! Returns the translation of the ellipsoid for collision detection. | 110 | //! Returns the translation of the ellipsoid for collision detection. |
111 | core::vector3df CSceneNodeAnimatorCollisionResponse::getEllipsoidTranslation() const | 111 | core::vector3df CSceneNodeAnimatorCollisionResponse::getEllipsoidTranslation() const |
112 | { | 112 | { |
113 | return Translation; | 113 | return Translation; |
114 | } | 114 | } |
115 | 115 | ||
116 | 116 | ||
117 | //! Sets a triangle selector holding all triangles of the world with which | 117 | //! Sets a triangle selector holding all triangles of the world with which |
118 | //! the scene node may collide. | 118 | //! the scene node may collide. |
119 | void CSceneNodeAnimatorCollisionResponse::setWorld(ITriangleSelector* newWorld) | 119 | void CSceneNodeAnimatorCollisionResponse::setWorld(ITriangleSelector* newWorld) |
120 | { | 120 | { |
121 | if (newWorld) | 121 | if (newWorld) |
122 | newWorld->grab(); | 122 | newWorld->grab(); |
123 | 123 | ||
124 | if (World) | 124 | if (World) |
125 | World->drop(); | 125 | World->drop(); |
126 | 126 | ||
127 | World = newWorld; | 127 | World = newWorld; |
128 | 128 | ||
129 | FirstUpdate = true; | 129 | FirstUpdate = true; |
130 | } | 130 | } |
131 | 131 | ||
132 | 132 | ||
133 | //! Returns the current triangle selector containing all triangles for | 133 | //! Returns the current triangle selector containing all triangles for |
134 | //! collision detection. | 134 | //! collision detection. |
135 | ITriangleSelector* CSceneNodeAnimatorCollisionResponse::getWorld() const | 135 | ITriangleSelector* CSceneNodeAnimatorCollisionResponse::getWorld() const |
136 | { | 136 | { |
137 | return World; | 137 | return World; |
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | void CSceneNodeAnimatorCollisionResponse::animateNode(ISceneNode* node, u32 timeMs) | 141 | void CSceneNodeAnimatorCollisionResponse::animateNode(ISceneNode* node, u32 timeMs) |
142 | { | 142 | { |
143 | CollisionOccurred = false; | 143 | CollisionOccurred = false; |
144 | 144 | ||
145 | if (node != Object) | 145 | if (node != Object) |
146 | setNode(node); | 146 | setNode(node); |
147 | 147 | ||
148 | if(!Object || !World) | 148 | if(!Object || !World) |
149 | return; | 149 | return; |
150 | 150 | ||
151 | // trigger reset | 151 | // trigger reset |
152 | if ( timeMs == 0 ) | 152 | if ( timeMs == 0 ) |
153 | { | 153 | { |
154 | FirstUpdate = true; | 154 | FirstUpdate = true; |
155 | timeMs = LastTime; | 155 | timeMs = LastTime; |
156 | } | 156 | } |
157 | 157 | ||
158 | if ( FirstUpdate ) | 158 | if ( FirstUpdate ) |
159 | { | 159 | { |
160 | LastPosition = Object->getPosition(); | 160 | LastPosition = Object->getPosition(); |
161 | Falling = false; | 161 | Falling = false; |
162 | LastTime = timeMs; | 162 | LastTime = timeMs; |
163 | FallingVelocity.set ( 0, 0, 0 ); | 163 | FallingVelocity.set ( 0, 0, 0 ); |
164 | 164 | ||
165 | FirstUpdate = false; | 165 | FirstUpdate = false; |
166 | } | 166 | } |
167 | 167 | ||
168 | const u32 diff = timeMs - LastTime; | 168 | const u32 diff = timeMs - LastTime; |
169 | LastTime = timeMs; | 169 | LastTime = timeMs; |
170 | 170 | ||
171 | CollisionResultPosition = Object->getPosition(); | 171 | CollisionResultPosition = Object->getPosition(); |
172 | core::vector3df vel = CollisionResultPosition - LastPosition; | 172 | core::vector3df vel = CollisionResultPosition - LastPosition; |
173 | 173 | ||
174 | FallingVelocity += Gravity * (f32)diff * 0.001f; | 174 | FallingVelocity += Gravity * (f32)diff * 0.001f; |
175 | 175 | ||
176 | CollisionTriangle = RefTriangle; | 176 | CollisionTriangle = RefTriangle; |
177 | CollisionPoint = core::vector3df(); | 177 | CollisionPoint = core::vector3df(); |
178 | CollisionResultPosition = core::vector3df(); | 178 | CollisionResultPosition = core::vector3df(); |
179 | CollisionNode = 0; | 179 | CollisionNode = 0; |
180 | 180 | ||
181 | // core::vector3df force = vel + FallingVelocity; | 181 | // core::vector3df force = vel + FallingVelocity; |
182 | 182 | ||
183 | if ( AnimateCameraTarget ) | 183 | if ( AnimateCameraTarget ) |
184 | { | 184 | { |
185 | // TODO: divide SlidingSpeed by frame time | 185 | // TODO: divide SlidingSpeed by frame time |
186 | 186 | ||
187 | bool f = false; | 187 | bool f = false; |
188 | CollisionResultPosition | 188 | CollisionResultPosition |
189 | = SceneManager->getSceneCollisionManager()->getCollisionResultPosition( | 189 | = SceneManager->getSceneCollisionManager()->getCollisionResultPosition( |
190 | World, LastPosition-Translation, | 190 | World, LastPosition-Translation, |
191 | Radius, vel, CollisionTriangle, CollisionPoint, f, | 191 | Radius, vel, CollisionTriangle, CollisionPoint, f, |
192 | CollisionNode, SlidingSpeed, FallingVelocity); | 192 | CollisionNode, SlidingSpeed, FallingVelocity); |
193 | 193 | ||
194 | CollisionOccurred = (CollisionTriangle != RefTriangle); | 194 | CollisionOccurred = (CollisionTriangle != RefTriangle); |
195 | 195 | ||
196 | CollisionResultPosition += Translation; | 196 | CollisionResultPosition += Translation; |
197 | 197 | ||
198 | if (f)//CollisionTriangle == RefTriangle) | 198 | if (f)//CollisionTriangle == RefTriangle) |
199 | { | 199 | { |
200 | Falling = true; | 200 | Falling = true; |
201 | } | 201 | } |
202 | else | 202 | else |
203 | { | 203 | { |
204 | Falling = false; | 204 | Falling = false; |
205 | FallingVelocity.set(0, 0, 0); | 205 | FallingVelocity.set(0, 0, 0); |
206 | } | 206 | } |
207 | 207 | ||
208 | bool collisionConsumed = false; | 208 | bool collisionConsumed = false; |
209 | 209 | ||
210 | if (CollisionOccurred && CollisionCallback) | 210 | if (CollisionOccurred && CollisionCallback) |
211 | collisionConsumed = CollisionCallback->onCollision(*this); | 211 | collisionConsumed = CollisionCallback->onCollision(*this); |
212 | 212 | ||
213 | if(!collisionConsumed) | 213 | if(!collisionConsumed) |
214 | Object->setPosition(CollisionResultPosition); | 214 | Object->setPosition(CollisionResultPosition); |
215 | } | 215 | } |
216 | 216 | ||
217 | // move camera target | 217 | // move camera target |
218 | if (AnimateCameraTarget && IsCamera) | 218 | if (AnimateCameraTarget && IsCamera) |
219 | { | 219 | { |
220 | const core::vector3df pdiff = Object->getPosition() - LastPosition - vel; | 220 | const core::vector3df pdiff = Object->getPosition() - LastPosition - vel; |
221 | ICameraSceneNode* cam = (ICameraSceneNode*)Object; | 221 | ICameraSceneNode* cam = (ICameraSceneNode*)Object; |
222 | cam->setTarget(cam->getTarget() + pdiff); | 222 | cam->setTarget(cam->getTarget() + pdiff); |
223 | } | 223 | } |
224 | 224 | ||
225 | LastPosition = Object->getPosition(); | 225 | LastPosition = Object->getPosition(); |
226 | } | 226 | } |
227 | 227 | ||
228 | 228 | ||
229 | void CSceneNodeAnimatorCollisionResponse::setNode(ISceneNode* node) | 229 | void CSceneNodeAnimatorCollisionResponse::setNode(ISceneNode* node) |
230 | { | 230 | { |
231 | Object = node; | 231 | Object = node; |
232 | 232 | ||
233 | if (Object) | 233 | if (Object) |
234 | { | 234 | { |
235 | LastPosition = Object->getPosition(); | 235 | LastPosition = Object->getPosition(); |
236 | IsCamera = (Object->getType() == ESNT_CAMERA); | 236 | IsCamera = (Object->getType() == ESNT_CAMERA); |
237 | } | 237 | } |
238 | 238 | ||
239 | LastTime = os::Timer::getTime(); | 239 | LastTime = os::Timer::getTime(); |
240 | } | 240 | } |
241 | 241 | ||
242 | 242 | ||
243 | //! Writes attributes of the scene node animator. | 243 | //! Writes attributes of the scene node animator. |
244 | void CSceneNodeAnimatorCollisionResponse::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const | 244 | void CSceneNodeAnimatorCollisionResponse::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const |
245 | { | 245 | { |
246 | out->addVector3d("Radius", Radius); | 246 | out->addVector3d("Radius", Radius); |
247 | out->addVector3d("Gravity", Gravity); | 247 | out->addVector3d("Gravity", Gravity); |
248 | out->addVector3d("Translation", Translation); | 248 | out->addVector3d("Translation", Translation); |
249 | out->addBool("AnimateCameraTarget", AnimateCameraTarget); | 249 | out->addBool("AnimateCameraTarget", AnimateCameraTarget); |
250 | } | 250 | } |
251 | 251 | ||
252 | 252 | ||
253 | //! Reads attributes of the scene node animator. | 253 | //! Reads attributes of the scene node animator. |
254 | void CSceneNodeAnimatorCollisionResponse::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) | 254 | void CSceneNodeAnimatorCollisionResponse::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) |
255 | { | 255 | { |
256 | Radius = in->getAttributeAsVector3d("Radius"); | 256 | Radius = in->getAttributeAsVector3d("Radius"); |
257 | Gravity = in->getAttributeAsVector3d("Gravity"); | 257 | Gravity = in->getAttributeAsVector3d("Gravity"); |
258 | Translation = in->getAttributeAsVector3d("Translation"); | 258 | Translation = in->getAttributeAsVector3d("Translation"); |
259 | AnimateCameraTarget = in->getAttributeAsBool("AnimateCameraTarget"); | 259 | AnimateCameraTarget = in->getAttributeAsBool("AnimateCameraTarget"); |
260 | } | 260 | } |
261 | 261 | ||
262 | 262 | ||
263 | ISceneNodeAnimator* CSceneNodeAnimatorCollisionResponse::createClone(ISceneNode* node, ISceneManager* newManager) | 263 | ISceneNodeAnimator* CSceneNodeAnimatorCollisionResponse::createClone(ISceneNode* node, ISceneManager* newManager) |
264 | { | 264 | { |
265 | if (!newManager) newManager = SceneManager; | 265 | if (!newManager) newManager = SceneManager; |
266 | 266 | ||
267 | CSceneNodeAnimatorCollisionResponse * newAnimator = | 267 | CSceneNodeAnimatorCollisionResponse * newAnimator = |
268 | new CSceneNodeAnimatorCollisionResponse(newManager, World, Object, Radius, | 268 | new CSceneNodeAnimatorCollisionResponse(newManager, World, Object, Radius, |
269 | (Gravity * 1000.0f), Translation, SlidingSpeed); | 269 | (Gravity * 1000.0f), Translation, SlidingSpeed); |
270 | 270 | ||
271 | return newAnimator; | 271 | return newAnimator; |
272 | } | 272 | } |
273 | 273 | ||
274 | void CSceneNodeAnimatorCollisionResponse::setCollisionCallback(ICollisionCallback* callback) | 274 | void CSceneNodeAnimatorCollisionResponse::setCollisionCallback(ICollisionCallback* callback) |
275 | { | 275 | { |
276 | if ( CollisionCallback == callback ) | 276 | if ( CollisionCallback == callback ) |
277 | return; | 277 | return; |
278 | 278 | ||
279 | if (CollisionCallback) | 279 | if (CollisionCallback) |
280 | CollisionCallback->drop(); | 280 | CollisionCallback->drop(); |
281 | 281 | ||
282 | CollisionCallback = callback; | 282 | CollisionCallback = callback; |
283 | 283 | ||
284 | if (CollisionCallback) | 284 | if (CollisionCallback) |
285 | CollisionCallback->grab(); | 285 | CollisionCallback->grab(); |
286 | } | 286 | } |
287 | 287 | ||
288 | //! Should the Target react on collision ( default = true ) | 288 | //! Should the Target react on collision ( default = true ) |
289 | void CSceneNodeAnimatorCollisionResponse::setAnimateTarget ( bool enable ) | 289 | void CSceneNodeAnimatorCollisionResponse::setAnimateTarget ( bool enable ) |
290 | { | 290 | { |
291 | AnimateCameraTarget = enable; | 291 | AnimateCameraTarget = enable; |
292 | FirstUpdate = true; | 292 | FirstUpdate = true; |
293 | } | 293 | } |
294 | 294 | ||
295 | //! Should the Target react on collision ( default = true ) | 295 | //! Should the Target react on collision ( default = true ) |
296 | bool CSceneNodeAnimatorCollisionResponse::getAnimateTarget () const | 296 | bool CSceneNodeAnimatorCollisionResponse::getAnimateTarget () const |
297 | { | 297 | { |
298 | return AnimateCameraTarget; | 298 | return AnimateCameraTarget; |
299 | } | 299 | } |
300 | 300 | ||
301 | } // end namespace scene | 301 | } // end namespace scene |
302 | } // end namespace irr | 302 | } // end namespace irr |
303 | 303 | ||