diff options
author | Robert Adams | 2012-09-23 18:39:46 -0700 |
---|---|---|
committer | Robert Adams | 2012-09-27 22:01:37 -0700 |
commit | d016051fa028a485b09fac47b3fa3d8fd08e207a (patch) | |
tree | 8f483976bb64b1328439b76754675126b09943b0 /OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |
parent | BulletSim: fix regression that caused cylindar shapes to have a box collision... (diff) | |
download | opensim-SC_OLD-d016051fa028a485b09fac47b3fa3d8fd08e207a.zip opensim-SC_OLD-d016051fa028a485b09fac47b3fa3d8fd08e207a.tar.gz opensim-SC_OLD-d016051fa028a485b09fac47b3fa3d8fd08e207a.tar.bz2 opensim-SC_OLD-d016051fa028a485b09fac47b3fa3d8fd08e207a.tar.xz |
BulletSim: renamed members of BulletShape, BulletSim and BulletBody
so the members case is consistant. Caused modifications everywhere.
New logic in BSShapeCollection to track use and sharing of shapes.
I just reslized, though, that shapes cannot be shared because the
shape's UserPointer is the localID of the prim and is required
for tracking collisions. More changes coming.
Added DuplicateCollisionShape2() to API and changed BuildNativeShape2
to take a ShapeData structure so don't have to pass so many parameters.
This matches the latest version of BulletSim.dll.
Additions and removal of DetailLog() statements for debugging.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 159 |
1 files changed, 100 insertions, 59 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index b764379..5be2b1b 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -24,6 +24,11 @@ | |||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | |||
28 | // Uncomment this it enable code to do all shape an body memory management | ||
29 | // in the C# code. | ||
30 | #define CSHARP_BODY_MANAGEMENT | ||
31 | |||
27 | using System; | 32 | using System; |
28 | using System.Reflection; | 33 | using System.Reflection; |
29 | using System.Collections.Generic; | 34 | using System.Collections.Generic; |
@@ -36,6 +41,7 @@ using OpenSim.Region.Physics.ConvexDecompositionDotNet; | |||
36 | 41 | ||
37 | namespace OpenSim.Region.Physics.BulletSPlugin | 42 | namespace OpenSim.Region.Physics.BulletSPlugin |
38 | { | 43 | { |
44 | |||
39 | [Serializable] | 45 | [Serializable] |
40 | public sealed class BSPrim : BSPhysObject | 46 | public sealed class BSPrim : BSPhysObject |
41 | { | 47 | { |
@@ -126,7 +132,7 @@ public sealed class BSPrim : BSPhysObject | |||
126 | { | 132 | { |
127 | CreateGeomAndObject(true); | 133 | CreateGeomAndObject(true); |
128 | 134 | ||
129 | CurrentCollisionFlags = BulletSimAPI.GetCollisionFlags2(BSBody.Ptr); | 135 | CurrentCollisionFlags = BulletSimAPI.GetCollisionFlags2(BSBody.ptr); |
130 | }); | 136 | }); |
131 | } | 137 | } |
132 | 138 | ||
@@ -246,10 +252,10 @@ public sealed class BSPrim : BSPhysObject | |||
246 | _rotationalVelocity = OMV.Vector3.Zero; | 252 | _rotationalVelocity = OMV.Vector3.Zero; |
247 | 253 | ||
248 | // Zero some other properties directly into the physics engine | 254 | // Zero some other properties directly into the physics engine |
249 | BulletSimAPI.SetLinearVelocity2(BSBody.Ptr, OMV.Vector3.Zero); | 255 | BulletSimAPI.SetLinearVelocity2(BSBody.ptr, OMV.Vector3.Zero); |
250 | BulletSimAPI.SetAngularVelocity2(BSBody.Ptr, OMV.Vector3.Zero); | 256 | BulletSimAPI.SetAngularVelocity2(BSBody.ptr, OMV.Vector3.Zero); |
251 | BulletSimAPI.SetInterpolationVelocity2(BSBody.Ptr, OMV.Vector3.Zero, OMV.Vector3.Zero); | 257 | BulletSimAPI.SetInterpolationVelocity2(BSBody.ptr, OMV.Vector3.Zero, OMV.Vector3.Zero); |
252 | BulletSimAPI.ClearForces2(BSBody.Ptr); | 258 | BulletSimAPI.ClearForces2(BSBody.ptr); |
253 | } | 259 | } |
254 | 260 | ||
255 | public override void LockAngularMotion(OMV.Vector3 axis) | 261 | public override void LockAngularMotion(OMV.Vector3 axis) |
@@ -262,7 +268,7 @@ public sealed class BSPrim : BSPhysObject | |||
262 | get { | 268 | get { |
263 | if (!Linkset.IsRoot(this)) | 269 | if (!Linkset.IsRoot(this)) |
264 | // child prims move around based on their parent. Need to get the latest location | 270 | // child prims move around based on their parent. Need to get the latest location |
265 | _position = BulletSimAPI.GetPosition2(BSBody.Ptr); | 271 | _position = BulletSimAPI.GetPosition2(BSBody.ptr); |
266 | 272 | ||
267 | // don't do the GetObjectPosition for root elements because this function is called a zillion times | 273 | // don't do the GetObjectPosition for root elements because this function is called a zillion times |
268 | // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, LocalID); | 274 | // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, LocalID); |
@@ -274,7 +280,7 @@ public sealed class BSPrim : BSPhysObject | |||
274 | PhysicsScene.TaintedObject("BSPrim.setPosition", delegate() | 280 | PhysicsScene.TaintedObject("BSPrim.setPosition", delegate() |
275 | { | 281 | { |
276 | DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 282 | DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
277 | BulletSimAPI.SetTranslation2(BSBody.Ptr, _position, _orientation); | 283 | BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); |
278 | }); | 284 | }); |
279 | } | 285 | } |
280 | } | 286 | } |
@@ -312,7 +318,7 @@ public sealed class BSPrim : BSPhysObject | |||
312 | PhysicsScene.TaintedObject("BSPrim.setForce", delegate() | 318 | PhysicsScene.TaintedObject("BSPrim.setForce", delegate() |
313 | { | 319 | { |
314 | DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force); | 320 | DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force); |
315 | BulletSimAPI.SetObjectForce2(BSBody.Ptr, _force); | 321 | BulletSimAPI.SetObjectForce2(BSBody.ptr, _force); |
316 | }); | 322 | }); |
317 | } | 323 | } |
318 | } | 324 | } |
@@ -374,12 +380,15 @@ public sealed class BSPrim : BSPhysObject | |||
374 | // Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more | 380 | // Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more |
375 | public override void SetVolumeDetect(int param) { | 381 | public override void SetVolumeDetect(int param) { |
376 | bool newValue = (param != 0); | 382 | bool newValue = (param != 0); |
377 | _isVolumeDetect = newValue; | 383 | if (_isVolumeDetect != newValue) |
378 | PhysicsScene.TaintedObject("BSPrim.SetVolumeDetect", delegate() | ||
379 | { | 384 | { |
380 | DetailLog("{0},setVolumeDetect,taint,volDetect={1}", LocalID, _isVolumeDetect); | 385 | _isVolumeDetect = newValue; |
381 | SetObjectDynamic(true); | 386 | PhysicsScene.TaintedObject("BSPrim.SetVolumeDetect", delegate() |
382 | }); | 387 | { |
388 | DetailLog("{0},setVolumeDetect,taint,volDetect={1}", LocalID, _isVolumeDetect); | ||
389 | SetObjectDynamic(true); | ||
390 | }); | ||
391 | } | ||
383 | return; | 392 | return; |
384 | } | 393 | } |
385 | 394 | ||
@@ -390,7 +399,7 @@ public sealed class BSPrim : BSPhysObject | |||
390 | PhysicsScene.TaintedObject("BSPrim.setVelocity", delegate() | 399 | PhysicsScene.TaintedObject("BSPrim.setVelocity", delegate() |
391 | { | 400 | { |
392 | DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity); | 401 | DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity); |
393 | BulletSimAPI.SetLinearVelocity2(BSBody.Ptr, _velocity); | 402 | BulletSimAPI.SetLinearVelocity2(BSBody.ptr, _velocity); |
394 | }); | 403 | }); |
395 | } | 404 | } |
396 | } | 405 | } |
@@ -414,7 +423,7 @@ public sealed class BSPrim : BSPhysObject | |||
414 | if (!Linkset.IsRoot(this)) | 423 | if (!Linkset.IsRoot(this)) |
415 | { | 424 | { |
416 | // Children move around because tied to parent. Get a fresh value. | 425 | // Children move around because tied to parent. Get a fresh value. |
417 | _orientation = BulletSimAPI.GetOrientation2(BSBody.Ptr); | 426 | _orientation = BulletSimAPI.GetOrientation2(BSBody.ptr); |
418 | } | 427 | } |
419 | return _orientation; | 428 | return _orientation; |
420 | } | 429 | } |
@@ -425,7 +434,7 @@ public sealed class BSPrim : BSPhysObject | |||
425 | { | 434 | { |
426 | // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, LocalID); | 435 | // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, LocalID); |
427 | DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 436 | DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
428 | BulletSimAPI.SetTranslation2(BSBody.Ptr, _position, _orientation); | 437 | BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); |
429 | }); | 438 | }); |
430 | } | 439 | } |
431 | } | 440 | } |
@@ -436,12 +445,15 @@ public sealed class BSPrim : BSPhysObject | |||
436 | public override bool IsPhysical { | 445 | public override bool IsPhysical { |
437 | get { return _isPhysical; } | 446 | get { return _isPhysical; } |
438 | set { | 447 | set { |
439 | _isPhysical = value; | 448 | if (_isPhysical != value) |
440 | PhysicsScene.TaintedObject("BSPrim.setIsPhysical", delegate() | ||
441 | { | 449 | { |
442 | DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical); | 450 | _isPhysical = value; |
443 | SetObjectDynamic(true); | 451 | PhysicsScene.TaintedObject("BSPrim.setIsPhysical", delegate() |
444 | }); | 452 | { |
453 | DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical); | ||
454 | SetObjectDynamic(true); | ||
455 | }); | ||
456 | } | ||
445 | } | 457 | } |
446 | } | 458 | } |
447 | 459 | ||
@@ -458,7 +470,7 @@ public sealed class BSPrim : BSPhysObject | |||
458 | } | 470 | } |
459 | 471 | ||
460 | // Make gravity work if the object is physical and not selected | 472 | // Make gravity work if the object is physical and not selected |
461 | // No locking here because only called when it is safe | 473 | // No locking here because only called when it is safe (called at taint-time). |
462 | // There are four flags we're interested in: | 474 | // There are four flags we're interested in: |
463 | // IsStatic: Object does not move, otherwise the object has mass and moves | 475 | // IsStatic: Object does not move, otherwise the object has mass and moves |
464 | // isSolid: other objects bounce off of this object | 476 | // isSolid: other objects bounce off of this object |
@@ -481,11 +493,13 @@ public sealed class BSPrim : BSPhysObject | |||
481 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,entry,body={1},shape={2}", LocalID, BSBody, BSShape); | 493 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,entry,body={1},shape={2}", LocalID, BSBody, BSShape); |
482 | 494 | ||
483 | // Mangling all the physical properties requires the object to be out of the physical world | 495 | // Mangling all the physical properties requires the object to be out of the physical world |
484 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.Ptr, BSBody.Ptr); | 496 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, BSBody.ptr); |
485 | 497 | ||
498 | #if !CSHARP_BODY_MANAGEMENT | ||
486 | // Make solid or not (do things bounce off or pass through this object) | 499 | // Make solid or not (do things bounce off or pass through this object) |
487 | // This is done first because it can change the collisionObject type. | 500 | // This is done first because it can change the collisionObject type. |
488 | MakeSolid(IsSolid); | 501 | MakeSolid(IsSolid); |
502 | #endif // !CSHARP_BODY_MANAGEMENT | ||
489 | 503 | ||
490 | // Set up the object physicalness (does gravity and collisions move this object) | 504 | // Set up the object physicalness (does gravity and collisions move this object) |
491 | MakeDynamic(IsStatic); | 505 | MakeDynamic(IsStatic); |
@@ -493,15 +507,23 @@ public sealed class BSPrim : BSPhysObject | |||
493 | // Arrange for collisions events if the simulator wants them | 507 | // Arrange for collisions events if the simulator wants them |
494 | EnableCollisions(SubscribedEvents()); | 508 | EnableCollisions(SubscribedEvents()); |
495 | 509 | ||
496 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.Ptr, BSBody.Ptr); | 510 | #if CSHARP_BODY_MANAGEMENT |
511 | // Make solid or not (do things bounce off or pass through this object). | ||
512 | MakeSolid(IsSolid); | ||
513 | #endif // CSHARP_BODY_MANAGEMENT | ||
514 | |||
515 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, BSBody.ptr); | ||
516 | |||
517 | // Rebuild its shape | ||
518 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, BSBody.ptr); | ||
497 | 519 | ||
498 | // Recompute any linkset parameters. | 520 | // Recompute any linkset parameters. |
499 | // When going from non-physical to physical, this re-enables the constraints that | 521 | // When going from non-physical to physical, this re-enables the constraints that |
500 | // had been automatically disabled when the mass was set to zero. | 522 | // had been automatically disabled when the mass was set to zero. |
501 | Linkset.Refresh(this); | 523 | Linkset.Refresh(this); |
502 | 524 | ||
503 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,taint,static={1},solid={2},mass={3},collide={4},cf={5}", | 525 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,exit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}", |
504 | LocalID, IsStatic, IsSolid, _mass, SubscribedEvents(), CurrentCollisionFlags); | 526 | LocalID, IsStatic, IsSolid, _mass, SubscribedEvents(), CurrentCollisionFlags, BSBody, BSShape); |
505 | } | 527 | } |
506 | 528 | ||
507 | // "Making dynamic" means changing to and from static. | 529 | // "Making dynamic" means changing to and from static. |
@@ -514,52 +536,52 @@ public sealed class BSPrim : BSPhysObject | |||
514 | if (makeStatic) | 536 | if (makeStatic) |
515 | { | 537 | { |
516 | // Become a Bullet 'static' object type | 538 | // Become a Bullet 'static' object type |
517 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_STATIC_OBJECT); | 539 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.ptr, CollisionFlags.CF_STATIC_OBJECT); |
518 | // Stop all movement | 540 | // Stop all movement |
519 | BulletSimAPI.ClearAllForces2(BSBody.Ptr); | 541 | BulletSimAPI.ClearAllForces2(BSBody.ptr); |
520 | // Center of mass is at the center of the object | 542 | // Center of mass is at the center of the object |
521 | BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.BSBody.Ptr, _position, _orientation); | 543 | BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.BSBody.ptr, _position, _orientation); |
522 | // Mass is zero which disables a bunch of physics stuff in Bullet | 544 | // Mass is zero which disables a bunch of physics stuff in Bullet |
523 | BulletSimAPI.SetMassProps2(BSBody.Ptr, 0f, OMV.Vector3.Zero); | 545 | BulletSimAPI.SetMassProps2(BSBody.ptr, 0f, OMV.Vector3.Zero); |
524 | // There is no inertia in a static object | 546 | // There is no inertia in a static object |
525 | BulletSimAPI.UpdateInertiaTensor2(BSBody.Ptr); | 547 | BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); |
526 | // There can be special things needed for implementing linksets | 548 | // There can be special things needed for implementing linksets |
527 | Linkset.MakeStatic(this); | 549 | Linkset.MakeStatic(this); |
528 | // The activation state is 'sleeping' so Bullet will not try to act on it | 550 | // The activation state is 'sleeping' so Bullet will not try to act on it |
529 | BulletSimAPI.ForceActivationState2(BSBody.Ptr, ActivationState.ISLAND_SLEEPING); | 551 | BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ISLAND_SLEEPING); |
530 | // BulletSimAPI.ForceActivationState2(BSBody.Ptr, ActivationState.DISABLE_SIMULATION); | 552 | // BulletSimAPI.ForceActivationState2(BSBody.Ptr, ActivationState.DISABLE_SIMULATION); |
531 | } | 553 | } |
532 | else | 554 | else |
533 | { | 555 | { |
534 | // Not a Bullet static object | 556 | // Not a Bullet static object |
535 | CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_STATIC_OBJECT); | 557 | CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.ptr, CollisionFlags.CF_STATIC_OBJECT); |
536 | 558 | ||
537 | // Set various physical properties so internal dynamic properties will get computed correctly as they are set | 559 | // Set various physical properties so internal dynamic properties will get computed correctly as they are set |
538 | BulletSimAPI.SetFriction2(BSBody.Ptr, PhysicsScene.Params.defaultFriction); | 560 | BulletSimAPI.SetFriction2(BSBody.ptr, PhysicsScene.Params.defaultFriction); |
539 | BulletSimAPI.SetRestitution2(BSBody.Ptr, PhysicsScene.Params.defaultRestitution); | 561 | BulletSimAPI.SetRestitution2(BSBody.ptr, PhysicsScene.Params.defaultRestitution); |
540 | // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 | 562 | // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 |
541 | BulletSimAPI.SetInterpolationLinearVelocity2(BSBody.Ptr, OMV.Vector3.Zero); | 563 | BulletSimAPI.SetInterpolationLinearVelocity2(BSBody.ptr, OMV.Vector3.Zero); |
542 | BulletSimAPI.SetInterpolationAngularVelocity2(BSBody.Ptr, OMV.Vector3.Zero); | 564 | BulletSimAPI.SetInterpolationAngularVelocity2(BSBody.ptr, OMV.Vector3.Zero); |
543 | BulletSimAPI.SetInterpolationVelocity2(BSBody.Ptr, OMV.Vector3.Zero, OMV.Vector3.Zero); | 565 | BulletSimAPI.SetInterpolationVelocity2(BSBody.ptr, OMV.Vector3.Zero, OMV.Vector3.Zero); |
544 | 566 | ||
545 | // A dynamic object has mass | 567 | // A dynamic object has mass |
546 | IntPtr collisionShapePtr = BulletSimAPI.GetCollisionShape2(BSBody.Ptr); | 568 | IntPtr collisionShapePtr = BulletSimAPI.GetCollisionShape2(BSBody.ptr); |
547 | OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(collisionShapePtr, Linkset.LinksetMass); | 569 | OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(collisionShapePtr, Linkset.LinksetMass); |
548 | BulletSimAPI.SetMassProps2(BSBody.Ptr, _mass, inertia); | 570 | BulletSimAPI.SetMassProps2(BSBody.ptr, _mass, inertia); |
549 | // Inertia is based on our new mass | 571 | // Inertia is based on our new mass |
550 | BulletSimAPI.UpdateInertiaTensor2(BSBody.Ptr); | 572 | BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); |
551 | 573 | ||
552 | // Various values for simulation limits | 574 | // Various values for simulation limits |
553 | BulletSimAPI.SetDamping2(BSBody.Ptr, PhysicsScene.Params.linearDamping, PhysicsScene.Params.angularDamping); | 575 | BulletSimAPI.SetDamping2(BSBody.ptr, PhysicsScene.Params.linearDamping, PhysicsScene.Params.angularDamping); |
554 | BulletSimAPI.SetDeactivationTime2(BSBody.Ptr, PhysicsScene.Params.deactivationTime); | 576 | BulletSimAPI.SetDeactivationTime2(BSBody.ptr, PhysicsScene.Params.deactivationTime); |
555 | BulletSimAPI.SetSleepingThresholds2(BSBody.Ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold); | 577 | BulletSimAPI.SetSleepingThresholds2(BSBody.ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold); |
556 | BulletSimAPI.SetContactProcessingThreshold2(BSBody.Ptr, PhysicsScene.Params.contactProcessingThreshold); | 578 | BulletSimAPI.SetContactProcessingThreshold2(BSBody.ptr, PhysicsScene.Params.contactProcessingThreshold); |
557 | 579 | ||
558 | // There can be special things needed for implementing linksets | 580 | // There can be special things needed for implementing linksets |
559 | Linkset.MakeDynamic(this); | 581 | Linkset.MakeDynamic(this); |
560 | 582 | ||
561 | // Force activation of the object so Bullet will act on it. | 583 | // Force activation of the object so Bullet will act on it. |
562 | BulletSimAPI.Activate2(BSBody.Ptr, true); | 584 | BulletSimAPI.Activate2(BSBody.ptr, true); |
563 | } | 585 | } |
564 | } | 586 | } |
565 | 587 | ||
@@ -569,8 +591,28 @@ public sealed class BSPrim : BSPhysObject | |||
569 | // the functions after this one set up the state of a possibly newly created collision body. | 591 | // the functions after this one set up the state of a possibly newly created collision body. |
570 | private void MakeSolid(bool makeSolid) | 592 | private void MakeSolid(bool makeSolid) |
571 | { | 593 | { |
572 | #if !CSHARP_BODY_MANAGEMENT | 594 | #if CSHARP_BODY_MANAGEMENT |
573 | CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(BSBody.Ptr); | 595 | CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(BSBody.ptr); |
596 | if (makeSolid) | ||
597 | { | ||
598 | // Verify the previous code created the correct shape for this type of thing. | ||
599 | if ((bodyType & CollisionObjectTypes.CO_RIGID_BODY) == 0) | ||
600 | { | ||
601 | m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for solidity. id={1}, type={2}", LogHeader, LocalID, bodyType); | ||
602 | } | ||
603 | CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); | ||
604 | } | ||
605 | else | ||
606 | { | ||
607 | if ((bodyType & CollisionObjectTypes.CO_GHOST_OBJECT) == 0) | ||
608 | { | ||
609 | m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for non-solidness. id={1}, type={2}", LogHeader, LocalID, bodyType); | ||
610 | } | ||
611 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); | ||
612 | } | ||
613 | #else | ||
614 | // If doing the body management in C#, all this logic is in CSShapeCollection.CreateObject(). | ||
615 | CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(BSBody.ptr); | ||
574 | if (makeSolid) | 616 | if (makeSolid) |
575 | { | 617 | { |
576 | if ((bodyType & CollisionObjectTypes.CO_RIGID_BODY) == 0) | 618 | if ((bodyType & CollisionObjectTypes.CO_RIGID_BODY) == 0) |
@@ -618,11 +660,11 @@ public sealed class BSPrim : BSPhysObject | |||
618 | { | 660 | { |
619 | if (wantsCollisionEvents) | 661 | if (wantsCollisionEvents) |
620 | { | 662 | { |
621 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 663 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); |
622 | } | 664 | } |
623 | else | 665 | else |
624 | { | 666 | { |
625 | CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 667 | CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); |
626 | } | 668 | } |
627 | } | 669 | } |
628 | 670 | ||
@@ -683,7 +725,7 @@ public sealed class BSPrim : BSPhysObject | |||
683 | PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate() | 725 | PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate() |
684 | { | 726 | { |
685 | DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); | 727 | DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); |
686 | BulletSimAPI.SetAngularVelocity2(BSBody.Ptr, _rotationalVelocity); | 728 | BulletSimAPI.SetAngularVelocity2(BSBody.ptr, _rotationalVelocity); |
687 | }); | 729 | }); |
688 | } | 730 | } |
689 | } | 731 | } |
@@ -702,7 +744,7 @@ public sealed class BSPrim : BSPhysObject | |||
702 | DetailLog("{0},BSPrim.SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | 744 | DetailLog("{0},BSPrim.SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy); |
703 | // Buoyancy is faked by changing the gravity applied to the object | 745 | // Buoyancy is faked by changing the gravity applied to the object |
704 | float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); | 746 | float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); |
705 | BulletSimAPI.SetGravity2(BSBody.Ptr, new OMV.Vector3(0f, 0f, grav)); | 747 | BulletSimAPI.SetGravity2(BSBody.ptr, new OMV.Vector3(0f, 0f, grav)); |
706 | // BulletSimAPI.SetObjectBuoyancy(Scene.WorldID, LocalID, _buoyancy); | 748 | // BulletSimAPI.SetObjectBuoyancy(Scene.WorldID, LocalID, _buoyancy); |
707 | }); | 749 | }); |
708 | } | 750 | } |
@@ -767,7 +809,7 @@ public sealed class BSPrim : BSPhysObject | |||
767 | } | 809 | } |
768 | DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, fSum); | 810 | DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, fSum); |
769 | // For unknown reasons, "ApplyCentralForce" adds this force to the total force on the object. | 811 | // For unknown reasons, "ApplyCentralForce" adds this force to the total force on the object. |
770 | BulletSimAPI.ApplyCentralForce2(BSBody.Ptr, fSum); | 812 | BulletSimAPI.ApplyCentralForce2(BSBody.ptr, fSum); |
771 | }); | 813 | }); |
772 | } | 814 | } |
773 | 815 | ||
@@ -1394,7 +1436,7 @@ public sealed class BSPrim : BSPhysObject | |||
1394 | } | 1436 | } |
1395 | // Rebuild the geometry and object. | 1437 | // Rebuild the geometry and object. |
1396 | // This is called when the shape changes so we need to recreate the mesh/hull. | 1438 | // This is called when the shape changes so we need to recreate the mesh/hull. |
1397 | // No locking here because this is done when the physics engine is not simulating | 1439 | // No locking here because this is done when the physics engine is not simulating (taint-time). |
1398 | private void CreateGeomAndObject(bool forceRebuild) | 1440 | private void CreateGeomAndObject(bool forceRebuild) |
1399 | { | 1441 | { |
1400 | #if CSHARP_BODY_MANAGEMENT | 1442 | #if CSHARP_BODY_MANAGEMENT |
@@ -1403,11 +1445,10 @@ public sealed class BSPrim : BSPhysObject | |||
1403 | 1445 | ||
1404 | // Create the correct physical representation for this type of object. | 1446 | // Create the correct physical representation for this type of object. |
1405 | // Updates BSBody and BSShape with the new information. | 1447 | // Updates BSBody and BSShape with the new information. |
1406 | if (PhysicsScene.Shapes.GetBodyAndShape(forceRebuild, PhysicsScene.World, this, shapeData, _pbs)) | 1448 | PhysicsScene.Shapes.GetBodyAndShape(forceRebuild, PhysicsScene.World, this, shapeData, _pbs); |
1407 | { | 1449 | |
1408 | // Make sure the properties are set on the new object | 1450 | // Make sure the properties are set on the new object |
1409 | UpdatePhysicalParameters(); | 1451 | UpdatePhysicalParameters(); |
1410 | } | ||
1411 | #else | 1452 | #else |
1412 | // m_log.DebugFormat("{0}: CreateGeomAndObject. lID={1}, force={2}", LogHeader, LocalID, forceRebuild); | 1453 | // m_log.DebugFormat("{0}: CreateGeomAndObject. lID={1}, force={2}", LogHeader, LocalID, forceRebuild); |
1413 | // Create the geometry that will make up the object | 1454 | // Create the geometry that will make up the object |