diff options
author | Robert Adams | 2013-02-07 11:53:49 -0800 |
---|---|---|
committer | Robert Adams | 2013-02-07 17:13:27 -0800 |
commit | ebb63b55aab98da6d44e82fc0ecfd5d22f245172 (patch) | |
tree | 4c695e5e577547e5c2562f23f8bb1ad06177447f /OpenSim/Region/Physics | |
parent | Extend TestJsonReadNotecard() for reads to non-root locations and fake stores. (diff) | |
download | opensim-SC_OLD-ebb63b55aab98da6d44e82fc0ecfd5d22f245172.zip opensim-SC_OLD-ebb63b55aab98da6d44e82fc0ecfd5d22f245172.tar.gz opensim-SC_OLD-ebb63b55aab98da6d44e82fc0ecfd5d22f245172.tar.bz2 opensim-SC_OLD-ebb63b55aab98da6d44e82fc0ecfd5d22f245172.tar.xz |
BulletSim: add user setting of friction, density and restitution.
Diffstat (limited to 'OpenSim/Region/Physics')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | 5 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 17 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 99 |
3 files changed, 94 insertions, 27 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..0b35f3a 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 | GravityModifier = 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,16 @@ 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 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); | ||
174 | Friction = matAttrib.friction; | ||
175 | Restitution = matAttrib.restitution; | ||
176 | Density = matAttrib.density; | ||
167 | } | 177 | } |
168 | 178 | ||
169 | // Stop all physical motion. | 179 | // Stop all physical motion. |
170 | public abstract void ZeroMotion(bool inTaintTime); | 180 | public abstract void ZeroMotion(bool inTaintTime); |
171 | public abstract void ZeroAngularMotion(bool inTaintTime); | 181 | public abstract void ZeroAngularMotion(bool inTaintTime); |
172 | 182 | ||
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. | 183 | // Update the physical location and motion of the object. Called with data from Bullet. |
177 | public abstract void UpdateProperties(EntityProperties entprop); | 184 | public abstract void UpdateProperties(EntityProperties entprop); |
178 | 185 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 54bf063..a86932a 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(); |
@@ -457,11 +448,6 @@ public sealed class BSPrim : BSPhysObject | |||
457 | { | 448 | { |
458 | AddObjectToPhysicalWorld(); | 449 | AddObjectToPhysicalWorld(); |
459 | } | 450 | } |
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 | } | 451 | } |
466 | } | 452 | } |
467 | } | 453 | } |
@@ -469,7 +455,7 @@ public sealed class BSPrim : BSPhysObject | |||
469 | // Return what gravity should be set to this very moment | 455 | // Return what gravity should be set to this very moment |
470 | public OMV.Vector3 ComputeGravity(float buoyancy) | 456 | public OMV.Vector3 ComputeGravity(float buoyancy) |
471 | { | 457 | { |
472 | OMV.Vector3 ret = PhysicsScene.DefaultGravity; | 458 | OMV.Vector3 ret = PhysicsScene.DefaultGravity * GravityModifier; |
473 | 459 | ||
474 | if (!IsStatic) | 460 | if (!IsStatic) |
475 | ret *= (1f - buoyancy); | 461 | ret *= (1f - buoyancy); |
@@ -596,6 +582,74 @@ public sealed class BSPrim : BSPhysObject | |||
596 | } | 582 | } |
597 | return; | 583 | return; |
598 | } | 584 | } |
585 | public override void SetMaterial(int material) | ||
586 | { | ||
587 | base.SetMaterial(material); | ||
588 | PhysicsScene.TaintedObject("BSPrim.SetMaterial", delegate() | ||
589 | { | ||
590 | UpdatePhysicalParameters(); | ||
591 | }); | ||
592 | } | ||
593 | public override float Friction | ||
594 | { | ||
595 | get { return base.Friction; } | ||
596 | set | ||
597 | { | ||
598 | if (base.Friction != value) | ||
599 | { | ||
600 | base.Friction = value; | ||
601 | PhysicsScene.TaintedObject("BSPrim.setFriction", delegate() | ||
602 | { | ||
603 | UpdatePhysicalParameters(); | ||
604 | }); | ||
605 | } | ||
606 | } | ||
607 | } | ||
608 | public override float Restitution | ||
609 | { | ||
610 | get { return base.Restitution; } | ||
611 | set | ||
612 | { | ||
613 | if (base.Restitution != value) | ||
614 | { | ||
615 | base.Restitution = value; | ||
616 | PhysicsScene.TaintedObject("BSPrim.setRestitution", delegate() | ||
617 | { | ||
618 | UpdatePhysicalParameters(); | ||
619 | }); | ||
620 | } | ||
621 | } | ||
622 | } | ||
623 | public override float Density | ||
624 | { | ||
625 | get { return base.Density; } | ||
626 | set | ||
627 | { | ||
628 | if (base.Density != value) | ||
629 | { | ||
630 | base.Density = value; | ||
631 | PhysicsScene.TaintedObject("BSPrim.setDensity", delegate() | ||
632 | { | ||
633 | UpdatePhysicalParameters(); | ||
634 | }); | ||
635 | } | ||
636 | } | ||
637 | } | ||
638 | public override float GravityModifier | ||
639 | { | ||
640 | get { return base.GravityModifier; } | ||
641 | set | ||
642 | { | ||
643 | if (base.GravityModifier != value) | ||
644 | { | ||
645 | base.GravityModifier = value; | ||
646 | PhysicsScene.TaintedObject("BSPrim.setGravityModifier", delegate() | ||
647 | { | ||
648 | UpdatePhysicalParameters(); | ||
649 | }); | ||
650 | } | ||
651 | } | ||
652 | } | ||
599 | public override OMV.Vector3 RawVelocity | 653 | public override OMV.Vector3 RawVelocity |
600 | { | 654 | { |
601 | get { return _velocity; } | 655 | get { return _velocity; } |
@@ -810,8 +864,8 @@ public sealed class BSPrim : BSPhysObject | |||
810 | 864 | ||
811 | // Set various physical properties so other object interact properly | 865 | // Set various physical properties so other object interact properly |
812 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); | 866 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); |
813 | PhysicsScene.PE.SetFriction(PhysBody, matAttrib.friction); | 867 | PhysicsScene.PE.SetFriction(PhysBody, Friction); |
814 | PhysicsScene.PE.SetRestitution(PhysBody, matAttrib.restitution); | 868 | PhysicsScene.PE.SetRestitution(PhysBody, Restitution); |
815 | 869 | ||
816 | // Mass is zero which disables a bunch of physics stuff in Bullet | 870 | // Mass is zero which disables a bunch of physics stuff in Bullet |
817 | UpdatePhysicalMassProperties(0f, false); | 871 | UpdatePhysicalMassProperties(0f, false); |
@@ -840,8 +894,8 @@ public sealed class BSPrim : BSPhysObject | |||
840 | 894 | ||
841 | // Set various physical properties so other object interact properly | 895 | // Set various physical properties so other object interact properly |
842 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true); | 896 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true); |
843 | PhysicsScene.PE.SetFriction(PhysBody, matAttrib.friction); | 897 | PhysicsScene.PE.SetFriction(PhysBody, Friction); |
844 | PhysicsScene.PE.SetRestitution(PhysBody, matAttrib.restitution); | 898 | PhysicsScene.PE.SetRestitution(PhysBody, Restitution); |
845 | 899 | ||
846 | // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 | 900 | // 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 | 901 | // Since this can be called multiple times, only zero forces when becoming physical |
@@ -940,6 +994,11 @@ public sealed class BSPrim : BSPhysObject | |||
940 | if (PhysBody.HasPhysicalBody) | 994 | if (PhysBody.HasPhysicalBody) |
941 | { | 995 | { |
942 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody); | 996 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody); |
997 | |||
998 | // Must set gravity after it has been added to the world because, for unknown reasons, | ||
999 | // adding the object resets the object's gravity to world gravity | ||
1000 | OMV.Vector3 grav = ComputeGravity(Buoyancy); | ||
1001 | PhysicsScene.PE.SetGravity(PhysBody, grav); | ||
943 | } | 1002 | } |
944 | else | 1003 | else |
945 | { | 1004 | { |
@@ -1581,7 +1640,7 @@ public sealed class BSPrim : BSPhysObject | |||
1581 | profileEnd = 1.0f - (float)BaseShape.ProfileEnd * 2.0e-5f; | 1640 | profileEnd = 1.0f - (float)BaseShape.ProfileEnd * 2.0e-5f; |
1582 | volume *= (profileEnd - profileBegin); | 1641 | volume *= (profileEnd - profileBegin); |
1583 | 1642 | ||
1584 | returnMass = _density * volume; | 1643 | returnMass = Density * volume; |
1585 | 1644 | ||
1586 | /* Comment out code that computes the mass of the linkset. That is done in the Linkset class. | 1645 | /* Comment out code that computes the mass of the linkset. That is done in the Linkset class. |
1587 | if (IsRootOfLinkset) | 1646 | if (IsRootOfLinkset) |