diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 116 |
1 files changed, 88 insertions, 28 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 54bf063..85c2627 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -55,7 +55,6 @@ public sealed class BSPrim : BSPhysObject | |||
55 | private OMV.Vector3 _position; | 55 | private OMV.Vector3 _position; |
56 | 56 | ||
57 | private float _mass; // the mass of this object | 57 | private float _mass; // the mass of this object |
58 | private float _density; | ||
59 | private OMV.Vector3 _force; | 58 | private OMV.Vector3 _force; |
60 | private OMV.Vector3 _velocity; | 59 | private OMV.Vector3 _velocity; |
61 | private OMV.Vector3 _torque; | 60 | private OMV.Vector3 _torque; |
@@ -64,8 +63,6 @@ public sealed class BSPrim : BSPhysObject | |||
64 | private int _physicsActorType; | 63 | private int _physicsActorType; |
65 | private bool _isPhysical; | 64 | private bool _isPhysical; |
66 | private bool _flying; | 65 | private bool _flying; |
67 | private float _friction; | ||
68 | private float _restitution; | ||
69 | private bool _setAlwaysRun; | 66 | private bool _setAlwaysRun; |
70 | private bool _throttleUpdates; | 67 | private bool _throttleUpdates; |
71 | private bool _floatOnWater; | 68 | private bool _floatOnWater; |
@@ -101,12 +98,6 @@ public sealed class BSPrim : BSPhysObject | |||
101 | _isPhysical = pisPhysical; | 98 | _isPhysical = pisPhysical; |
102 | _isVolumeDetect = false; | 99 | _isVolumeDetect = false; |
103 | 100 | ||
104 | // Someday set default attributes based on the material but, for now, we don't know the prim material yet. | ||
105 | // MaterialAttributes primMat = BSMaterials.GetAttributes(Material, pisPhysical); | ||
106 | _density = PhysicsScene.Params.defaultDensity; | ||
107 | _friction = PhysicsScene.Params.defaultFriction; | ||
108 | _restitution = PhysicsScene.Params.defaultRestitution; | ||
109 | |||
110 | VehicleController = new BSDynamics(PhysicsScene, this); // add vehicleness | 101 | VehicleController = new BSDynamics(PhysicsScene, this); // add vehicleness |
111 | 102 | ||
112 | _mass = CalculateMass(); | 103 | _mass = CalculateMass(); |
@@ -432,8 +423,6 @@ public sealed class BSPrim : BSPhysObject | |||
432 | } | 423 | } |
433 | else | 424 | else |
434 | { | 425 | { |
435 | OMV.Vector3 grav = ComputeGravity(Buoyancy); | ||
436 | |||
437 | if (inWorld) | 426 | if (inWorld) |
438 | { | 427 | { |
439 | // Changing interesting properties doesn't change proxy and collision cache | 428 | // Changing interesting properties doesn't change proxy and collision cache |
@@ -443,25 +432,20 @@ public sealed class BSPrim : BSPhysObject | |||
443 | } | 432 | } |
444 | 433 | ||
445 | // The computation of mass props requires gravity to be set on the object. | 434 | // The computation of mass props requires gravity to be set on the object. |
446 | PhysicsScene.PE.SetGravity(PhysBody, grav); | 435 | Gravity = ComputeGravity(Buoyancy); |
436 | PhysicsScene.PE.SetGravity(PhysBody, Gravity); | ||
447 | 437 | ||
448 | Inertia = PhysicsScene.PE.CalculateLocalInertia(PhysShape, physMass); | 438 | Inertia = PhysicsScene.PE.CalculateLocalInertia(PhysShape, physMass); |
449 | PhysicsScene.PE.SetMassProps(PhysBody, physMass, Inertia); | 439 | PhysicsScene.PE.SetMassProps(PhysBody, physMass, Inertia); |
450 | PhysicsScene.PE.UpdateInertiaTensor(PhysBody); | 440 | PhysicsScene.PE.UpdateInertiaTensor(PhysBody); |
451 | 441 | ||
452 | // center of mass is at the zero of the object | 442 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}", |
453 | // DEBUG DEBUG PhysicsScene.PE.SetCenterOfMassByPosRot(PhysBody, ForcePosition, ForceOrientation); | 443 | LocalID, physMass, Inertia, Gravity, inWorld); |
454 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}", LocalID, physMass, Inertia, grav, inWorld); | ||
455 | 444 | ||
456 | if (inWorld) | 445 | if (inWorld) |
457 | { | 446 | { |
458 | AddObjectToPhysicalWorld(); | 447 | AddObjectToPhysicalWorld(); |
459 | } | 448 | } |
460 | |||
461 | // Must set gravity after it has been added to the world because, for unknown reasons, | ||
462 | // adding the object resets the object's gravity to world gravity | ||
463 | PhysicsScene.PE.SetGravity(PhysBody, grav); | ||
464 | |||
465 | } | 449 | } |
466 | } | 450 | } |
467 | } | 451 | } |
@@ -472,7 +456,10 @@ public sealed class BSPrim : BSPhysObject | |||
472 | OMV.Vector3 ret = PhysicsScene.DefaultGravity; | 456 | OMV.Vector3 ret = PhysicsScene.DefaultGravity; |
473 | 457 | ||
474 | if (!IsStatic) | 458 | if (!IsStatic) |
459 | { | ||
475 | ret *= (1f - buoyancy); | 460 | ret *= (1f - buoyancy); |
461 | ret *= GravModifier; | ||
462 | } | ||
476 | 463 | ||
477 | return ret; | 464 | return ret; |
478 | } | 465 | } |
@@ -596,6 +583,74 @@ public sealed class BSPrim : BSPhysObject | |||
596 | } | 583 | } |
597 | return; | 584 | return; |
598 | } | 585 | } |
586 | public override void SetMaterial(int material) | ||
587 | { | ||
588 | base.SetMaterial(material); | ||
589 | PhysicsScene.TaintedObject("BSPrim.SetMaterial", delegate() | ||
590 | { | ||
591 | UpdatePhysicalParameters(); | ||
592 | }); | ||
593 | } | ||
594 | public override float Friction | ||
595 | { | ||
596 | get { return base.Friction; } | ||
597 | set | ||
598 | { | ||
599 | if (base.Friction != value) | ||
600 | { | ||
601 | base.Friction = value; | ||
602 | PhysicsScene.TaintedObject("BSPrim.setFriction", delegate() | ||
603 | { | ||
604 | UpdatePhysicalParameters(); | ||
605 | }); | ||
606 | } | ||
607 | } | ||
608 | } | ||
609 | public override float Restitution | ||
610 | { | ||
611 | get { return base.Restitution; } | ||
612 | set | ||
613 | { | ||
614 | if (base.Restitution != value) | ||
615 | { | ||
616 | base.Restitution = value; | ||
617 | PhysicsScene.TaintedObject("BSPrim.setRestitution", delegate() | ||
618 | { | ||
619 | UpdatePhysicalParameters(); | ||
620 | }); | ||
621 | } | ||
622 | } | ||
623 | } | ||
624 | public override float Density | ||
625 | { | ||
626 | get { return base.Density; } | ||
627 | set | ||
628 | { | ||
629 | if (base.Density != value) | ||
630 | { | ||
631 | base.Density = value; | ||
632 | PhysicsScene.TaintedObject("BSPrim.setDensity", delegate() | ||
633 | { | ||
634 | UpdatePhysicalParameters(); | ||
635 | }); | ||
636 | } | ||
637 | } | ||
638 | } | ||
639 | public override float GravModifier | ||
640 | { | ||
641 | get { return base.GravModifier; } | ||
642 | set | ||
643 | { | ||
644 | if (base.GravModifier != value) | ||
645 | { | ||
646 | base.GravModifier = value; | ||
647 | PhysicsScene.TaintedObject("BSPrim.setGravityModifier", delegate() | ||
648 | { | ||
649 | UpdatePhysicalParameters(); | ||
650 | }); | ||
651 | } | ||
652 | } | ||
653 | } | ||
599 | public override OMV.Vector3 RawVelocity | 654 | public override OMV.Vector3 RawVelocity |
600 | { | 655 | { |
601 | get { return _velocity; } | 656 | get { return _velocity; } |
@@ -761,7 +816,12 @@ public sealed class BSPrim : BSPhysObject | |||
761 | // collisionEvents: whether this object returns collision events | 816 | // collisionEvents: whether this object returns collision events |
762 | public void UpdatePhysicalParameters() | 817 | public void UpdatePhysicalParameters() |
763 | { | 818 | { |
764 | // DetailLog("{0},BSPrim.UpdatePhysicalParameters,entry,body={1},shape={2}", LocalID, BSBody, BSShape); | 819 | if (!PhysBody.HasPhysicalBody) |
820 | { | ||
821 | // This would only happen if updates are called for during initialization when the body is not set up yet. | ||
822 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,taint,calledWithNoPhysBody", LocalID); | ||
823 | return; | ||
824 | } | ||
765 | 825 | ||
766 | // Mangling all the physical properties requires the object not be in the physical world. | 826 | // Mangling all the physical properties requires the object not be in the physical world. |
767 | // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found). | 827 | // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found). |
@@ -810,8 +870,8 @@ public sealed class BSPrim : BSPhysObject | |||
810 | 870 | ||
811 | // Set various physical properties so other object interact properly | 871 | // Set various physical properties so other object interact properly |
812 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); | 872 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); |
813 | PhysicsScene.PE.SetFriction(PhysBody, matAttrib.friction); | 873 | PhysicsScene.PE.SetFriction(PhysBody, Friction); |
814 | PhysicsScene.PE.SetRestitution(PhysBody, matAttrib.restitution); | 874 | PhysicsScene.PE.SetRestitution(PhysBody, Restitution); |
815 | 875 | ||
816 | // Mass is zero which disables a bunch of physics stuff in Bullet | 876 | // Mass is zero which disables a bunch of physics stuff in Bullet |
817 | UpdatePhysicalMassProperties(0f, false); | 877 | UpdatePhysicalMassProperties(0f, false); |
@@ -839,9 +899,9 @@ public sealed class BSPrim : BSPhysObject | |||
839 | CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT); | 899 | CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT); |
840 | 900 | ||
841 | // Set various physical properties so other object interact properly | 901 | // Set various physical properties so other object interact properly |
842 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true); | 902 | PhysicsScene.PE.SetFriction(PhysBody, Friction); |
843 | PhysicsScene.PE.SetFriction(PhysBody, matAttrib.friction); | 903 | PhysicsScene.PE.SetRestitution(PhysBody, Restitution); |
844 | PhysicsScene.PE.SetRestitution(PhysBody, matAttrib.restitution); | 904 | // DetailLog("{0},BSPrim.MakeDynamic,frict={1},rest={2}", LocalID, Friction, Restitution); |
845 | 905 | ||
846 | // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 | 906 | // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 |
847 | // Since this can be called multiple times, only zero forces when becoming physical | 907 | // Since this can be called multiple times, only zero forces when becoming physical |
@@ -944,7 +1004,7 @@ public sealed class BSPrim : BSPhysObject | |||
944 | else | 1004 | else |
945 | { | 1005 | { |
946 | m_log.ErrorFormat("{0} Attempt to add physical object without body. id={1}", LogHeader, LocalID); | 1006 | m_log.ErrorFormat("{0} Attempt to add physical object without body. id={1}", LogHeader, LocalID); |
947 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,addObjectWithoutBody,cType={1}", LocalID, PhysBody.collisionType); | 1007 | DetailLog("{0},BSPrim.AddObjectToPhysicalWorld,addObjectWithoutBody,cType={1}", LocalID, PhysBody.collisionType); |
948 | } | 1008 | } |
949 | } | 1009 | } |
950 | 1010 | ||
@@ -1581,7 +1641,7 @@ public sealed class BSPrim : BSPhysObject | |||
1581 | profileEnd = 1.0f - (float)BaseShape.ProfileEnd * 2.0e-5f; | 1641 | profileEnd = 1.0f - (float)BaseShape.ProfileEnd * 2.0e-5f; |
1582 | volume *= (profileEnd - profileBegin); | 1642 | volume *= (profileEnd - profileBegin); |
1583 | 1643 | ||
1584 | returnMass = _density * volume; | 1644 | returnMass = Density * volume; |
1585 | 1645 | ||
1586 | /* Comment out code that computes the mass of the linkset. That is done in the Linkset class. | 1646 | /* Comment out code that computes the mass of the linkset. That is done in the Linkset class. |
1587 | if (IsRootOfLinkset) | 1647 | if (IsRootOfLinkset) |