diff options
author | Robert Adams | 2012-09-26 09:25:56 -0700 |
---|---|---|
committer | Robert Adams | 2012-09-27 22:01:47 -0700 |
commit | 4589bc84a32366c6aae68b67f1fc7a2ee08be86d (patch) | |
tree | e635ab006f40e85eeb7b49870c04e6b2ca572dee /OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |
parent | BulletSim: btGhostObjects working to make 'volume detect' work. (diff) | |
download | opensim-SC-4589bc84a32366c6aae68b67f1fc7a2ee08be86d.zip opensim-SC-4589bc84a32366c6aae68b67f1fc7a2ee08be86d.tar.gz opensim-SC-4589bc84a32366c6aae68b67f1fc7a2ee08be86d.tar.bz2 opensim-SC-4589bc84a32366c6aae68b67f1fc7a2ee08be86d.tar.xz |
BulletSim: Terrain sets proper collision flags on creation.
Static objects are set to ISLAND_SLEEPING rather than DISABLE_SIMULATION.
Might reconsider this and, alternatively, have dynamic objects force activation.
Clean up use of DetailLog().
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 1c6d476..68a153e 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -174,7 +174,7 @@ public sealed class BSPrim : BSPhysObject | |||
174 | // Since _size changed, the mesh needs to be rebuilt. If rebuilt, all the correct | 174 | // Since _size changed, the mesh needs to be rebuilt. If rebuilt, all the correct |
175 | // scale and margins are set. | 175 | // scale and margins are set. |
176 | CreateGeomAndObject(true); | 176 | CreateGeomAndObject(true); |
177 | DetailLog("{0},BSPrim.setSize,size={1},scale={2},mass={3},physical={4}", LocalID, _size, _scale, _mass, IsPhysical); | 177 | // DetailLog("{0},BSPrim.setSize,size={1},scale={2},mass={3},physical={4}", LocalID, _size, _scale, _mass, IsPhysical); |
178 | }); | 178 | }); |
179 | } | 179 | } |
180 | } | 180 | } |
@@ -204,6 +204,7 @@ public sealed class BSPrim : BSPhysObject | |||
204 | _isSelected = value; | 204 | _isSelected = value; |
205 | PhysicsScene.TaintedObject("BSPrim.setSelected", delegate() | 205 | PhysicsScene.TaintedObject("BSPrim.setSelected", delegate() |
206 | { | 206 | { |
207 | // DetailLog("{0},BSPrim.selected,taint,selected={1}", LocalID, _isSelected); | ||
207 | SetObjectDynamic(false); | 208 | SetObjectDynamic(false); |
208 | }); | 209 | }); |
209 | } | 210 | } |
@@ -279,7 +280,7 @@ public sealed class BSPrim : BSPhysObject | |||
279 | // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint? | 280 | // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint? |
280 | PhysicsScene.TaintedObject("BSPrim.setPosition", delegate() | 281 | PhysicsScene.TaintedObject("BSPrim.setPosition", delegate() |
281 | { | 282 | { |
282 | DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 283 | // DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
283 | BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); | 284 | BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); |
284 | }); | 285 | }); |
285 | } | 286 | } |
@@ -317,7 +318,7 @@ public sealed class BSPrim : BSPhysObject | |||
317 | _force = value; | 318 | _force = value; |
318 | PhysicsScene.TaintedObject("BSPrim.setForce", delegate() | 319 | PhysicsScene.TaintedObject("BSPrim.setForce", delegate() |
319 | { | 320 | { |
320 | DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force); | 321 | // DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force); |
321 | BulletSimAPI.SetObjectForce2(BSBody.ptr, _force); | 322 | BulletSimAPI.SetObjectForce2(BSBody.ptr, _force); |
322 | }); | 323 | }); |
323 | } | 324 | } |
@@ -385,7 +386,7 @@ public sealed class BSPrim : BSPhysObject | |||
385 | _isVolumeDetect = newValue; | 386 | _isVolumeDetect = newValue; |
386 | PhysicsScene.TaintedObject("BSPrim.SetVolumeDetect", delegate() | 387 | PhysicsScene.TaintedObject("BSPrim.SetVolumeDetect", delegate() |
387 | { | 388 | { |
388 | DetailLog("{0},setVolumeDetect,taint,volDetect={1}", LocalID, _isVolumeDetect); | 389 | // DetailLog("{0},setVolumeDetect,taint,volDetect={1}", LocalID, _isVolumeDetect); |
389 | SetObjectDynamic(true); | 390 | SetObjectDynamic(true); |
390 | }); | 391 | }); |
391 | } | 392 | } |
@@ -398,7 +399,7 @@ public sealed class BSPrim : BSPhysObject | |||
398 | _velocity = value; | 399 | _velocity = value; |
399 | PhysicsScene.TaintedObject("BSPrim.setVelocity", delegate() | 400 | PhysicsScene.TaintedObject("BSPrim.setVelocity", delegate() |
400 | { | 401 | { |
401 | DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity); | 402 | // DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity); |
402 | BulletSimAPI.SetLinearVelocity2(BSBody.ptr, _velocity); | 403 | BulletSimAPI.SetLinearVelocity2(BSBody.ptr, _velocity); |
403 | }); | 404 | }); |
404 | } | 405 | } |
@@ -406,7 +407,7 @@ public sealed class BSPrim : BSPhysObject | |||
406 | public override OMV.Vector3 Torque { | 407 | public override OMV.Vector3 Torque { |
407 | get { return _torque; } | 408 | get { return _torque; } |
408 | set { _torque = value; | 409 | set { _torque = value; |
409 | DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque); | 410 | // DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque); |
410 | } | 411 | } |
411 | } | 412 | } |
412 | public override float CollisionScore { | 413 | public override float CollisionScore { |
@@ -433,7 +434,7 @@ public sealed class BSPrim : BSPhysObject | |||
433 | PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() | 434 | PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() |
434 | { | 435 | { |
435 | // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr); | 436 | // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr); |
436 | DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 437 | // DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
437 | BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); | 438 | BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); |
438 | }); | 439 | }); |
439 | } | 440 | } |
@@ -450,7 +451,7 @@ public sealed class BSPrim : BSPhysObject | |||
450 | _isPhysical = value; | 451 | _isPhysical = value; |
451 | PhysicsScene.TaintedObject("BSPrim.setIsPhysical", delegate() | 452 | PhysicsScene.TaintedObject("BSPrim.setIsPhysical", delegate() |
452 | { | 453 | { |
453 | DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical); | 454 | // DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical); |
454 | SetObjectDynamic(true); | 455 | SetObjectDynamic(true); |
455 | }); | 456 | }); |
456 | } | 457 | } |
@@ -470,12 +471,7 @@ public sealed class BSPrim : BSPhysObject | |||
470 | } | 471 | } |
471 | 472 | ||
472 | // Make gravity work if the object is physical and not selected | 473 | // Make gravity work if the object is physical and not selected |
473 | // No locking here because only called when it is safe (called at taint-time). | 474 | // Called at taint-time!! |
474 | // There are four flags we're interested in: | ||
475 | // IsStatic: Object does not move, otherwise the object has mass and moves | ||
476 | // isSolid: other objects bounce off of this object | ||
477 | // isVolumeDetect: other objects pass through but can generate collisions | ||
478 | // collisionEvents: whether this object returns collision events | ||
479 | private void SetObjectDynamic(bool forceRebuild) | 475 | private void SetObjectDynamic(bool forceRebuild) |
480 | { | 476 | { |
481 | #if CSHARP_BODY_MANAGEMENT | 477 | #if CSHARP_BODY_MANAGEMENT |
@@ -488,11 +484,17 @@ public sealed class BSPrim : BSPhysObject | |||
488 | #endif // CSHARP_BODY_MANAGEMENT | 484 | #endif // CSHARP_BODY_MANAGEMENT |
489 | } | 485 | } |
490 | 486 | ||
487 | // Convert the simulator's physical properties into settings on BulletSim objects. | ||
488 | // There are four flags we're interested in: | ||
489 | // IsStatic: Object does not move, otherwise the object has mass and moves | ||
490 | // isSolid: other objects bounce off of this object | ||
491 | // isVolumeDetect: other objects pass through but can generate collisions | ||
492 | // collisionEvents: whether this object returns collision events | ||
491 | private void UpdatePhysicalParameters() | 493 | private void UpdatePhysicalParameters() |
492 | { | 494 | { |
493 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,entry,body={1},shape={2}", LocalID, BSBody, BSShape); | 495 | // DetailLog("{0},BSPrim.UpdatePhysicalParameters,entry,body={1},shape={2}", LocalID, BSBody, BSShape); |
494 | 496 | ||
495 | // Mangling all the physical properties requires the object to be out of the physical world. | 497 | // Mangling all the physical properties requires the object not be in the physical world. |
496 | // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found). | 498 | // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found). |
497 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, BSBody.ptr); | 499 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, BSBody.ptr); |
498 | 500 | ||
@@ -505,7 +507,7 @@ public sealed class BSPrim : BSPhysObject | |||
505 | // Set up the object physicalness (does gravity and collisions move this object) | 507 | // Set up the object physicalness (does gravity and collisions move this object) |
506 | MakeDynamic(IsStatic); | 508 | MakeDynamic(IsStatic); |
507 | 509 | ||
508 | // Arrange for collisions events if the simulator wants them | 510 | // Arrange for collision events if the simulator wants them |
509 | EnableCollisions(SubscribedEvents()); | 511 | EnableCollisions(SubscribedEvents()); |
510 | 512 | ||
511 | #if CSHARP_BODY_MANAGEMENT | 513 | #if CSHARP_BODY_MANAGEMENT |
@@ -522,8 +524,6 @@ public sealed class BSPrim : BSPhysObject | |||
522 | if (BSBody.collisionFilter != 0 || BSBody.collisionMask != 0) | 524 | if (BSBody.collisionFilter != 0 || BSBody.collisionMask != 0) |
523 | { | 525 | { |
524 | BulletSimAPI.SetCollisionFilterMask2(BSBody.ptr, (uint)BSBody.collisionFilter, (uint)BSBody.collisionMask); | 526 | BulletSimAPI.SetCollisionFilterMask2(BSBody.ptr, (uint)BSBody.collisionFilter, (uint)BSBody.collisionMask); |
525 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,setCollisionFilterMask,filter={1},mask={2}", | ||
526 | LocalID, BSBody.collisionFilter.ToString("X"), BSBody.collisionMask.ToString("X")); | ||
527 | } | 527 | } |
528 | 528 | ||
529 | // Recompute any linkset parameters. | 529 | // Recompute any linkset parameters. |
@@ -557,8 +557,8 @@ public sealed class BSPrim : BSPhysObject | |||
557 | // There can be special things needed for implementing linksets | 557 | // There can be special things needed for implementing linksets |
558 | Linkset.MakeStatic(this); | 558 | Linkset.MakeStatic(this); |
559 | // The activation state is 'sleeping' so Bullet will not try to act on it | 559 | // The activation state is 'sleeping' so Bullet will not try to act on it |
560 | // BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ISLAND_SLEEPING); | 560 | BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ISLAND_SLEEPING); |
561 | BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.DISABLE_SIMULATION); | 561 | // BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.DISABLE_SIMULATION); |
562 | 562 | ||
563 | BSBody.collisionFilter = CollisionFilterGroups.StaticObjectFilter; | 563 | BSBody.collisionFilter = CollisionFilterGroups.StaticObjectFilter; |
564 | BSBody.collisionMask = CollisionFilterGroups.StaticObjectMask; | 564 | BSBody.collisionMask = CollisionFilterGroups.StaticObjectMask; |
@@ -571,16 +571,14 @@ public sealed class BSPrim : BSPhysObject | |||
571 | // Set various physical properties so internal dynamic properties will get computed correctly as they are set | 571 | // Set various physical properties so internal dynamic properties will get computed correctly as they are set |
572 | BulletSimAPI.SetFriction2(BSBody.ptr, PhysicsScene.Params.defaultFriction); | 572 | BulletSimAPI.SetFriction2(BSBody.ptr, PhysicsScene.Params.defaultFriction); |
573 | BulletSimAPI.SetRestitution2(BSBody.ptr, PhysicsScene.Params.defaultRestitution); | 573 | BulletSimAPI.SetRestitution2(BSBody.ptr, PhysicsScene.Params.defaultRestitution); |
574 | |||
574 | // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 | 575 | // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 |
575 | BulletSimAPI.SetInterpolationLinearVelocity2(BSBody.ptr, OMV.Vector3.Zero); | 576 | BulletSimAPI.ClearAllForces2(BSBody.ptr); |
576 | BulletSimAPI.SetInterpolationAngularVelocity2(BSBody.ptr, OMV.Vector3.Zero); | ||
577 | BulletSimAPI.SetInterpolationVelocity2(BSBody.ptr, OMV.Vector3.Zero, OMV.Vector3.Zero); | ||
578 | 577 | ||
579 | // A dynamic object has mass | 578 | // A dynamic object has mass |
580 | IntPtr collisionShapePtr = BulletSimAPI.GetCollisionShape2(BSBody.ptr); | 579 | IntPtr collisionShapePtr = BulletSimAPI.GetCollisionShape2(BSBody.ptr); |
581 | OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(collisionShapePtr, Linkset.LinksetMass); | 580 | OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(collisionShapePtr, Linkset.LinksetMass); |
582 | BulletSimAPI.SetMassProps2(BSBody.ptr, _mass, inertia); | 581 | BulletSimAPI.SetMassProps2(BSBody.ptr, _mass, inertia); |
583 | // Inertia is based on our new mass | ||
584 | BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); | 582 | BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); |
585 | 583 | ||
586 | // Various values for simulation limits | 584 | // Various values for simulation limits |
@@ -645,7 +643,7 @@ public sealed class BSPrim : BSPhysObject | |||
645 | 643 | ||
646 | // Create the new body with the shape | 644 | // Create the new body with the shape |
647 | BSBody = new BulletBody(LocalID, BulletSimAPI.CreateBodyFromShape2(PhysicsScene.World.Ptr, BSShape.Ptr, _position, _orientation)); | 645 | BSBody = new BulletBody(LocalID, BulletSimAPI.CreateBodyFromShape2(PhysicsScene.World.Ptr, BSShape.Ptr, _position, _orientation)); |
648 | BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); | 646 | CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); |
649 | DetailLog("{0},BSPrim.MakeSolid:rigidBody,body={1},shape={2}", LocalID, BSBody, BSShape); | 647 | DetailLog("{0},BSPrim.MakeSolid:rigidBody,body={1},shape={2}", LocalID, BSBody, BSShape); |
650 | } | 648 | } |
651 | } | 649 | } |
@@ -741,7 +739,7 @@ public sealed class BSPrim : BSPhysObject | |||
741 | // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); | 739 | // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); |
742 | PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate() | 740 | PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate() |
743 | { | 741 | { |
744 | DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); | 742 | // DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); |
745 | BulletSimAPI.SetAngularVelocity2(BSBody.ptr, _rotationalVelocity); | 743 | BulletSimAPI.SetAngularVelocity2(BSBody.ptr, _rotationalVelocity); |
746 | }); | 744 | }); |
747 | } | 745 | } |
@@ -758,7 +756,7 @@ public sealed class BSPrim : BSPhysObject | |||
758 | _buoyancy = value; | 756 | _buoyancy = value; |
759 | PhysicsScene.TaintedObject("BSPrim.setBuoyancy", delegate() | 757 | PhysicsScene.TaintedObject("BSPrim.setBuoyancy", delegate() |
760 | { | 758 | { |
761 | DetailLog("{0},BSPrim.SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | 759 | // DetailLog("{0},BSPrim.SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy); |
762 | // Buoyancy is faked by changing the gravity applied to the object | 760 | // Buoyancy is faked by changing the gravity applied to the object |
763 | float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); | 761 | float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); |
764 | BulletSimAPI.SetGravity2(BSBody.ptr, new OMV.Vector3(0f, 0f, grav)); | 762 | BulletSimAPI.SetGravity2(BSBody.ptr, new OMV.Vector3(0f, 0f, grav)); |
@@ -823,18 +821,18 @@ public sealed class BSPrim : BSPhysObject | |||
823 | } | 821 | } |
824 | m_accumulatedForces.Clear(); | 822 | m_accumulatedForces.Clear(); |
825 | } | 823 | } |
826 | DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, fSum); | 824 | // DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, fSum); |
827 | // For unknown reasons, "ApplyCentralForce" adds this force to the total force on the object. | 825 | // For unknown reasons, "ApplyCentralForce" adds this force to the total force on the object. |
828 | BulletSimAPI.ApplyCentralForce2(BSBody.ptr, fSum); | 826 | BulletSimAPI.ApplyCentralForce2(BSBody.ptr, fSum); |
829 | }); | 827 | }); |
830 | } | 828 | } |
831 | 829 | ||
832 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { | 830 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { |
833 | DetailLog("{0},BSPrim.AddAngularForce,call,angForce={1},push={2}", LocalID, force, pushforce); | 831 | // DetailLog("{0},BSPrim.AddAngularForce,call,angForce={1},push={2}", LocalID, force, pushforce); |
834 | // m_log.DebugFormat("{0}: AddAngularForce. f={1}, push={2}", LogHeader, force, pushforce); | 832 | // m_log.DebugFormat("{0}: AddAngularForce. f={1}, push={2}", LogHeader, force, pushforce); |
835 | } | 833 | } |
836 | public override void SetMomentum(OMV.Vector3 momentum) { | 834 | public override void SetMomentum(OMV.Vector3 momentum) { |
837 | DetailLog("{0},BSPrim.SetMomentum,call,mom={1}", LocalID, momentum); | 835 | // DetailLog("{0},BSPrim.SetMomentum,call,mom={1}", LocalID, momentum); |
838 | } | 836 | } |
839 | #region Mass Calculation | 837 | #region Mass Calculation |
840 | 838 | ||
@@ -1452,7 +1450,7 @@ public sealed class BSPrim : BSPhysObject | |||
1452 | } | 1450 | } |
1453 | // Rebuild the geometry and object. | 1451 | // Rebuild the geometry and object. |
1454 | // This is called when the shape changes so we need to recreate the mesh/hull. | 1452 | // This is called when the shape changes so we need to recreate the mesh/hull. |
1455 | // No locking here because this is done when the physics engine is not simulating (taint-time). | 1453 | // Called at taint-time!!! |
1456 | private void CreateGeomAndObject(bool forceRebuild) | 1454 | private void CreateGeomAndObject(bool forceRebuild) |
1457 | { | 1455 | { |
1458 | #if CSHARP_BODY_MANAGEMENT | 1456 | #if CSHARP_BODY_MANAGEMENT |