aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs5
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs19
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs116
3 files changed, 105 insertions, 35 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 192bcb5..d694a6a 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -749,9 +749,10 @@ public sealed class BSCharacter : BSPhysObject
749 _buoyancy = value; 749 _buoyancy = value;
750 DetailLog("{0},BSCharacter.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); 750 DetailLog("{0},BSCharacter.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy);
751 // Buoyancy is faked by changing the gravity applied to the object 751 // Buoyancy is faked by changing the gravity applied to the object
752 float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); 752 float grav = BSParam.Gravity * (1f - _buoyancy);
753 Gravity = new OMV.Vector3(0f, 0f, grav);
753 if (PhysBody.HasPhysicalBody) 754 if (PhysBody.HasPhysicalBody)
754 PhysicsScene.PE.SetGravity(PhysBody, new OMV.Vector3(0f, 0f, grav)); 755 PhysicsScene.PE.SetGravity(PhysBody, Gravity);
755 } 756 }
756 } 757 }
757 758
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
index ec25aa9..0d8bb03 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
@@ -78,6 +78,10 @@ public abstract class BSPhysObject : PhysicsActor
78 Name = name; // PhysicsActor also has the name of the object. Someday consolidate. 78 Name = name; // PhysicsActor also has the name of the object. Someday consolidate.
79 TypeName = typeName; 79 TypeName = typeName;
80 80
81 // Initialize variables kept in base.
82 GravModifier = 1.0f;
83 Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity);
84
81 // We don't have any physical representation yet. 85 // We don't have any physical representation yet.
82 PhysBody = new BulletBody(localID); 86 PhysBody = new BulletBody(localID);
83 PhysShape = new BulletShape(); 87 PhysShape = new BulletShape();
@@ -88,8 +92,8 @@ public abstract class BSPhysObject : PhysicsActor
88 92
89 LastAssetBuildFailed = false; 93 LastAssetBuildFailed = false;
90 94
91 // Default material type 95 // Default material type. Also sets Friction, Restitution and Density.
92 Material = MaterialAttributes.Material.Wood; 96 SetMaterial((int)MaterialAttributes.Material.Wood);
93 97
94 CollisionCollection = new CollisionEventUpdate(); 98 CollisionCollection = new CollisionEventUpdate();
95 CollisionsLastTick = CollisionCollection; 99 CollisionsLastTick = CollisionCollection;
@@ -122,6 +126,8 @@ public abstract class BSPhysObject : PhysicsActor
122 // 'inWorld' true if the object has already been added to the dynamic world. 126 // 'inWorld' true if the object has already been added to the dynamic world.
123 public abstract void UpdatePhysicalMassProperties(float mass, bool inWorld); 127 public abstract void UpdatePhysicalMassProperties(float mass, bool inWorld);
124 128
129 // The gravity being applied to the object. A function of default grav, GravityModifier and Buoyancy.
130 public virtual OMV.Vector3 Gravity { get; set; }
125 // The last value calculated for the prim's inertia 131 // The last value calculated for the prim's inertia
126 public OMV.Vector3 Inertia { get; set; } 132 public OMV.Vector3 Inertia { get; set; }
127 133
@@ -164,15 +170,18 @@ public abstract class BSPhysObject : PhysicsActor
164 public override void SetMaterial(int material) 170 public override void SetMaterial(int material)
165 { 171 {
166 Material = (MaterialAttributes.Material)material; 172 Material = (MaterialAttributes.Material)material;
173
174 // Setting the material sets the material attributes also.
175 MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false);
176 Friction = matAttrib.friction;
177 Restitution = matAttrib.restitution;
178 Density = matAttrib.density;
167 } 179 }
168 180
169 // Stop all physical motion. 181 // Stop all physical motion.
170 public abstract void ZeroMotion(bool inTaintTime); 182 public abstract void ZeroMotion(bool inTaintTime);
171 public abstract void ZeroAngularMotion(bool inTaintTime); 183 public abstract void ZeroAngularMotion(bool inTaintTime);
172 184
173 // Step the vehicle simulation for this object. A NOOP if the vehicle was not configured.
174 public virtual void StepVehicle(float timeStep) { }
175
176 // Update the physical location and motion of the object. Called with data from Bullet. 185 // Update the physical location and motion of the object. Called with data from Bullet.
177 public abstract void UpdateProperties(EntityProperties entprop); 186 public abstract void UpdateProperties(EntityProperties entprop);
178 187
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)