diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | 86 |
1 files changed, 42 insertions, 44 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index d4f5c63..f164afe 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | |||
@@ -122,7 +122,7 @@ public class BSCharacter : PhysicsActor | |||
122 | shapeData.Restitution = _scene.Params.avatarRestitution; | 122 | shapeData.Restitution = _scene.Params.avatarRestitution; |
123 | 123 | ||
124 | // do actual create at taint time | 124 | // do actual create at taint time |
125 | _scene.TaintedObject(delegate() | 125 | _scene.TaintedObject("BSCharacter.create", delegate() |
126 | { | 126 | { |
127 | BulletSimAPI.CreateObject(parent_scene.WorldID, shapeData); | 127 | BulletSimAPI.CreateObject(parent_scene.WorldID, shapeData); |
128 | 128 | ||
@@ -138,7 +138,7 @@ public class BSCharacter : PhysicsActor | |||
138 | public void Destroy() | 138 | public void Destroy() |
139 | { | 139 | { |
140 | // DetailLog("{0},Destroy", LocalID); | 140 | // DetailLog("{0},Destroy", LocalID); |
141 | _scene.TaintedObject(delegate() | 141 | _scene.TaintedObject("BSCharacter.destroy", delegate() |
142 | { | 142 | { |
143 | BulletSimAPI.DestroyObject(_scene.WorldID, _localID); | 143 | BulletSimAPI.DestroyObject(_scene.WorldID, _localID); |
144 | }); | 144 | }); |
@@ -169,7 +169,7 @@ public class BSCharacter : PhysicsActor | |||
169 | 169 | ||
170 | ComputeAvatarVolumeAndMass(); | 170 | ComputeAvatarVolumeAndMass(); |
171 | 171 | ||
172 | _scene.TaintedObject(delegate() | 172 | _scene.TaintedObject("BSCharacter.setSize", delegate() |
173 | { | 173 | { |
174 | BulletSimAPI.SetObjectScaleMass(_scene.WorldID, LocalID, _scale, _mass, true); | 174 | BulletSimAPI.SetObjectScaleMass(_scene.WorldID, LocalID, _scale, _mass, true); |
175 | }); | 175 | }); |
@@ -205,13 +205,37 @@ public class BSCharacter : PhysicsActor | |||
205 | } | 205 | } |
206 | set { | 206 | set { |
207 | _position = value; | 207 | _position = value; |
208 | _scene.TaintedObject(delegate() | 208 | PositionSanityCheck(); |
209 | |||
210 | _scene.TaintedObject("BSCharacter.setPosition", delegate() | ||
209 | { | 211 | { |
210 | DetailLog("{0},SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 212 | DetailLog("{0},SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
211 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); | 213 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); |
212 | }); | 214 | }); |
213 | } | 215 | } |
214 | } | 216 | } |
217 | |||
218 | // Check that the current position is sane and, if not, modify the position to make it so. | ||
219 | // Check for being below terrain and being out of bounds. | ||
220 | // Returns 'true' of the position was made sane by some action. | ||
221 | private bool PositionSanityCheck() | ||
222 | { | ||
223 | bool ret = false; | ||
224 | |||
225 | // If below the ground, move the avatar up | ||
226 | float terrainHeight = Scene.GetTerrainHeightAtXYZ(_position); | ||
227 | if (_position.Z < terrainHeight) | ||
228 | { | ||
229 | DetailLog("{0},PositionAdjustUnderGround,call,pos={1},orient={2}", LocalID, _position, _orientation); | ||
230 | _position.Z = terrainHeight + 2.0f; | ||
231 | ret = true; | ||
232 | } | ||
233 | |||
234 | // TODO: check for out of bounds | ||
235 | |||
236 | return ret; | ||
237 | } | ||
238 | |||
215 | public override float Mass { | 239 | public override float Mass { |
216 | get { | 240 | get { |
217 | return _mass; | 241 | return _mass; |
@@ -222,9 +246,9 @@ public class BSCharacter : PhysicsActor | |||
222 | set { | 246 | set { |
223 | _force = value; | 247 | _force = value; |
224 | // m_log.DebugFormat("{0}: Force = {1}", LogHeader, _force); | 248 | // m_log.DebugFormat("{0}: Force = {1}", LogHeader, _force); |
225 | Scene.TaintedObject(delegate() | 249 | Scene.TaintedObject("BSCharacter.SetForce", delegate() |
226 | { | 250 | { |
227 | DetailLog("{0},setForce,taint,force={1}", LocalID, _force); | 251 | DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force); |
228 | BulletSimAPI.SetObjectForce(Scene.WorldID, LocalID, _force); | 252 | BulletSimAPI.SetObjectForce(Scene.WorldID, LocalID, _force); |
229 | }); | 253 | }); |
230 | } | 254 | } |
@@ -249,9 +273,9 @@ public class BSCharacter : PhysicsActor | |||
249 | set { | 273 | set { |
250 | _velocity = value; | 274 | _velocity = value; |
251 | // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); | 275 | // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); |
252 | _scene.TaintedObject(delegate() | 276 | _scene.TaintedObject("BSCharacter.setVelocity", delegate() |
253 | { | 277 | { |
254 | DetailLog("{0},setVelocity,taint,vel={1}", LocalID, _velocity); | 278 | DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity); |
255 | BulletSimAPI.SetObjectVelocity(_scene.WorldID, _localID, _velocity); | 279 | BulletSimAPI.SetObjectVelocity(_scene.WorldID, _localID, _velocity); |
256 | }); | 280 | }); |
257 | } | 281 | } |
@@ -275,7 +299,7 @@ public class BSCharacter : PhysicsActor | |||
275 | set { | 299 | set { |
276 | _orientation = value; | 300 | _orientation = value; |
277 | // m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation); | 301 | // m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation); |
278 | _scene.TaintedObject(delegate() | 302 | _scene.TaintedObject("BSCharacter.setOrientation", delegate() |
279 | { | 303 | { |
280 | // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); | 304 | // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); |
281 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); | 305 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); |
@@ -342,7 +366,7 @@ public class BSCharacter : PhysicsActor | |||
342 | public override float Buoyancy { | 366 | public override float Buoyancy { |
343 | get { return _buoyancy; } | 367 | get { return _buoyancy; } |
344 | set { _buoyancy = value; | 368 | set { _buoyancy = value; |
345 | _scene.TaintedObject(delegate() | 369 | _scene.TaintedObject("BSCharacter.setBuoyancy", delegate() |
346 | { | 370 | { |
347 | DetailLog("{0},setBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | 371 | DetailLog("{0},setBuoyancy,taint,buoy={1}", LocalID, _buoyancy); |
348 | BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, LocalID, _buoyancy); | 372 | BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, LocalID, _buoyancy); |
@@ -389,7 +413,7 @@ public class BSCharacter : PhysicsActor | |||
389 | _force.Y += force.Y; | 413 | _force.Y += force.Y; |
390 | _force.Z += force.Z; | 414 | _force.Z += force.Z; |
391 | // m_log.DebugFormat("{0}: AddForce. adding={1}, newForce={2}", LogHeader, force, _force); | 415 | // m_log.DebugFormat("{0}: AddForce. adding={1}, newForce={2}", LogHeader, force, _force); |
392 | _scene.TaintedObject(delegate() | 416 | _scene.TaintedObject("BSCharacter.AddForce", delegate() |
393 | { | 417 | { |
394 | DetailLog("{0},setAddForce,taint,addedForce={1}", LocalID, _force); | 418 | DetailLog("{0},setAddForce,taint,addedForce={1}", LocalID, _force); |
395 | BulletSimAPI.AddObjectForce2(Body.Ptr, _force); | 419 | BulletSimAPI.AddObjectForce2(Body.Ptr, _force); |
@@ -415,7 +439,7 @@ public class BSCharacter : PhysicsActor | |||
415 | // make sure first collision happens | 439 | // make sure first collision happens |
416 | _nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs; | 440 | _nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs; |
417 | 441 | ||
418 | Scene.TaintedObject(delegate() | 442 | Scene.TaintedObject("BSCharacter.SubscribeEvents", delegate() |
419 | { | 443 | { |
420 | BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 444 | BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); |
421 | }); | 445 | }); |
@@ -425,7 +449,7 @@ public class BSCharacter : PhysicsActor | |||
425 | public override void UnSubscribeEvents() { | 449 | public override void UnSubscribeEvents() { |
426 | _subscribedEventsMs = 0; | 450 | _subscribedEventsMs = 0; |
427 | // Avatars get all their collision events | 451 | // Avatars get all their collision events |
428 | // Scene.TaintedObject(delegate() | 452 | // Scene.TaintedObject("BSCharacter.UnSubscribeEvents", delegate() |
429 | // { | 453 | // { |
430 | // BulletSimAPI.RemoveFromCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 454 | // BulletSimAPI.RemoveFromCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); |
431 | // }); | 455 | // }); |
@@ -456,43 +480,17 @@ public class BSCharacter : PhysicsActor | |||
456 | // the world that things have changed. | 480 | // the world that things have changed. |
457 | public void UpdateProperties(EntityProperties entprop) | 481 | public void UpdateProperties(EntityProperties entprop) |
458 | { | 482 | { |
459 | /* | ||
460 | bool changed = false; | ||
461 | // we assign to the local variables so the normal set action does not happen | ||
462 | if (_position != entprop.Position) { | ||
463 | _position = entprop.Position; | ||
464 | changed = true; | ||
465 | } | ||
466 | if (_orientation != entprop.Rotation) { | ||
467 | _orientation = entprop.Rotation; | ||
468 | changed = true; | ||
469 | } | ||
470 | if (_velocity != entprop.Velocity) { | ||
471 | _velocity = entprop.Velocity; | ||
472 | changed = true; | ||
473 | } | ||
474 | if (_acceleration != entprop.Acceleration) { | ||
475 | _acceleration = entprop.Acceleration; | ||
476 | changed = true; | ||
477 | } | ||
478 | if (_rotationalVelocity != entprop.RotationalVelocity) { | ||
479 | _rotationalVelocity = entprop.RotationalVelocity; | ||
480 | changed = true; | ||
481 | } | ||
482 | if (changed) { | ||
483 | // m_log.DebugFormat("{0}: UpdateProperties: id={1}, c={2}, pos={3}, rot={4}", LogHeader, LocalID, changed, _position, _orientation); | ||
484 | // Avatar movement is not done by generating this event. There is code in the heartbeat | ||
485 | // loop that updates avatars. | ||
486 | // base.RequestPhysicsterseUpdate(); | ||
487 | } | ||
488 | */ | ||
489 | _position = entprop.Position; | 483 | _position = entprop.Position; |
490 | _orientation = entprop.Rotation; | 484 | _orientation = entprop.Rotation; |
491 | _velocity = entprop.Velocity; | 485 | _velocity = entprop.Velocity; |
492 | _acceleration = entprop.Acceleration; | 486 | _acceleration = entprop.Acceleration; |
493 | _rotationalVelocity = entprop.RotationalVelocity; | 487 | _rotationalVelocity = entprop.RotationalVelocity; |
494 | // Avatars don't report theirr changes the usual way. Changes are checked for in the heartbeat loop. | 488 | // Avatars don't report their changes the usual way. Changes are checked for in the heartbeat loop. |
495 | // base.RequestPhysicsterseUpdate(); | 489 | // base.RequestPhysicsterseUpdate(); |
490 | |||
491 | DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", | ||
492 | LocalID, entprop.Position, entprop.Rotation, entprop.Velocity, | ||
493 | entprop.Acceleration, entprop.RotationalVelocity); | ||
496 | } | 494 | } |
497 | 495 | ||
498 | // Called by the scene when a collision with this object is reported | 496 | // Called by the scene when a collision with this object is reported |