diff options
Diffstat (limited to '')
31 files changed, 350 insertions, 211 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 041eac2..9683c38 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs | |||
@@ -2447,10 +2447,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
2447 | m_lastSize = Appearance.AvatarSize; | 2447 | m_lastSize = Appearance.AvatarSize; |
2448 | SendAvatarDataToAllAgents(); | 2448 | SendAvatarDataToAllAgents(); |
2449 | } | 2449 | } |
2450 | // Throw away duplicate or insignificant updates | ||
2451 | else if ( | ||
2452 | // If the velocity has become zero, send it no matter what. | ||
2453 | (Velocity != m_lastVelocity && Velocity == Vector3.Zero) | ||
2454 | // otherwise, if things have changed reasonably, send the update | ||
2455 | || (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) | ||
2456 | || !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) | ||
2457 | || !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE))) | ||
2450 | 2458 | ||
2451 | else if (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) || | ||
2452 | !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || | ||
2453 | !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE)) | ||
2454 | { | 2459 | { |
2455 | SendTerseUpdateToAllClients(); | 2460 | SendTerseUpdateToAllClients(); |
2456 | 2461 | ||
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSCharacter.cs index 4c4e950..d91c47f 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSCharacter.cs | |||
@@ -174,7 +174,7 @@ public sealed class BSCharacter : BSPhysObject | |||
174 | BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, BSParam.CcdSweptSphereRadius); | 174 | BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, BSParam.CcdSweptSphereRadius); |
175 | } | 175 | } |
176 | 176 | ||
177 | UpdatePhysicalMassProperties(RawMass); | 177 | UpdatePhysicalMassProperties(RawMass, false); |
178 | 178 | ||
179 | // Make so capsule does not fall over | 179 | // Make so capsule does not fall over |
180 | BulletSimAPI.SetAngularFactorV2(PhysBody.ptr, OMV.Vector3.Zero); | 180 | BulletSimAPI.SetAngularFactorV2(PhysBody.ptr, OMV.Vector3.Zero); |
@@ -224,7 +224,7 @@ public sealed class BSCharacter : BSPhysObject | |||
224 | if (PhysBody.HasPhysicalBody && PhysShape.HasPhysicalShape) | 224 | if (PhysBody.HasPhysicalBody && PhysShape.HasPhysicalShape) |
225 | { | 225 | { |
226 | BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale); | 226 | BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale); |
227 | UpdatePhysicalMassProperties(RawMass); | 227 | UpdatePhysicalMassProperties(RawMass, true); |
228 | // Make sure this change appears as a property update event | 228 | // Make sure this change appears as a property update event |
229 | BulletSimAPI.PushUpdate2(PhysBody.ptr); | 229 | BulletSimAPI.PushUpdate2(PhysBody.ptr); |
230 | } | 230 | } |
@@ -260,7 +260,6 @@ public sealed class BSCharacter : BSPhysObject | |||
260 | public override void ZeroMotion(bool inTaintTime) | 260 | public override void ZeroMotion(bool inTaintTime) |
261 | { | 261 | { |
262 | _velocity = OMV.Vector3.Zero; | 262 | _velocity = OMV.Vector3.Zero; |
263 | _velocityMotor.Zero(); | ||
264 | _acceleration = OMV.Vector3.Zero; | 263 | _acceleration = OMV.Vector3.Zero; |
265 | _rotationalVelocity = OMV.Vector3.Zero; | 264 | _rotationalVelocity = OMV.Vector3.Zero; |
266 | 265 | ||
@@ -390,7 +389,7 @@ public sealed class BSCharacter : BSPhysObject | |||
390 | public override float RawMass { | 389 | public override float RawMass { |
391 | get {return _mass; } | 390 | get {return _mass; } |
392 | } | 391 | } |
393 | public override void UpdatePhysicalMassProperties(float physMass) | 392 | public override void UpdatePhysicalMassProperties(float physMass, bool inWorld) |
394 | { | 393 | { |
395 | OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); | 394 | OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); |
396 | BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, localInertia); | 395 | BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, localInertia); |
@@ -787,6 +786,7 @@ public sealed class BSCharacter : BSPhysObject | |||
787 | // the motor can be turned off. Set the velocity to zero so the zero motion is sent to the viewer. | 786 | // the motor can be turned off. Set the velocity to zero so the zero motion is sent to the viewer. |
788 | if (_velocityMotor.TargetValue.ApproxEquals(OMV.Vector3.Zero, 0.01f) && _velocityMotor.ErrorIsZero) | 787 | if (_velocityMotor.TargetValue.ApproxEquals(OMV.Vector3.Zero, 0.01f) && _velocityMotor.ErrorIsZero) |
789 | { | 788 | { |
789 | ZeroMotion(true); | ||
790 | stepVelocity = OMV.Vector3.Zero; | 790 | stepVelocity = OMV.Vector3.Zero; |
791 | _velocityMotor.Enabled = false; | 791 | _velocityMotor.Enabled = false; |
792 | DetailLog("{0},BSCharacter.UpdateProperties,taint,disableVelocityMotor,m={1}", LocalID, _velocityMotor); | 792 | DetailLog("{0},BSCharacter.UpdateProperties,taint,disableVelocityMotor,m={1}", LocalID, _velocityMotor); |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSConstraint.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSConstraint.cs index 426bdc2..f1bed39 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSConstraint.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSConstraint.cs | |||
@@ -36,7 +36,7 @@ public abstract class BSConstraint : IDisposable | |||
36 | { | 36 | { |
37 | private static string LogHeader = "[BULLETSIM CONSTRAINT]"; | 37 | private static string LogHeader = "[BULLETSIM CONSTRAINT]"; |
38 | 38 | ||
39 | protected BulletSim m_world; | 39 | protected BulletWorld m_world; |
40 | protected BulletBody m_body1; | 40 | protected BulletBody m_body1; |
41 | protected BulletBody m_body2; | 41 | protected BulletBody m_body2; |
42 | protected BulletConstraint m_constraint; | 42 | protected BulletConstraint m_constraint; |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSConstraint6Dof.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSConstraint6Dof.cs index 0181d9d..d1e3f55 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSConstraint6Dof.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSConstraint6Dof.cs | |||
@@ -39,7 +39,7 @@ public sealed class BSConstraint6Dof : BSConstraint | |||
39 | public override ConstraintType Type { get { return ConstraintType.D6_CONSTRAINT_TYPE; } } | 39 | public override ConstraintType Type { get { return ConstraintType.D6_CONSTRAINT_TYPE; } } |
40 | 40 | ||
41 | // Create a btGeneric6DofConstraint | 41 | // Create a btGeneric6DofConstraint |
42 | public BSConstraint6Dof(BulletSim world, BulletBody obj1, BulletBody obj2, | 42 | public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2, |
43 | Vector3 frame1, Quaternion frame1rot, | 43 | Vector3 frame1, Quaternion frame1rot, |
44 | Vector3 frame2, Quaternion frame2rot, | 44 | Vector3 frame2, Quaternion frame2rot, |
45 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) | 45 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) |
@@ -58,7 +58,7 @@ public sealed class BSConstraint6Dof : BSConstraint | |||
58 | obj1.ID, obj1.ptr.ToString(), obj2.ID, obj2.ptr.ToString()); | 58 | obj1.ID, obj1.ptr.ToString(), obj2.ID, obj2.ptr.ToString()); |
59 | } | 59 | } |
60 | 60 | ||
61 | public BSConstraint6Dof(BulletSim world, BulletBody obj1, BulletBody obj2, | 61 | public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2, |
62 | Vector3 joinPoint, | 62 | Vector3 joinPoint, |
63 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) | 63 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) |
64 | { | 64 | { |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSConstraintCollection.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSConstraintCollection.cs index 5c00b1a..87d1e44 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSConstraintCollection.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSConstraintCollection.cs | |||
@@ -41,9 +41,9 @@ public sealed class BSConstraintCollection : IDisposable | |||
41 | delegate bool ConstraintAction(BSConstraint constrain); | 41 | delegate bool ConstraintAction(BSConstraint constrain); |
42 | 42 | ||
43 | private List<BSConstraint> m_constraints; | 43 | private List<BSConstraint> m_constraints; |
44 | private BulletSim m_world; | 44 | private BulletWorld m_world; |
45 | 45 | ||
46 | public BSConstraintCollection(BulletSim world) | 46 | public BSConstraintCollection(BulletWorld world) |
47 | { | 47 | { |
48 | m_world = world; | 48 | m_world = world; |
49 | m_constraints = new List<BSConstraint>(); | 49 | m_constraints = new List<BSConstraint>(); |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSConstraintHinge.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSConstraintHinge.cs index 7951f06..fbd1bc0 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSConstraintHinge.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSConstraintHinge.cs | |||
@@ -36,7 +36,7 @@ public sealed class BSConstraintHinge : BSConstraint | |||
36 | { | 36 | { |
37 | public override ConstraintType Type { get { return ConstraintType.HINGE_CONSTRAINT_TYPE; } } | 37 | public override ConstraintType Type { get { return ConstraintType.HINGE_CONSTRAINT_TYPE; } } |
38 | 38 | ||
39 | public BSConstraintHinge(BulletSim world, BulletBody obj1, BulletBody obj2, | 39 | public BSConstraintHinge(BulletWorld world, BulletBody obj1, BulletBody obj2, |
40 | Vector3 pivotInA, Vector3 pivotInB, | 40 | Vector3 pivotInA, Vector3 pivotInB, |
41 | Vector3 axisInA, Vector3 axisInB, | 41 | Vector3 axisInA, Vector3 axisInB, |
42 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) | 42 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSDynamics.cs index 72afacc..415ad4f 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSDynamics.cs | |||
@@ -573,6 +573,9 @@ namespace OpenSim.Region.Physics.BulletSNPlugin | |||
573 | BulletSimAPI.SetMassProps2(Prim.PhysBody.ptr, m_vehicleMass, localInertia); | 573 | BulletSimAPI.SetMassProps2(Prim.PhysBody.ptr, m_vehicleMass, localInertia); |
574 | BulletSimAPI.UpdateInertiaTensor2(Prim.PhysBody.ptr); | 574 | BulletSimAPI.UpdateInertiaTensor2(Prim.PhysBody.ptr); |
575 | 575 | ||
576 | Vector3 grav = PhysicsScene.DefaultGravity * (1f - Prim.Buoyancy); | ||
577 | BulletSimAPI.SetGravity2(Prim.PhysBody.ptr, grav); | ||
578 | |||
576 | VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4}", | 579 | VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4}", |
577 | Prim.LocalID, m_vehicleMass, friction, localInertia, angularDamping); | 580 | Prim.LocalID, m_vehicleMass, friction, localInertia, angularDamping); |
578 | } | 581 | } |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSLinkset.cs index 253128b..845a113 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSLinkset.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSLinkset.cs | |||
@@ -97,14 +97,7 @@ public abstract class BSLinkset | |||
97 | } | 97 | } |
98 | 98 | ||
99 | // We keep the prim's mass in the linkset structure since it could be dependent on other prims | 99 | // We keep the prim's mass in the linkset structure since it could be dependent on other prims |
100 | protected float m_mass; | 100 | public float LinksetMass { get; protected set; } |
101 | public float LinksetMass | ||
102 | { | ||
103 | get | ||
104 | { | ||
105 | return m_mass; | ||
106 | } | ||
107 | } | ||
108 | 101 | ||
109 | public virtual bool LinksetIsColliding { get { return false; } } | 102 | public virtual bool LinksetIsColliding { get { return false; } } |
110 | 103 | ||
@@ -128,7 +121,7 @@ public abstract class BSLinkset | |||
128 | PhysicsScene = scene; | 121 | PhysicsScene = scene; |
129 | LinksetRoot = parent; | 122 | LinksetRoot = parent; |
130 | m_children = new HashSet<BSPhysObject>(); | 123 | m_children = new HashSet<BSPhysObject>(); |
131 | m_mass = parent.RawMass; | 124 | LinksetMass = parent.RawMass; |
132 | Rebuilding = false; | 125 | Rebuilding = false; |
133 | } | 126 | } |
134 | 127 | ||
@@ -143,7 +136,7 @@ public abstract class BSLinkset | |||
143 | // Don't add the root to its own linkset | 136 | // Don't add the root to its own linkset |
144 | if (!IsRoot(child)) | 137 | if (!IsRoot(child)) |
145 | AddChildToLinkset(child); | 138 | AddChildToLinkset(child); |
146 | m_mass = ComputeLinksetMass(); | 139 | LinksetMass = ComputeLinksetMass(); |
147 | } | 140 | } |
148 | return this; | 141 | return this; |
149 | } | 142 | } |
@@ -162,7 +155,7 @@ public abstract class BSLinkset | |||
162 | return this; | 155 | return this; |
163 | } | 156 | } |
164 | RemoveChildFromLinkset(child); | 157 | RemoveChildFromLinkset(child); |
165 | m_mass = ComputeLinksetMass(); | 158 | LinksetMass = ComputeLinksetMass(); |
166 | } | 159 | } |
167 | 160 | ||
168 | // The child is down to a linkset of just itself | 161 | // The child is down to a linkset of just itself |
@@ -230,7 +223,10 @@ public abstract class BSLinkset | |||
230 | // When physical properties are changed the linkset needs to recalculate | 223 | // When physical properties are changed the linkset needs to recalculate |
231 | // its internal properties. | 224 | // its internal properties. |
232 | // May be called at runtime or taint-time. | 225 | // May be called at runtime or taint-time. |
233 | public abstract void Refresh(BSPhysObject requestor); | 226 | public virtual void Refresh(BSPhysObject requestor) |
227 | { | ||
228 | LinksetMass = ComputeLinksetMass(); | ||
229 | } | ||
234 | 230 | ||
235 | // Flag denoting the linkset is in the process of being rebuilt. | 231 | // Flag denoting the linkset is in the process of being rebuilt. |
236 | // Used to know not the schedule a rebuild in the middle of a rebuild. | 232 | // Used to know not the schedule a rebuild in the middle of a rebuild. |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSLinksetCompound.cs index 23a0b8b..9a977e6 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSLinksetCompound.cs | |||
@@ -89,6 +89,8 @@ public sealed class BSLinksetCompound : BSLinkset | |||
89 | // its internal properties. | 89 | // its internal properties. |
90 | public override void Refresh(BSPhysObject requestor) | 90 | public override void Refresh(BSPhysObject requestor) |
91 | { | 91 | { |
92 | base.Refresh(requestor); | ||
93 | |||
92 | // Something changed so do the rebuilding thing | 94 | // Something changed so do the rebuilding thing |
93 | // ScheduleRebuild(); | 95 | // ScheduleRebuild(); |
94 | } | 96 | } |
@@ -96,13 +98,13 @@ public sealed class BSLinksetCompound : BSLinkset | |||
96 | // Schedule a refresh to happen after all the other taint processing. | 98 | // Schedule a refresh to happen after all the other taint processing. |
97 | private void ScheduleRebuild(BSPhysObject requestor) | 99 | private void ScheduleRebuild(BSPhysObject requestor) |
98 | { | 100 | { |
99 | DetailLog("{0},BSLinksetCompound.Refresh,schedulingRefresh,rebuilding={1}", | 101 | DetailLog("{0},BSLinksetCompound.ScheduleRebuild,,rebuilding={1}", |
100 | requestor.LocalID, Rebuilding); | 102 | requestor.LocalID, Rebuilding); |
101 | // When rebuilding, it is possible to set properties that would normally require a rebuild. | 103 | // When rebuilding, it is possible to set properties that would normally require a rebuild. |
102 | // If already rebuilding, don't request another rebuild. | 104 | // If already rebuilding, don't request another rebuild. |
103 | if (!Rebuilding) | 105 | if (!Rebuilding) |
104 | { | 106 | { |
105 | PhysicsScene.PostTaintObject("BSLinksetCompound.Refresh", LinksetRoot.LocalID, delegate() | 107 | PhysicsScene.PostTaintObject("BSLinksetCompound.ScheduleRebuild", LinksetRoot.LocalID, delegate() |
106 | { | 108 | { |
107 | if (HasAnyChildren) | 109 | if (HasAnyChildren) |
108 | RecomputeLinksetCompound(); | 110 | RecomputeLinksetCompound(); |
@@ -123,7 +125,6 @@ public sealed class BSLinksetCompound : BSLinkset | |||
123 | if (IsRoot(child)) | 125 | if (IsRoot(child)) |
124 | { | 126 | { |
125 | // The root is going dynamic. Make sure mass is properly set. | 127 | // The root is going dynamic. Make sure mass is properly set. |
126 | m_mass = ComputeLinksetMass(); | ||
127 | ScheduleRebuild(LinksetRoot); | 128 | ScheduleRebuild(LinksetRoot); |
128 | } | 129 | } |
129 | else | 130 | else |
@@ -377,8 +378,8 @@ public sealed class BSLinksetCompound : BSLinkset | |||
377 | }); | 378 | }); |
378 | 379 | ||
379 | // With all of the linkset packed into the root prim, it has the mass of everyone. | 380 | // With all of the linkset packed into the root prim, it has the mass of everyone. |
380 | float linksetMass = LinksetMass; | 381 | LinksetMass = LinksetMass; |
381 | LinksetRoot.UpdatePhysicalMassProperties(linksetMass); | 382 | LinksetRoot.UpdatePhysicalMassProperties(LinksetMass, true); |
382 | } | 383 | } |
383 | finally | 384 | finally |
384 | { | 385 | { |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSLinksetConstraints.cs index 5757e64..46ff99f 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSLinksetConstraints.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSLinksetConstraints.cs | |||
@@ -46,6 +46,8 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
46 | // refresh will happen once after all the other taints are applied. | 46 | // refresh will happen once after all the other taints are applied. |
47 | public override void Refresh(BSPhysObject requestor) | 47 | public override void Refresh(BSPhysObject requestor) |
48 | { | 48 | { |
49 | base.Refresh(requestor); | ||
50 | |||
49 | // Queue to happen after all the other taint processing | 51 | // Queue to happen after all the other taint processing |
50 | PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate() | 52 | PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate() |
51 | { | 53 | { |
@@ -279,7 +281,7 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
279 | private void RecomputeLinksetConstraints() | 281 | private void RecomputeLinksetConstraints() |
280 | { | 282 | { |
281 | float linksetMass = LinksetMass; | 283 | float linksetMass = LinksetMass; |
282 | LinksetRoot.UpdatePhysicalMassProperties(linksetMass); | 284 | LinksetRoot.UpdatePhysicalMassProperties(linksetMass, true); |
283 | 285 | ||
284 | // DEBUG: see of inter-linkset collisions are causing problems | 286 | // DEBUG: see of inter-linkset collisions are causing problems |
285 | // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr, | 287 | // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr, |
@@ -292,7 +294,7 @@ public sealed class BSLinksetConstraints : BSLinkset | |||
292 | // A child in the linkset physically shows the mass of the whole linkset. | 294 | // A child in the linkset physically shows the mass of the whole linkset. |
293 | // This allows Bullet to apply enough force on the child to move the whole linkset. | 295 | // This allows Bullet to apply enough force on the child to move the whole linkset. |
294 | // (Also do the mass stuff before recomputing the constraint so mass is not zero.) | 296 | // (Also do the mass stuff before recomputing the constraint so mass is not zero.) |
295 | child.UpdatePhysicalMassProperties(linksetMass); | 297 | child.UpdatePhysicalMassProperties(linksetMass, true); |
296 | 298 | ||
297 | BSConstraint constrain; | 299 | BSConstraint constrain; |
298 | if (!PhysicsScene.Constraints.TryGetConstraint(LinksetRoot.PhysBody, child.PhysBody, out constrain)) | 300 | if (!PhysicsScene.Constraints.TryGetConstraint(LinksetRoot.PhysBody, child.PhysBody, out constrain)) |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSMaterials.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSMaterials.cs index 732191f..d7941b6 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSMaterials.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSMaterials.cs | |||
@@ -119,26 +119,26 @@ public static class BSMaterials | |||
119 | Attributes[(int)MaterialAttributes.Material.Light] = | 119 | Attributes[(int)MaterialAttributes.Material.Light] = |
120 | new MaterialAttributes("light",dDensity, dFriction, dRestitution); | 120 | new MaterialAttributes("light",dDensity, dFriction, dRestitution); |
121 | Attributes[(int)MaterialAttributes.Material.Avatar] = | 121 | Attributes[(int)MaterialAttributes.Material.Avatar] = |
122 | new MaterialAttributes("avatar",60f, 0.2f, 0f); | 122 | new MaterialAttributes("avatar",3.5f, 0.2f, 0f); |
123 | 123 | ||
124 | Attributes[(int)MaterialAttributes.Material.Stone + (int)MaterialAttributes.Material.NumberOfTypes] = | 124 | Attributes[(int)MaterialAttributes.Material.Stone + (int)MaterialAttributes.Material.NumberOfTypes] = |
125 | new MaterialAttributes("stonePhysical",dDensity, 0.8f, 0.4f); | 125 | new MaterialAttributes("stonePhysical",dDensity, 0.8f, 0.4f); |
126 | Attributes[(int)MaterialAttributes.Material.Metal + (int)MaterialAttributes.Material.NumberOfTypes] = | 126 | Attributes[(int)MaterialAttributes.Material.Metal + (int)MaterialAttributes.Material.NumberOfTypes] = |
127 | new MaterialAttributes("metalPhysical",dDensity, 0.8f, 0.4f); | 127 | new MaterialAttributes("metalPhysical",dDensity, 0.3f, 0.4f); |
128 | Attributes[(int)MaterialAttributes.Material.Glass + (int)MaterialAttributes.Material.NumberOfTypes] = | 128 | Attributes[(int)MaterialAttributes.Material.Glass + (int)MaterialAttributes.Material.NumberOfTypes] = |
129 | new MaterialAttributes("glassPhysical",dDensity, 0.8f, 0.7f); | 129 | new MaterialAttributes("glassPhysical",dDensity, 0.2f, 0.7f); |
130 | Attributes[(int)MaterialAttributes.Material.Wood + (int)MaterialAttributes.Material.NumberOfTypes] = | 130 | Attributes[(int)MaterialAttributes.Material.Wood + (int)MaterialAttributes.Material.NumberOfTypes] = |
131 | new MaterialAttributes("woodPhysical",dDensity, 0.8f, 0.5f); | 131 | new MaterialAttributes("woodPhysical",dDensity, 0.6f, 0.5f); |
132 | Attributes[(int)MaterialAttributes.Material.Flesh + (int)MaterialAttributes.Material.NumberOfTypes] = | 132 | Attributes[(int)MaterialAttributes.Material.Flesh + (int)MaterialAttributes.Material.NumberOfTypes] = |
133 | new MaterialAttributes("fleshPhysical",dDensity, 0.8f, 0.3f); | 133 | new MaterialAttributes("fleshPhysical",dDensity, 0.9f, 0.3f); |
134 | Attributes[(int)MaterialAttributes.Material.Plastic + (int)MaterialAttributes.Material.NumberOfTypes] = | 134 | Attributes[(int)MaterialAttributes.Material.Plastic + (int)MaterialAttributes.Material.NumberOfTypes] = |
135 | new MaterialAttributes("plasticPhysical",dDensity, 0.8f, 0.7f); | 135 | new MaterialAttributes("plasticPhysical",dDensity, 0.4f, 0.7f); |
136 | Attributes[(int)MaterialAttributes.Material.Rubber + (int)MaterialAttributes.Material.NumberOfTypes] = | 136 | Attributes[(int)MaterialAttributes.Material.Rubber + (int)MaterialAttributes.Material.NumberOfTypes] = |
137 | new MaterialAttributes("rubberPhysical",dDensity, 0.8f, 0.9f); | 137 | new MaterialAttributes("rubberPhysical",dDensity, 0.9f, 0.9f); |
138 | Attributes[(int)MaterialAttributes.Material.Light + (int)MaterialAttributes.Material.NumberOfTypes] = | 138 | Attributes[(int)MaterialAttributes.Material.Light + (int)MaterialAttributes.Material.NumberOfTypes] = |
139 | new MaterialAttributes("lightPhysical",dDensity, dFriction, dRestitution); | 139 | new MaterialAttributes("lightPhysical",dDensity, dFriction, dRestitution); |
140 | Attributes[(int)MaterialAttributes.Material.Avatar + (int)MaterialAttributes.Material.NumberOfTypes] = | 140 | Attributes[(int)MaterialAttributes.Material.Avatar + (int)MaterialAttributes.Material.NumberOfTypes] = |
141 | new MaterialAttributes("avatarPhysical",60f, 0.2f, 0f); | 141 | new MaterialAttributes("avatarPhysical",3.5f, 0.2f, 0f); |
142 | } | 142 | } |
143 | 143 | ||
144 | // Under the [BulletSim] section, one can change the individual material | 144 | // Under the [BulletSim] section, one can change the individual material |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSParam.cs index 20c0939..5e93a03 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSParam.cs | |||
@@ -351,7 +351,7 @@ public static class BSParam | |||
351 | (s) => { return AvatarStandingFriction; }, | 351 | (s) => { return AvatarStandingFriction; }, |
352 | (s,p,l,v) => { AvatarStandingFriction = v; } ), | 352 | (s,p,l,v) => { AvatarStandingFriction = v; } ), |
353 | new ParameterDefn("AvatarDensity", "Density of an avatar. Changed on avatar recreation.", | 353 | new ParameterDefn("AvatarDensity", "Density of an avatar. Changed on avatar recreation.", |
354 | 60f, | 354 | 3.5f, |
355 | (s,cf,p,v) => { AvatarDensity = cf.GetFloat(p, v); }, | 355 | (s,cf,p,v) => { AvatarDensity = cf.GetFloat(p, v); }, |
356 | (s) => { return AvatarDensity; }, | 356 | (s) => { return AvatarDensity; }, |
357 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarDensity=x;}, p, l, v); } ), | 357 | (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarDensity=x;}, p, l, v); } ), |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSPhysObject.cs index 4096ef8..689da7f 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSPhysObject.cs | |||
@@ -96,7 +96,8 @@ public abstract class BSPhysObject : PhysicsActor | |||
96 | // Return the object mass without calculating it or having side effects | 96 | // Return the object mass without calculating it or having side effects |
97 | public abstract float RawMass { get; } | 97 | public abstract float RawMass { get; } |
98 | // Set the raw mass but also update physical mass properties (inertia, ...) | 98 | // Set the raw mass but also update physical mass properties (inertia, ...) |
99 | public abstract void UpdatePhysicalMassProperties(float mass); | 99 | // 'inWorld' true if the object has already been added to the dynamic world. |
100 | public abstract void UpdatePhysicalMassProperties(float mass, bool inWorld); | ||
100 | 101 | ||
101 | // The last value calculated for the prim's inertia | 102 | // The last value calculated for the prim's inertia |
102 | public OMV.Vector3 Inertia { get; set; } | 103 | public OMV.Vector3 Inertia { get; set; } |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs index a889c24..9c4ba30 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs | |||
@@ -115,6 +115,8 @@ public sealed class BSPrim : BSPhysObject | |||
115 | PhysBody = new BulletBody(LocalID); | 115 | PhysBody = new BulletBody(LocalID); |
116 | PhysShape = new BulletShape(); | 116 | PhysShape = new BulletShape(); |
117 | 117 | ||
118 | Linkset.Refresh(this); | ||
119 | |||
118 | DetailLog("{0},BSPrim.constructor,call", LocalID); | 120 | DetailLog("{0},BSPrim.constructor,call", LocalID); |
119 | // do the actual object creation at taint time | 121 | // do the actual object creation at taint time |
120 | PhysicsScene.TaintedObject("BSPrim.create", delegate() | 122 | PhysicsScene.TaintedObject("BSPrim.create", delegate() |
@@ -384,13 +386,13 @@ public sealed class BSPrim : BSPhysObject | |||
384 | } | 386 | } |
385 | 387 | ||
386 | // Return the effective mass of the object. | 388 | // Return the effective mass of the object. |
387 | // If there are multiple items in the linkset, add them together for the root | 389 | // The definition of this call is to return the mass of the prim. |
390 | // If the simulator cares about the mass of the linkset, it will sum it itself. | ||
388 | public override float Mass | 391 | public override float Mass |
389 | { | 392 | { |
390 | get | 393 | get |
391 | { | 394 | { |
392 | return Linkset.LinksetMass; | 395 | return _mass; |
393 | // return _mass; | ||
394 | } | 396 | } |
395 | } | 397 | } |
396 | 398 | ||
@@ -400,22 +402,45 @@ public sealed class BSPrim : BSPhysObject | |||
400 | } | 402 | } |
401 | // Set the physical mass to the passed mass. | 403 | // Set the physical mass to the passed mass. |
402 | // Note that this does not change _mass! | 404 | // Note that this does not change _mass! |
403 | public override void UpdatePhysicalMassProperties(float physMass) | 405 | public override void UpdatePhysicalMassProperties(float physMass, bool inWorld) |
404 | { | 406 | { |
405 | if (IsStatic) | 407 | if (PhysBody.HasPhysicalBody) |
406 | { | 408 | { |
407 | Inertia = OMV.Vector3.Zero; | 409 | if (IsStatic) |
408 | BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia); | 410 | { |
409 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); | 411 | Inertia = OMV.Vector3.Zero; |
410 | } | 412 | BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia); |
411 | else | 413 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); |
412 | { | 414 | } |
413 | Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); | 415 | else |
414 | BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia); | 416 | { |
415 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); | 417 | if (inWorld) |
416 | // center of mass is at the zero of the object | 418 | { |
417 | // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation); | 419 | // Changing interesting properties doesn't change proxy and collision cache |
418 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2}", LocalID, physMass, Inertia); | 420 | // information. The Bullet solution is to re-add the object to the world |
421 | // after parameters are changed. | ||
422 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr); | ||
423 | } | ||
424 | |||
425 | Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); | ||
426 | BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia); | ||
427 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); | ||
428 | |||
429 | // center of mass is at the zero of the object | ||
430 | // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation); | ||
431 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},inWorld={3}", LocalID, physMass, Inertia, inWorld); | ||
432 | |||
433 | if (inWorld) | ||
434 | { | ||
435 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr,_position,_orientation); | ||
436 | } | ||
437 | |||
438 | // Must set gravity after it has been added to the world because, for unknown reasons, | ||
439 | // adding the object resets the object's gravity to world gravity | ||
440 | OMV.Vector3 grav = PhysicsScene.DefaultGravity * (1f - Buoyancy); | ||
441 | BulletSimAPI.SetGravity2(PhysBody.ptr, grav); | ||
442 | |||
443 | } | ||
419 | } | 444 | } |
420 | } | 445 | } |
421 | 446 | ||
@@ -714,7 +739,7 @@ public sealed class BSPrim : BSPhysObject | |||
714 | Linkset.Refresh(this); | 739 | Linkset.Refresh(this); |
715 | 740 | ||
716 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}", | 741 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}", |
717 | LocalID, IsStatic, IsSolid, _mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody, PhysShape); | 742 | LocalID, IsStatic, IsSolid, Mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody, PhysShape); |
718 | } | 743 | } |
719 | 744 | ||
720 | // "Making dynamic" means changing to and from static. | 745 | // "Making dynamic" means changing to and from static. |
@@ -737,7 +762,7 @@ public sealed class BSPrim : BSPhysObject | |||
737 | BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution); | 762 | BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution); |
738 | 763 | ||
739 | // Mass is zero which disables a bunch of physics stuff in Bullet | 764 | // Mass is zero which disables a bunch of physics stuff in Bullet |
740 | UpdatePhysicalMassProperties(0f); | 765 | UpdatePhysicalMassProperties(0f, false); |
741 | // Set collision detection parameters | 766 | // Set collision detection parameters |
742 | if (BSParam.CcdMotionThreshold > 0f) | 767 | if (BSParam.CcdMotionThreshold > 0f) |
743 | { | 768 | { |
@@ -777,7 +802,7 @@ public sealed class BSPrim : BSPhysObject | |||
777 | // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation); | 802 | // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation); |
778 | 803 | ||
779 | // A dynamic object has mass | 804 | // A dynamic object has mass |
780 | UpdatePhysicalMassProperties(RawMass); | 805 | UpdatePhysicalMassProperties(RawMass, false); |
781 | 806 | ||
782 | // Set collision detection parameters | 807 | // Set collision detection parameters |
783 | if (BSParam.CcdMotionThreshold > 0f) | 808 | if (BSParam.CcdMotionThreshold > 0f) |
@@ -950,13 +975,9 @@ public sealed class BSPrim : BSPhysObject | |||
950 | set { | 975 | set { |
951 | _buoyancy = value; | 976 | _buoyancy = value; |
952 | // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | 977 | // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); |
953 | // Buoyancy is faked by changing the gravity applied to the object | 978 | // Force the recalculation of the various inertia,etc variables in the object |
954 | if (PhysBody.HasPhysicalBody) | 979 | UpdatePhysicalMassProperties(_mass, true); |
955 | { | 980 | ActivateIfPhysical(false); |
956 | float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); | ||
957 | BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); | ||
958 | ActivateIfPhysical(false); | ||
959 | } | ||
960 | } | 981 | } |
961 | } | 982 | } |
962 | 983 | ||
@@ -993,7 +1014,9 @@ public sealed class BSPrim : BSPhysObject | |||
993 | public override float APIDDamping { set { return; } } | 1014 | public override float APIDDamping { set { return; } } |
994 | 1015 | ||
995 | public override void AddForce(OMV.Vector3 force, bool pushforce) { | 1016 | public override void AddForce(OMV.Vector3 force, bool pushforce) { |
996 | AddForce(force, pushforce, false); | 1017 | // Since this force is being applied in only one step, make this a force per second. |
1018 | OMV.Vector3 addForce = force / PhysicsScene.LastTimeStep; | ||
1019 | AddForce(addForce, pushforce, false); | ||
997 | } | 1020 | } |
998 | // Applying a force just adds this to the total force on the object. | 1021 | // Applying a force just adds this to the total force on the object. |
999 | // This added force will only last the next simulation tick. | 1022 | // This added force will only last the next simulation tick. |
@@ -1001,8 +1024,16 @@ public sealed class BSPrim : BSPhysObject | |||
1001 | // for an object, doesn't matter if force is a pushforce or not | 1024 | // for an object, doesn't matter if force is a pushforce or not |
1002 | if (force.IsFinite()) | 1025 | if (force.IsFinite()) |
1003 | { | 1026 | { |
1027 | float magnitude = force.Length(); | ||
1028 | if (magnitude > 20000f) | ||
1029 | { | ||
1030 | // Force has a limit | ||
1031 | force = force / magnitude * 20000f; | ||
1032 | } | ||
1033 | |||
1004 | OMV.Vector3 addForce = force; | 1034 | OMV.Vector3 addForce = force; |
1005 | DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce); | 1035 | DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce); |
1036 | |||
1006 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate() | 1037 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate() |
1007 | { | 1038 | { |
1008 | // Bullet adds this central force to the total force for this tick | 1039 | // Bullet adds this central force to the total force for this tick |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSScene.cs index 6bcea3f..1a7c34b 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSScene.cs | |||
@@ -74,7 +74,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
74 | 74 | ||
75 | public IMesher mesher; | 75 | public IMesher mesher; |
76 | public uint WorldID { get; private set; } | 76 | public uint WorldID { get; private set; } |
77 | public BulletSim World { get; private set; } | 77 | public BulletWorld World { get; private set; } |
78 | 78 | ||
79 | // All the constraints that have been allocated in this instance. | 79 | // All the constraints that have been allocated in this instance. |
80 | public BSConstraintCollection Constraints { get; private set; } | 80 | public BSConstraintCollection Constraints { get; private set; } |
@@ -244,7 +244,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
244 | 244 | ||
245 | // m_log.DebugFormat("{0}: Initialize: Calling BulletSimAPI.Initialize.", LogHeader); | 245 | // m_log.DebugFormat("{0}: Initialize: Calling BulletSimAPI.Initialize.", LogHeader); |
246 | 246 | ||
247 | World = new BulletSim(0, this, BulletSimAPI.Initialize2(worldExtent, UnmanagedParams, | 247 | World = new BulletWorld(0, this, BulletSimAPI.Initialize2(worldExtent, UnmanagedParams, |
248 | m_maxCollisionsPerFrame, ref m_collisionArray, | 248 | m_maxCollisionsPerFrame, ref m_collisionArray, |
249 | m_maxUpdatesPerFrame,ref m_updateArray, | 249 | m_maxUpdatesPerFrame,ref m_updateArray, |
250 | m_DebugLogCallbackHandle)); | 250 | m_DebugLogCallbackHandle)); |
@@ -497,13 +497,16 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
497 | 497 | ||
498 | InTaintTime = false; // Only used for debugging so locking is not necessary. | 498 | InTaintTime = false; // Only used for debugging so locking is not necessary. |
499 | 499 | ||
500 | // The following causes the unmanaged code to output ALL the values found in ALL the objects in the world. | ||
501 | // Only enable this in a limited test world with few objects. | ||
502 | // BulletSimAPI.DumpAllInfo2(World.ptr); // DEBUG DEBUG DEBUG | ||
503 | |||
500 | // step the physical world one interval | 504 | // step the physical world one interval |
501 | m_simulationStep++; | 505 | m_simulationStep++; |
502 | int numSubSteps = 0; | 506 | int numSubSteps = 0; |
503 | 507 | ||
504 | try | 508 | try |
505 | { | 509 | { |
506 | //if (VehicleLoggingEnabled) DumpVehicles(); // DEBUG | ||
507 | if (PhysicsLogging.Enabled) beforeTime = Util.EnvironmentTickCount(); | 510 | if (PhysicsLogging.Enabled) beforeTime = Util.EnvironmentTickCount(); |
508 | 511 | ||
509 | numSubSteps = BulletSimAPI.PhysicsStep2(World.ptr, timeStep, m_maxSubSteps, m_fixedTimeStep, | 512 | numSubSteps = BulletSimAPI.PhysicsStep2(World.ptr, timeStep, m_maxSubSteps, m_fixedTimeStep, |
@@ -833,7 +836,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
833 | { | 836 | { |
834 | DetailLog("{0},BSScene.AssertInTaintTime,NOT IN TAINT TIME,Region={1},Where={2}", DetailLogZero, RegionName, whereFrom); | 837 | DetailLog("{0},BSScene.AssertInTaintTime,NOT IN TAINT TIME,Region={1},Where={2}", DetailLogZero, RegionName, whereFrom); |
835 | m_log.ErrorFormat("{0} NOT IN TAINT TIME!! Region={1}, Where={2}", LogHeader, RegionName, whereFrom); | 838 | m_log.ErrorFormat("{0} NOT IN TAINT TIME!! Region={1}, Where={2}", LogHeader, RegionName, whereFrom); |
836 | Util.PrintCallStack(); // Prints the stack into the DEBUG log file. | 839 | Util.PrintCallStack(DetailLog); |
837 | } | 840 | } |
838 | return InTaintTime; | 841 | return InTaintTime; |
839 | } | 842 | } |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSShapeCollection.cs index 398ece0..764aece 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSShapeCollection.cs | |||
@@ -98,7 +98,7 @@ public sealed class BSShapeCollection : IDisposable | |||
98 | // higher level dependencies on the shape or body. Mostly used for LinkSets to | 98 | // higher level dependencies on the shape or body. Mostly used for LinkSets to |
99 | // remove the physical constraints before the body is destroyed. | 99 | // remove the physical constraints before the body is destroyed. |
100 | // Called at taint-time!! | 100 | // Called at taint-time!! |
101 | public bool GetBodyAndShape(bool forceRebuild, BulletSim sim, BSPhysObject prim, | 101 | public bool GetBodyAndShape(bool forceRebuild, BulletWorld sim, BSPhysObject prim, |
102 | ShapeDestructionCallback shapeCallback, BodyDestructionCallback bodyCallback) | 102 | ShapeDestructionCallback shapeCallback, BodyDestructionCallback bodyCallback) |
103 | { | 103 | { |
104 | PhysicsScene.AssertInTaintTime("BSShapeCollection.GetBodyAndShape"); | 104 | PhysicsScene.AssertInTaintTime("BSShapeCollection.GetBodyAndShape"); |
@@ -126,7 +126,7 @@ public sealed class BSShapeCollection : IDisposable | |||
126 | return ret; | 126 | return ret; |
127 | } | 127 | } |
128 | 128 | ||
129 | public bool GetBodyAndShape(bool forceRebuild, BulletSim sim, BSPhysObject prim) | 129 | public bool GetBodyAndShape(bool forceRebuild, BulletWorld sim, BSPhysObject prim) |
130 | { | 130 | { |
131 | return GetBodyAndShape(forceRebuild, sim, prim, null, null); | 131 | return GetBodyAndShape(forceRebuild, sim, prim, null, null); |
132 | } | 132 | } |
@@ -637,7 +637,7 @@ public sealed class BSShapeCollection : IDisposable | |||
637 | } | 637 | } |
638 | else | 638 | else |
639 | { | 639 | { |
640 | meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, true, false); | 640 | meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, true, false, false, false); |
641 | 641 | ||
642 | if (meshData != null) | 642 | if (meshData != null) |
643 | { | 643 | { |
@@ -709,7 +709,7 @@ public sealed class BSShapeCollection : IDisposable | |||
709 | { | 709 | { |
710 | // Build a new hull in the physical world | 710 | // Build a new hull in the physical world |
711 | // Pass true for physicalness as this creates some sort of bounding box which we don't need | 711 | // Pass true for physicalness as this creates some sort of bounding box which we don't need |
712 | IMesh meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, true, false); | 712 | IMesh meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, true, false, false, false); |
713 | if (meshData != null) | 713 | if (meshData != null) |
714 | { | 714 | { |
715 | 715 | ||
@@ -918,7 +918,7 @@ public sealed class BSShapeCollection : IDisposable | |||
918 | // Updates prim.BSBody with the information about the new body if one is created. | 918 | // Updates prim.BSBody with the information about the new body if one is created. |
919 | // Returns 'true' if an object was actually created. | 919 | // Returns 'true' if an object was actually created. |
920 | // Called at taint-time. | 920 | // Called at taint-time. |
921 | private bool CreateBody(bool forceRebuild, BSPhysObject prim, BulletSim sim, BulletShape shape, | 921 | private bool CreateBody(bool forceRebuild, BSPhysObject prim, BulletWorld sim, BulletShape shape, |
922 | BodyDestructionCallback bodyCallback) | 922 | BodyDestructionCallback bodyCallback) |
923 | { | 923 | { |
924 | bool ret = false; | 924 | bool ret = false; |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainHeightmap.cs index 252953b..ba17059 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainHeightmap.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainHeightmap.cs | |||
@@ -103,7 +103,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
103 | Vector3 centerPos; | 103 | Vector3 centerPos; |
104 | centerPos.X = m_mapInfo.minCoords.X + (m_mapInfo.sizeX / 2f); | 104 | centerPos.X = m_mapInfo.minCoords.X + (m_mapInfo.sizeX / 2f); |
105 | centerPos.Y = m_mapInfo.minCoords.Y + (m_mapInfo.sizeY / 2f); | 105 | centerPos.Y = m_mapInfo.minCoords.Y + (m_mapInfo.sizeY / 2f); |
106 | centerPos.Z = m_mapInfo.minZ + ((m_mapInfo.maxZ - m_mapInfo.minZ) / 2f + 0.5f); | 106 | centerPos.Z = m_mapInfo.minZ + ((m_mapInfo.maxZ - m_mapInfo.minZ) / 2f - 0.5f); |
107 | 107 | ||
108 | m_mapInfo.terrainBody = new BulletBody(m_mapInfo.ID, | 108 | m_mapInfo.terrainBody = new BulletBody(m_mapInfo.ID, |
109 | BulletSimAPI.CreateBodyWithDefaultMotionState2(m_mapInfo.terrainShape.ptr, | 109 | BulletSimAPI.CreateBodyWithDefaultMotionState2(m_mapInfo.terrainShape.ptr, |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainManager.cs index dfad70e..66d62f0 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainManager.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainManager.cs | |||
@@ -140,7 +140,7 @@ public sealed class BSTerrainManager : IDisposable | |||
140 | m_groundPlane = new BulletBody(BSScene.GROUNDPLANE_ID, | 140 | m_groundPlane = new BulletBody(BSScene.GROUNDPLANE_ID, |
141 | BulletSimAPI.CreateBodyWithDefaultMotionState2(groundPlaneShape.ptr, BSScene.GROUNDPLANE_ID, | 141 | BulletSimAPI.CreateBodyWithDefaultMotionState2(groundPlaneShape.ptr, BSScene.GROUNDPLANE_ID, |
142 | Vector3.Zero, Quaternion.Identity)); | 142 | Vector3.Zero, Quaternion.Identity)); |
143 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr); | 143 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr, Vector3.Zero, Quaternion.Identity); |
144 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_groundPlane.ptr); | 144 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_groundPlane.ptr); |
145 | // Ground plane does not move | 145 | // Ground plane does not move |
146 | BulletSimAPI.ForceActivationState2(m_groundPlane.ptr, ActivationState.DISABLE_SIMULATION); | 146 | BulletSimAPI.ForceActivationState2(m_groundPlane.ptr, ActivationState.DISABLE_SIMULATION); |
@@ -376,6 +376,7 @@ public sealed class BSTerrainManager : IDisposable | |||
376 | DetailLog("{0},BSTerrainManager.GetTerrainHeightAtXYZ,terrainNotFound,pos={1},base={2}", | 376 | DetailLog("{0},BSTerrainManager.GetTerrainHeightAtXYZ,terrainNotFound,pos={1},base={2}", |
377 | BSScene.DetailLogZero, pos, terrainBaseXYZ); | 377 | BSScene.DetailLogZero, pos, terrainBaseXYZ); |
378 | } | 378 | } |
379 | |||
379 | lastHeight = ret; | 380 | lastHeight = ret; |
380 | return ret; | 381 | return ret; |
381 | } | 382 | } |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSNPlugin/BulletSimAPI.cs index 6af59d6..93643c9 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BulletSimAPI.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BulletSimAPI.cs | |||
@@ -58,7 +58,6 @@ public enum ConstraintType : int | |||
58 | MAX_CONSTRAINT_TYPE | 58 | MAX_CONSTRAINT_TYPE |
59 | } | 59 | } |
60 | 60 | ||
61 | |||
62 | // =============================================================================== | 61 | // =============================================================================== |
63 | [StructLayout(LayoutKind.Sequential)] | 62 | [StructLayout(LayoutKind.Sequential)] |
64 | public struct ConvexHull | 63 | public struct ConvexHull |
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSNPlugin/BulletSimData.cs index a1ed8d8..f509dc4 100644 --- a/OpenSim/Region/Physics/BulletSNPlugin/BulletSimData.cs +++ b/OpenSim/Region/Physics/BulletSNPlugin/BulletSimData.cs | |||
@@ -35,9 +35,9 @@ namespace OpenSim.Region.Physics.BulletSNPlugin | |||
35 | // These hold pointers to allocated objects in the unmanaged space. | 35 | // These hold pointers to allocated objects in the unmanaged space. |
36 | 36 | ||
37 | // The physics engine controller class created at initialization | 37 | // The physics engine controller class created at initialization |
38 | public struct BulletSim | 38 | public struct BulletWorld |
39 | { | 39 | { |
40 | public BulletSim(uint worldId, BSScene bss, object xx) | 40 | public BulletWorld(uint worldId, BSScene bss, object xx) |
41 | { | 41 | { |
42 | ptr = xx; | 42 | ptr = xx; |
43 | worldID = worldId; | 43 | worldID = worldId; |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index bf0545a..3f7b5e1 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | |||
@@ -260,7 +260,6 @@ public sealed class BSCharacter : BSPhysObject | |||
260 | public override void ZeroMotion(bool inTaintTime) | 260 | public override void ZeroMotion(bool inTaintTime) |
261 | { | 261 | { |
262 | _velocity = OMV.Vector3.Zero; | 262 | _velocity = OMV.Vector3.Zero; |
263 | _velocityMotor.Zero(); | ||
264 | _acceleration = OMV.Vector3.Zero; | 263 | _acceleration = OMV.Vector3.Zero; |
265 | _rotationalVelocity = OMV.Vector3.Zero; | 264 | _rotationalVelocity = OMV.Vector3.Zero; |
266 | 265 | ||
@@ -585,18 +584,6 @@ public sealed class BSCharacter : BSPhysObject | |||
585 | get { return _throttleUpdates; } | 584 | get { return _throttleUpdates; } |
586 | set { _throttleUpdates = value; } | 585 | set { _throttleUpdates = value; } |
587 | } | 586 | } |
588 | public override bool IsColliding { | ||
589 | get { return (CollidingStep == PhysicsScene.SimulationStep); } | ||
590 | set { _isColliding = value; } | ||
591 | } | ||
592 | public override bool CollidingGround { | ||
593 | get { return (CollidingGroundStep == PhysicsScene.SimulationStep); } | ||
594 | set { CollidingGround = value; } | ||
595 | } | ||
596 | public override bool CollidingObj { | ||
597 | get { return _collidingObj; } | ||
598 | set { _collidingObj = value; } | ||
599 | } | ||
600 | public override bool FloatOnWater { | 587 | public override bool FloatOnWater { |
601 | set { | 588 | set { |
602 | _floatOnWater = value; | 589 | _floatOnWater = value; |
@@ -684,22 +671,31 @@ public sealed class BSCharacter : BSPhysObject | |||
684 | public override void AddForce(OMV.Vector3 force, bool pushforce) { | 671 | public override void AddForce(OMV.Vector3 force, bool pushforce) { |
685 | if (force.IsFinite()) | 672 | if (force.IsFinite()) |
686 | { | 673 | { |
687 | _force.X += force.X; | 674 | float magnitude = force.Length(); |
688 | _force.Y += force.Y; | 675 | if (magnitude > BSParam.MaxAddForceMagnitude) |
689 | _force.Z += force.Z; | 676 | { |
690 | // m_log.DebugFormat("{0}: AddForce. adding={1}, newForce={2}", LogHeader, force, _force); | 677 | // Force has a limit |
678 | force = force / magnitude * BSParam.MaxAddForceMagnitude; | ||
679 | } | ||
680 | |||
681 | OMV.Vector3 addForce = force / PhysicsScene.LastTimeStep; | ||
682 | DetailLog("{0},BSCharacter.addForce,call,force={1}", LocalID, addForce); | ||
683 | |||
691 | PhysicsScene.TaintedObject("BSCharacter.AddForce", delegate() | 684 | PhysicsScene.TaintedObject("BSCharacter.AddForce", delegate() |
692 | { | 685 | { |
693 | DetailLog("{0},BSCharacter.setAddForce,taint,addedForce={1}", LocalID, _force); | 686 | // Bullet adds this central force to the total force for this tick |
687 | DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce); | ||
694 | if (PhysBody.HasPhysicalBody) | 688 | if (PhysBody.HasPhysicalBody) |
695 | BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); | 689 | { |
690 | BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, addForce); | ||
691 | } | ||
696 | }); | 692 | }); |
697 | } | 693 | } |
698 | else | 694 | else |
699 | { | 695 | { |
700 | m_log.ErrorFormat("{0}: Got a NaN force applied to a Character", LogHeader); | 696 | m_log.WarnFormat("{0}: Got a NaN force applied to a character. LocalID={1}", LogHeader, LocalID); |
697 | return; | ||
701 | } | 698 | } |
702 | //m_lastUpdateSent = false; | ||
703 | } | 699 | } |
704 | 700 | ||
705 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { | 701 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { |
@@ -761,22 +757,26 @@ public sealed class BSCharacter : BSPhysObject | |||
761 | 757 | ||
762 | OMV.Vector3 stepVelocity = _velocityMotor.Step(PhysicsScene.LastTimeStep); | 758 | OMV.Vector3 stepVelocity = _velocityMotor.Step(PhysicsScene.LastTimeStep); |
763 | 759 | ||
764 | // If falling, we keep the world's downward vector no matter what the other axis specify. | 760 | // Check for cases to turn off the motor. |
765 | if (!Flying && !IsColliding) | 761 | if ( |
766 | { | 762 | // If the walking motor is all done, turn it off |
767 | stepVelocity.Z = entprop.Velocity.Z; | 763 | (_velocityMotor.TargetValue.ApproxEquals(OMV.Vector3.Zero, 0.01f) && _velocityMotor.ErrorIsZero) ) |
768 | DetailLog("{0},BSCharacter.UpdateProperties,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity); | ||
769 | } | ||
770 | |||
771 | // If the user has said stop and we've stopped applying velocity correction, | ||
772 | // the motor can be turned off. Set the velocity to zero so the zero motion is sent to the viewer. | ||
773 | if (_velocityMotor.TargetValue.ApproxEquals(OMV.Vector3.Zero, 0.01f) && _velocityMotor.ErrorIsZero) | ||
774 | { | 764 | { |
775 | _velocityMotor.Enabled = false; | ||
776 | stepVelocity = OMV.Vector3.Zero; | ||
777 | ZeroMotion(true); | 765 | ZeroMotion(true); |
766 | stepVelocity = OMV.Vector3.Zero; | ||
767 | _velocityMotor.Enabled = false; | ||
778 | DetailLog("{0},BSCharacter.UpdateProperties,taint,disableVelocityMotor,m={1}", LocalID, _velocityMotor); | 768 | DetailLog("{0},BSCharacter.UpdateProperties,taint,disableVelocityMotor,m={1}", LocalID, _velocityMotor); |
779 | } | 769 | } |
770 | else | ||
771 | { | ||
772 | // If the motor is not being turned off... | ||
773 | // If falling, we keep the world's downward vector no matter what the other axis specify. | ||
774 | if (!Flying && !IsColliding) | ||
775 | { | ||
776 | stepVelocity.Z = entprop.Velocity.Z; | ||
777 | DetailLog("{0},BSCharacter.UpdateProperties,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity); | ||
778 | } | ||
779 | } | ||
780 | 780 | ||
781 | _velocity = stepVelocity; | 781 | _velocity = stepVelocity; |
782 | entprop.Velocity = _velocity; | 782 | entprop.Velocity = _velocity; |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 3fde57b..0bdfbe3 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |||
@@ -573,6 +573,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
573 | BulletSimAPI.SetMassProps2(Prim.PhysBody.ptr, m_vehicleMass, localInertia); | 573 | BulletSimAPI.SetMassProps2(Prim.PhysBody.ptr, m_vehicleMass, localInertia); |
574 | BulletSimAPI.UpdateInertiaTensor2(Prim.PhysBody.ptr); | 574 | BulletSimAPI.UpdateInertiaTensor2(Prim.PhysBody.ptr); |
575 | 575 | ||
576 | Vector3 grav = PhysicsScene.DefaultGravity * (1f - Prim.Buoyancy); | ||
577 | BulletSimAPI.SetGravity2(Prim.PhysBody.ptr, grav); | ||
578 | |||
576 | VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4}", | 579 | VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4}", |
577 | Prim.LocalID, m_vehicleMass, friction, localInertia, angularDamping); | 580 | Prim.LocalID, m_vehicleMass, friction, localInertia, angularDamping); |
578 | } | 581 | } |
@@ -819,6 +822,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
819 | { | 822 | { |
820 | if (!IsActive) return; | 823 | if (!IsActive) return; |
821 | 824 | ||
825 | if (PhysicsScene.VehiclePhysicalLoggingEnabled) | ||
826 | BulletSimAPI.DumpRigidBody2(PhysicsScene.World.ptr, Prim.PhysBody.ptr); | ||
827 | |||
822 | ForgetKnownVehicleProperties(); | 828 | ForgetKnownVehicleProperties(); |
823 | 829 | ||
824 | MoveLinear(pTimestep); | 830 | MoveLinear(pTimestep); |
@@ -833,6 +839,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
833 | // for the physics engine to note the changes so an UpdateProperties event will happen. | 839 | // for the physics engine to note the changes so an UpdateProperties event will happen. |
834 | PushKnownChanged(); | 840 | PushKnownChanged(); |
835 | 841 | ||
842 | if (PhysicsScene.VehiclePhysicalLoggingEnabled) | ||
843 | BulletSimAPI.DumpRigidBody2(PhysicsScene.World.ptr, Prim.PhysBody.ptr); | ||
844 | |||
836 | VDetailLog("{0},BSDynamics.Step,done,pos={1},force={2},velocity={3},angvel={4}", | 845 | VDetailLog("{0},BSDynamics.Step,done,pos={1},force={2},velocity={3},angvel={4}", |
837 | Prim.LocalID, VehiclePosition, Prim.Force, VehicleVelocity, VehicleRotationalVelocity); | 846 | Prim.LocalID, VehiclePosition, Prim.Force, VehicleVelocity, VehicleRotationalVelocity); |
838 | } | 847 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index d5cbf5f..19ce62b 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs | |||
@@ -5,7 +5,7 @@ | |||
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclat simer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyrightD | 9 | * * Redistributions in binary form must reproduce the above copyrightD |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
@@ -98,11 +98,12 @@ public sealed class BSLinksetCompound : BSLinkset | |||
98 | // Schedule a refresh to happen after all the other taint processing. | 98 | // Schedule a refresh to happen after all the other taint processing. |
99 | private void ScheduleRebuild(BSPhysObject requestor) | 99 | private void ScheduleRebuild(BSPhysObject requestor) |
100 | { | 100 | { |
101 | DetailLog("{0},BSLinksetCompound.ScheduleRebuild,,rebuilding={1}", | 101 | DetailLog("{0},BSLinksetCompound.ScheduleRebuild,,rebuilding={1},hasChildren={2}", |
102 | requestor.LocalID, Rebuilding); | 102 | requestor.LocalID, Rebuilding, HasAnyChildren); |
103 | // When rebuilding, it is possible to set properties that would normally require a rebuild. | 103 | // When rebuilding, it is possible to set properties that would normally require a rebuild. |
104 | // If already rebuilding, don't request another rebuild. | 104 | // If already rebuilding, don't request another rebuild. |
105 | if (!Rebuilding) | 105 | // If a linkset with just a root prim (simple non-linked prim) don't bother rebuilding. |
106 | if (!Rebuilding && HasAnyChildren) | ||
106 | { | 107 | { |
107 | PhysicsScene.PostTaintObject("BSLinksetCompound.ScheduleRebuild", LinksetRoot.LocalID, delegate() | 108 | PhysicsScene.PostTaintObject("BSLinksetCompound.ScheduleRebuild", LinksetRoot.LocalID, delegate() |
108 | { | 109 | { |
@@ -112,8 +113,7 @@ public sealed class BSLinksetCompound : BSLinkset | |||
112 | } | 113 | } |
113 | } | 114 | } |
114 | 115 | ||
115 | // The object is going dynamic (physical). Do any setup necessary | 116 | // The object is going dynamic (physical). Do any setup necessary for a dynamic linkset. |
116 | // for a dynamic linkset. | ||
117 | // Only the state of the passed object can be modified. The rest of the linkset | 117 | // Only the state of the passed object can be modified. The rest of the linkset |
118 | // has not yet been fully constructed. | 118 | // has not yet been fully constructed. |
119 | // Return 'true' if any properties updated on the passed object. | 119 | // Return 'true' if any properties updated on the passed object. |
@@ -124,7 +124,7 @@ public sealed class BSLinksetCompound : BSLinkset | |||
124 | DetailLog("{0},BSLinksetCompound.MakeDynamic,call,IsRoot={1}", child.LocalID, IsRoot(child)); | 124 | DetailLog("{0},BSLinksetCompound.MakeDynamic,call,IsRoot={1}", child.LocalID, IsRoot(child)); |
125 | if (IsRoot(child)) | 125 | if (IsRoot(child)) |
126 | { | 126 | { |
127 | // The root is going dynamic. Make sure mass is properly set. | 127 | // The root is going dynamic. Rebuild the linkset so parts and mass get computed properly. |
128 | ScheduleRebuild(LinksetRoot); | 128 | ScheduleRebuild(LinksetRoot); |
129 | } | 129 | } |
130 | else | 130 | else |
@@ -378,7 +378,7 @@ public sealed class BSLinksetCompound : BSLinkset | |||
378 | }); | 378 | }); |
379 | 379 | ||
380 | // With all of the linkset packed into the root prim, it has the mass of everyone. | 380 | // With all of the linkset packed into the root prim, it has the mass of everyone. |
381 | LinksetMass = LinksetMass; | 381 | LinksetMass = ComputeLinksetMass(); |
382 | LinksetRoot.UpdatePhysicalMassProperties(LinksetMass, true); | 382 | LinksetRoot.UpdatePhysicalMassProperties(LinksetMass, true); |
383 | } | 383 | } |
384 | finally | 384 | finally |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs index 9e1a9ba..817a5f7 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | |||
@@ -241,8 +241,8 @@ public class BSVMotor : BSMotor | |||
241 | 241 | ||
242 | public override string ToString() | 242 | public override string ToString() |
243 | { | 243 | { |
244 | return String.Format("<{0},curr={1},targ={2},decayTS={3},frictTS={4}>", | 244 | return String.Format("<{0},curr={1},targ={2},lastErr={3},decayTS={4},frictTS={5}>", |
245 | UseName, CurrentValue, TargetValue, TargetValueDecayTimeScale, FrictionTimescale); | 245 | UseName, CurrentValue, TargetValue, LastError, TargetValueDecayTimeScale, FrictionTimescale); |
246 | } | 246 | } |
247 | } | 247 | } |
248 | 248 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index 7454718..f8f24bd 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | |||
@@ -89,6 +89,18 @@ public static class BSParam | |||
89 | public static float PID_D { get; private set; } // derivative | 89 | public static float PID_D { get; private set; } // derivative |
90 | public static float PID_P { get; private set; } // proportional | 90 | public static float PID_P { get; private set; } // proportional |
91 | 91 | ||
92 | // Various constants that come from that other virtual world that shall not be named | ||
93 | public const float MinGravityZ = -1f; | ||
94 | public const float MaxGravityZ = 28f; | ||
95 | public const float MinFriction = 0f; | ||
96 | public const float MaxFriction = 255f; | ||
97 | public const float MinDensity = 0f; | ||
98 | public const float MaxDensity = 22587f; | ||
99 | public const float MinRestitution = 0f; | ||
100 | public const float MaxRestitution = 1f; | ||
101 | public const float MaxAddForceMagnitude = 20000f; | ||
102 | |||
103 | // =========================================================================== | ||
92 | public delegate void ParamUser(BSScene scene, IConfig conf, string paramName, float val); | 104 | public delegate void ParamUser(BSScene scene, IConfig conf, string paramName, float val); |
93 | public delegate float ParamGet(BSScene scene); | 105 | public delegate float ParamGet(BSScene scene); |
94 | public delegate void ParamSet(BSScene scene, string paramName, uint localID, float val); | 106 | public delegate void ParamSet(BSScene scene, string paramName, uint localID, float val); |
@@ -200,6 +212,11 @@ public static class BSParam | |||
200 | (s,cf,p,v) => { s.m_fixedTimeStep = cf.GetFloat(p, v); }, | 212 | (s,cf,p,v) => { s.m_fixedTimeStep = cf.GetFloat(p, v); }, |
201 | (s) => { return (float)s.m_fixedTimeStep; }, | 213 | (s) => { return (float)s.m_fixedTimeStep; }, |
202 | (s,p,l,v) => { s.m_fixedTimeStep = v; } ), | 214 | (s,p,l,v) => { s.m_fixedTimeStep = v; } ), |
215 | new ParameterDefn("NominalFrameRate", "The base frame rate we claim", | ||
216 | 55f, | ||
217 | (s,cf,p,v) => { s.NominalFrameRate = cf.GetInt(p, (int)v); }, | ||
218 | (s) => { return (float)s.NominalFrameRate; }, | ||
219 | (s,p,l,v) => { s.NominalFrameRate = (int)v; } ), | ||
203 | new ParameterDefn("MaxCollisionsPerFrame", "Max collisions returned at end of each frame", | 220 | new ParameterDefn("MaxCollisionsPerFrame", "Max collisions returned at end of each frame", |
204 | 2048f, | 221 | 2048f, |
205 | (s,cf,p,v) => { s.m_maxCollisionsPerFrame = cf.GetInt(p, (int)v); }, | 222 | (s,cf,p,v) => { s.m_maxCollisionsPerFrame = cf.GetInt(p, (int)v); }, |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 4bed535..73b5764 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | |||
@@ -182,9 +182,40 @@ public abstract class BSPhysObject : PhysicsActor | |||
182 | protected long CollidingStep { get; set; } | 182 | protected long CollidingStep { get; set; } |
183 | // The simulation step that last had a collision with the ground | 183 | // The simulation step that last had a collision with the ground |
184 | protected long CollidingGroundStep { get; set; } | 184 | protected long CollidingGroundStep { get; set; } |
185 | // The simulation step that last collided with an object | ||
186 | protected long CollidingObjectStep { get; set; } | ||
185 | // The collision flags we think are set in Bullet | 187 | // The collision flags we think are set in Bullet |
186 | protected CollisionFlags CurrentCollisionFlags { get; set; } | 188 | protected CollisionFlags CurrentCollisionFlags { get; set; } |
187 | 189 | ||
190 | public override bool IsColliding { | ||
191 | get { return (CollidingStep == PhysicsScene.SimulationStep); } | ||
192 | set { | ||
193 | if (value) | ||
194 | CollidingStep = PhysicsScene.SimulationStep; | ||
195 | else | ||
196 | CollidingStep = 0; | ||
197 | } | ||
198 | } | ||
199 | public override bool CollidingGround { | ||
200 | get { return (CollidingGroundStep == PhysicsScene.SimulationStep); } | ||
201 | set | ||
202 | { | ||
203 | if (value) | ||
204 | CollidingGroundStep = PhysicsScene.SimulationStep; | ||
205 | else | ||
206 | CollidingGroundStep = 0; | ||
207 | } | ||
208 | } | ||
209 | public override bool CollidingObj { | ||
210 | get { return (CollidingObjectStep == PhysicsScene.SimulationStep); } | ||
211 | set { | ||
212 | if (value) | ||
213 | CollidingObjectStep = PhysicsScene.SimulationStep; | ||
214 | else | ||
215 | CollidingObjectStep = 0; | ||
216 | } | ||
217 | } | ||
218 | |||
188 | // The collisions that have been collected this tick | 219 | // The collisions that have been collected this tick |
189 | protected CollisionEventUpdate CollisionCollection; | 220 | protected CollisionEventUpdate CollisionCollection; |
190 | 221 | ||
@@ -196,12 +227,16 @@ public abstract class BSPhysObject : PhysicsActor | |||
196 | { | 227 | { |
197 | bool ret = false; | 228 | bool ret = false; |
198 | 229 | ||
199 | // The following lines make IsColliding() and IsCollidingGround() work | 230 | // The following lines make IsColliding(), CollidingGround() and CollidingObj work |
200 | CollidingStep = PhysicsScene.SimulationStep; | 231 | CollidingStep = PhysicsScene.SimulationStep; |
201 | if (collidingWith <= PhysicsScene.TerrainManager.HighestTerrainID) | 232 | if (collidingWith <= PhysicsScene.TerrainManager.HighestTerrainID) |
202 | { | 233 | { |
203 | CollidingGroundStep = PhysicsScene.SimulationStep; | 234 | CollidingGroundStep = PhysicsScene.SimulationStep; |
204 | } | 235 | } |
236 | else | ||
237 | { | ||
238 | CollidingObjectStep = PhysicsScene.SimulationStep; | ||
239 | } | ||
205 | 240 | ||
206 | // prims in the same linkset cannot collide with each other | 241 | // prims in the same linkset cannot collide with each other |
207 | if (collidee != null && (this.Linkset.LinksetID == collidee.Linkset.LinksetID)) | 242 | if (collidee != null && (this.Linkset.LinksetID == collidee.Linkset.LinksetID)) |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 159f79f..5f3f0d1 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -94,7 +94,7 @@ public sealed class BSPrim : BSPhysObject | |||
94 | _size = size; | 94 | _size = size; |
95 | Scale = size; // prims are the size the user wants them to be (different for BSCharactes). | 95 | Scale = size; // prims are the size the user wants them to be (different for BSCharactes). |
96 | _orientation = rotation; | 96 | _orientation = rotation; |
97 | _buoyancy = 1f; | 97 | _buoyancy = 0f; |
98 | _velocity = OMV.Vector3.Zero; | 98 | _velocity = OMV.Vector3.Zero; |
99 | _rotationalVelocity = OMV.Vector3.Zero; | 99 | _rotationalVelocity = OMV.Vector3.Zero; |
100 | BaseShape = pbs; | 100 | BaseShape = pbs; |
@@ -408,12 +408,15 @@ public sealed class BSPrim : BSPhysObject | |||
408 | { | 408 | { |
409 | if (IsStatic) | 409 | if (IsStatic) |
410 | { | 410 | { |
411 | BulletSimAPI.SetGravity2(PhysBody.ptr, PhysicsScene.DefaultGravity); | ||
411 | Inertia = OMV.Vector3.Zero; | 412 | Inertia = OMV.Vector3.Zero; |
412 | BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia); | 413 | BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia); |
413 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); | 414 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); |
414 | } | 415 | } |
415 | else | 416 | else |
416 | { | 417 | { |
418 | OMV.Vector3 grav = ComputeGravity(); | ||
419 | |||
417 | if (inWorld) | 420 | if (inWorld) |
418 | { | 421 | { |
419 | // Changing interesting properties doesn't change proxy and collision cache | 422 | // Changing interesting properties doesn't change proxy and collision cache |
@@ -422,24 +425,41 @@ public sealed class BSPrim : BSPhysObject | |||
422 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr); | 425 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr); |
423 | } | 426 | } |
424 | 427 | ||
425 | float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); | 428 | // The computation of mass props requires gravity to be set on the object. |
426 | BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); | 429 | BulletSimAPI.SetGravity2(PhysBody.ptr, grav); |
427 | 430 | ||
428 | Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); | 431 | Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); |
429 | BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia); | 432 | BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia); |
430 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); | 433 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); |
434 | |||
431 | // center of mass is at the zero of the object | 435 | // center of mass is at the zero of the object |
432 | // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation); | 436 | // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation); |
433 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2}", LocalID, physMass, Inertia); | 437 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}", LocalID, physMass, Inertia, grav, inWorld); |
434 | 438 | ||
435 | if (inWorld) | 439 | if (inWorld) |
436 | { | 440 | { |
437 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr); | 441 | AddObjectToPhysicalWorld(); |
438 | } | 442 | } |
443 | |||
444 | // Must set gravity after it has been added to the world because, for unknown reasons, | ||
445 | // adding the object resets the object's gravity to world gravity | ||
446 | BulletSimAPI.SetGravity2(PhysBody.ptr, grav); | ||
447 | |||
439 | } | 448 | } |
440 | } | 449 | } |
441 | } | 450 | } |
442 | 451 | ||
452 | // Return what gravity should be set to this very moment | ||
453 | private OMV.Vector3 ComputeGravity() | ||
454 | { | ||
455 | OMV.Vector3 ret = PhysicsScene.DefaultGravity; | ||
456 | |||
457 | if (!IsStatic) | ||
458 | ret *= (1f - Buoyancy); | ||
459 | |||
460 | return ret; | ||
461 | } | ||
462 | |||
443 | // Is this used? | 463 | // Is this used? |
444 | public override OMV.Vector3 CenterOfMass | 464 | public override OMV.Vector3 CenterOfMass |
445 | { | 465 | { |
@@ -665,7 +685,7 @@ public sealed class BSPrim : BSPhysObject | |||
665 | _isPhysical = value; | 685 | _isPhysical = value; |
666 | PhysicsScene.TaintedObject("BSPrim.setIsPhysical", delegate() | 686 | PhysicsScene.TaintedObject("BSPrim.setIsPhysical", delegate() |
667 | { | 687 | { |
668 | // DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical); | 688 | DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical); |
669 | SetObjectDynamic(true); | 689 | SetObjectDynamic(true); |
670 | // whether phys-to-static or static-to-phys, the object is not moving. | 690 | // whether phys-to-static or static-to-phys, the object is not moving. |
671 | ZeroMotion(true); | 691 | ZeroMotion(true); |
@@ -720,22 +740,19 @@ public sealed class BSPrim : BSPhysObject | |||
720 | // Make solid or not (do things bounce off or pass through this object). | 740 | // Make solid or not (do things bounce off or pass through this object). |
721 | MakeSolid(IsSolid); | 741 | MakeSolid(IsSolid); |
722 | 742 | ||
723 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr); | 743 | AddObjectToPhysicalWorld(); |
724 | 744 | ||
725 | // Rebuild its shape | 745 | // Rebuild its shape |
726 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); | 746 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); |
727 | 747 | ||
728 | // Collision filter can be set only when the object is in the world | ||
729 | PhysBody.ApplyCollisionMask(); | ||
730 | |||
731 | // Recompute any linkset parameters. | 748 | // Recompute any linkset parameters. |
732 | // When going from non-physical to physical, this re-enables the constraints that | 749 | // When going from non-physical to physical, this re-enables the constraints that |
733 | // had been automatically disabled when the mass was set to zero. | 750 | // had been automatically disabled when the mass was set to zero. |
734 | // For compound based linksets, this enables and disables interactions of the children. | 751 | // For compound based linksets, this enables and disables interactions of the children. |
735 | Linkset.Refresh(this); | 752 | Linkset.Refresh(this); |
736 | 753 | ||
737 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}", | 754 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},cType={6},body={7},shape={8}", |
738 | LocalID, IsStatic, IsSolid, Mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody, PhysShape); | 755 | LocalID, IsStatic, IsSolid, Mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody.collisionType, PhysBody, PhysShape); |
739 | } | 756 | } |
740 | 757 | ||
741 | // "Making dynamic" means changing to and from static. | 758 | // "Making dynamic" means changing to and from static. |
@@ -876,6 +893,28 @@ public sealed class BSPrim : BSPhysObject | |||
876 | } | 893 | } |
877 | } | 894 | } |
878 | 895 | ||
896 | // Add me to the physical world. | ||
897 | // Object MUST NOT already be in the world. | ||
898 | // This routine exists because some assorted properties get mangled by adding to the world. | ||
899 | internal void AddObjectToPhysicalWorld() | ||
900 | { | ||
901 | if (PhysBody.HasPhysicalBody) | ||
902 | { | ||
903 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr); | ||
904 | |||
905 | // TODO: Fix this. Total kludge because adding object to world resets its gravity to default. | ||
906 | // Replace this when the new AddObjectToWorld function is complete. | ||
907 | BulletSimAPI.SetGravity2(PhysBody.ptr, ComputeGravity()); | ||
908 | |||
909 | // Collision filter can be set only when the object is in the world | ||
910 | if (!PhysBody.ApplyCollisionMask()) | ||
911 | { | ||
912 | m_log.ErrorFormat("{0} Failed setting object collision mask: id={1}", LogHeader, LocalID); | ||
913 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,failedSetMaskGroup,cType={1}", LocalID, PhysBody.collisionType); | ||
914 | } | ||
915 | } | ||
916 | } | ||
917 | |||
879 | // prims don't fly | 918 | // prims don't fly |
880 | public override bool Flying { | 919 | public override bool Flying { |
881 | get { return _flying; } | 920 | get { return _flying; } |
@@ -891,18 +930,6 @@ public sealed class BSPrim : BSPhysObject | |||
891 | get { return _throttleUpdates; } | 930 | get { return _throttleUpdates; } |
892 | set { _throttleUpdates = value; } | 931 | set { _throttleUpdates = value; } |
893 | } | 932 | } |
894 | public override bool IsColliding { | ||
895 | get { return (CollidingStep == PhysicsScene.SimulationStep); } | ||
896 | set { _isColliding = value; } | ||
897 | } | ||
898 | public override bool CollidingGround { | ||
899 | get { return (CollidingGroundStep == PhysicsScene.SimulationStep); } | ||
900 | set { _collidingGround = value; } | ||
901 | } | ||
902 | public override bool CollidingObj { | ||
903 | get { return _collidingObj; } | ||
904 | set { _collidingObj = value; } | ||
905 | } | ||
906 | public bool IsPhantom { | 933 | public bool IsPhantom { |
907 | get { | 934 | get { |
908 | // SceneObjectPart removes phantom objects from the physics scene | 935 | // SceneObjectPart removes phantom objects from the physics scene |
@@ -972,6 +999,7 @@ public sealed class BSPrim : BSPhysObject | |||
972 | _buoyancy = value; | 999 | _buoyancy = value; |
973 | // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | 1000 | // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); |
974 | // Force the recalculation of the various inertia,etc variables in the object | 1001 | // Force the recalculation of the various inertia,etc variables in the object |
1002 | DetailLog("{0},BSPrim.ForceBuoyancy,buoy={1},mass={2}", LocalID, _buoyancy, _mass); | ||
975 | UpdatePhysicalMassProperties(_mass, true); | 1003 | UpdatePhysicalMassProperties(_mass, true); |
976 | ActivateIfPhysical(false); | 1004 | ActivateIfPhysical(false); |
977 | } | 1005 | } |
@@ -981,12 +1009,12 @@ public sealed class BSPrim : BSPhysObject | |||
981 | public override OMV.Vector3 PIDTarget { | 1009 | public override OMV.Vector3 PIDTarget { |
982 | set { _PIDTarget = value; } | 1010 | set { _PIDTarget = value; } |
983 | } | 1011 | } |
984 | public override bool PIDActive { | ||
985 | set { _usePID = value; } | ||
986 | } | ||
987 | public override float PIDTau { | 1012 | public override float PIDTau { |
988 | set { _PIDTau = value; } | 1013 | set { _PIDTau = value; } |
989 | } | 1014 | } |
1015 | public override bool PIDActive { | ||
1016 | set { _usePID = value; } | ||
1017 | } | ||
990 | 1018 | ||
991 | // Used for llSetHoverHeight and maybe vehicle height | 1019 | // Used for llSetHoverHeight and maybe vehicle height |
992 | // Hover Height will override MoveTo target's Z | 1020 | // Hover Height will override MoveTo target's Z |
@@ -1010,7 +1038,9 @@ public sealed class BSPrim : BSPhysObject | |||
1010 | public override float APIDDamping { set { return; } } | 1038 | public override float APIDDamping { set { return; } } |
1011 | 1039 | ||
1012 | public override void AddForce(OMV.Vector3 force, bool pushforce) { | 1040 | public override void AddForce(OMV.Vector3 force, bool pushforce) { |
1013 | AddForce(force, pushforce, false); | 1041 | // Since this force is being applied in only one step, make this a force per second. |
1042 | OMV.Vector3 addForce = force / PhysicsScene.LastTimeStep; | ||
1043 | AddForce(addForce, pushforce, false); | ||
1014 | } | 1044 | } |
1015 | // Applying a force just adds this to the total force on the object. | 1045 | // Applying a force just adds this to the total force on the object. |
1016 | // This added force will only last the next simulation tick. | 1046 | // This added force will only last the next simulation tick. |
@@ -1018,8 +1048,16 @@ public sealed class BSPrim : BSPhysObject | |||
1018 | // for an object, doesn't matter if force is a pushforce or not | 1048 | // for an object, doesn't matter if force is a pushforce or not |
1019 | if (force.IsFinite()) | 1049 | if (force.IsFinite()) |
1020 | { | 1050 | { |
1051 | float magnitude = force.Length(); | ||
1052 | if (magnitude > BSParam.MaxAddForceMagnitude) | ||
1053 | { | ||
1054 | // Force has a limit | ||
1055 | force = force / magnitude * BSParam.MaxAddForceMagnitude; | ||
1056 | } | ||
1057 | |||
1021 | OMV.Vector3 addForce = force; | 1058 | OMV.Vector3 addForce = force; |
1022 | DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce); | 1059 | DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce); |
1060 | |||
1023 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate() | 1061 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate() |
1024 | { | 1062 | { |
1025 | // Bullet adds this central force to the total force for this tick | 1063 | // Bullet adds this central force to the total force for this tick |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 0022e45..4133107 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | |||
@@ -38,15 +38,6 @@ using Nini.Config; | |||
38 | using log4net; | 38 | using log4net; |
39 | using OpenMetaverse; | 39 | using OpenMetaverse; |
40 | 40 | ||
41 | // TODOs for BulletSim (for BSScene, BSPrim, BSCharacter and BulletSim) | ||
42 | // Based on material, set density and friction | ||
43 | // More efficient memory usage when passing hull information from BSPrim to BulletSim | ||
44 | // Do attachments need to be handled separately? Need collision events. Do not collide with VolumeDetect | ||
45 | // Implement LockAngularMotion | ||
46 | // Add PID movement operations. What does ScenePresence.MoveToTarget do? | ||
47 | // Check terrain size. 128 or 127? | ||
48 | // Raycast | ||
49 | // | ||
50 | namespace OpenSim.Region.Physics.BulletSPlugin | 41 | namespace OpenSim.Region.Physics.BulletSPlugin |
51 | { | 42 | { |
52 | public sealed class BSScene : PhysicsScene, IPhysicsParameters | 43 | public sealed class BSScene : PhysicsScene, IPhysicsParameters |
@@ -83,6 +74,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
83 | internal int m_maxSubSteps; | 74 | internal int m_maxSubSteps; |
84 | internal float m_fixedTimeStep; | 75 | internal float m_fixedTimeStep; |
85 | internal long m_simulationStep = 0; | 76 | internal long m_simulationStep = 0; |
77 | internal float NominalFrameRate { get; set; } | ||
86 | public long SimulationStep { get { return m_simulationStep; } } | 78 | public long SimulationStep { get { return m_simulationStep; } } |
87 | internal int m_taintsToProcessPerStep; | 79 | internal int m_taintsToProcessPerStep; |
88 | internal float LastTimeStep { get; private set; } | 80 | internal float LastTimeStep { get; private set; } |
@@ -171,6 +163,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
171 | private string m_physicsLoggingPrefix; | 163 | private string m_physicsLoggingPrefix; |
172 | private int m_physicsLoggingFileMinutes; | 164 | private int m_physicsLoggingFileMinutes; |
173 | private bool m_physicsLoggingDoFlush; | 165 | private bool m_physicsLoggingDoFlush; |
166 | private bool m_physicsPhysicalDumpEnabled; | ||
174 | // 'true' of the vehicle code is to log lots of details | 167 | // 'true' of the vehicle code is to log lots of details |
175 | public bool VehicleLoggingEnabled { get; private set; } | 168 | public bool VehicleLoggingEnabled { get; private set; } |
176 | public bool VehiclePhysicalLoggingEnabled { get; private set; } | 169 | public bool VehiclePhysicalLoggingEnabled { get; private set; } |
@@ -276,11 +269,13 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
276 | BSParam.SetParameterConfigurationValues(this, pConfig); | 269 | BSParam.SetParameterConfigurationValues(this, pConfig); |
277 | 270 | ||
278 | // Very detailed logging for physics debugging | 271 | // Very detailed logging for physics debugging |
272 | // TODO: the boolean values can be moved to the normal parameter processing. | ||
279 | m_physicsLoggingEnabled = pConfig.GetBoolean("PhysicsLoggingEnabled", false); | 273 | m_physicsLoggingEnabled = pConfig.GetBoolean("PhysicsLoggingEnabled", false); |
280 | m_physicsLoggingDir = pConfig.GetString("PhysicsLoggingDir", "."); | 274 | m_physicsLoggingDir = pConfig.GetString("PhysicsLoggingDir", "."); |
281 | m_physicsLoggingPrefix = pConfig.GetString("PhysicsLoggingPrefix", "physics-%REGIONNAME%-"); | 275 | m_physicsLoggingPrefix = pConfig.GetString("PhysicsLoggingPrefix", "physics-%REGIONNAME%-"); |
282 | m_physicsLoggingFileMinutes = pConfig.GetInt("PhysicsLoggingFileMinutes", 5); | 276 | m_physicsLoggingFileMinutes = pConfig.GetInt("PhysicsLoggingFileMinutes", 5); |
283 | m_physicsLoggingDoFlush = pConfig.GetBoolean("PhysicsLoggingDoFlush", false); | 277 | m_physicsLoggingDoFlush = pConfig.GetBoolean("PhysicsLoggingDoFlush", false); |
278 | m_physicsPhysicalDumpEnabled = pConfig.GetBoolean("PhysicsPhysicalDumpEnabled", false); | ||
284 | // Very detailed logging for vehicle debugging | 279 | // Very detailed logging for vehicle debugging |
285 | VehicleLoggingEnabled = pConfig.GetBoolean("VehicleLoggingEnabled", false); | 280 | VehicleLoggingEnabled = pConfig.GetBoolean("VehicleLoggingEnabled", false); |
286 | VehiclePhysicalLoggingEnabled = pConfig.GetBoolean("VehiclePhysicalLoggingEnabled", false); | 281 | VehiclePhysicalLoggingEnabled = pConfig.GetBoolean("VehiclePhysicalLoggingEnabled", false); |
@@ -495,6 +490,11 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
495 | 490 | ||
496 | InTaintTime = false; // Only used for debugging so locking is not necessary. | 491 | InTaintTime = false; // Only used for debugging so locking is not necessary. |
497 | 492 | ||
493 | // The following causes the unmanaged code to output ALL the values found in ALL the objects in the world. | ||
494 | // Only enable this in a limited test world with few objects. | ||
495 | if (m_physicsPhysicalDumpEnabled) | ||
496 | BulletSimAPI.DumpAllInfo2(World.ptr); | ||
497 | |||
498 | // step the physical world one interval | 498 | // step the physical world one interval |
499 | m_simulationStep++; | 499 | m_simulationStep++; |
500 | int numSubSteps = 0; | 500 | int numSubSteps = 0; |
@@ -592,12 +592,13 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
592 | 592 | ||
593 | // The following causes the unmanaged code to output ALL the values found in ALL the objects in the world. | 593 | // The following causes the unmanaged code to output ALL the values found in ALL the objects in the world. |
594 | // Only enable this in a limited test world with few objects. | 594 | // Only enable this in a limited test world with few objects. |
595 | // BulletSimAPI.DumpAllInfo2(World.ptr); // DEBUG DEBUG DEBUG | 595 | if (m_physicsPhysicalDumpEnabled) |
596 | BulletSimAPI.DumpAllInfo2(World.ptr); | ||
596 | 597 | ||
597 | // The physics engine returns the number of milliseconds it simulated this call. | 598 | // The physics engine returns the number of milliseconds it simulated this call. |
598 | // These are summed and normalized to one second and divided by 1000 to give the reported physics FPS. | 599 | // These are summed and normalized to one second and divided by 1000 to give the reported physics FPS. |
599 | // Multiply by 55 to give a nominal frame rate of 55. | 600 | // Multiply by 55 to give a nominal frame rate of 55. |
600 | return (float)numSubSteps * m_fixedTimeStep * 1000f * 55f; | 601 | return (float)numSubSteps * m_fixedTimeStep * 1000f * NominalFrameRate; |
601 | } | 602 | } |
602 | 603 | ||
603 | // Something has collided | 604 | // Something has collided |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs index afe5bca..eb4d039 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs | |||
@@ -250,20 +250,20 @@ public enum CollisionFilterGroups : uint | |||
250 | // filter/mask definition below. This way collision interactions | 250 | // filter/mask definition below. This way collision interactions |
251 | // are more easily found and debugged. | 251 | // are more easily found and debugged. |
252 | BNoneGroup = 0, | 252 | BNoneGroup = 0, |
253 | BDefaultGroup = 1 << 0, | 253 | BDefaultGroup = 1 << 0, // 0001 |
254 | BStaticGroup = 1 << 1, | 254 | BStaticGroup = 1 << 1, // 0002 |
255 | BKinematicGroup = 1 << 2, | 255 | BKinematicGroup = 1 << 2, // 0004 |
256 | BDebrisGroup = 1 << 3, | 256 | BDebrisGroup = 1 << 3, // 0008 |
257 | BSensorTrigger = 1 << 4, | 257 | BSensorTrigger = 1 << 4, // 0010 |
258 | BCharacterGroup = 1 << 5, | 258 | BCharacterGroup = 1 << 5, // 0020 |
259 | BAllGroup = 0xFFFFFFFF, | 259 | BAllGroup = 0x000FFFFF, |
260 | // Filter groups defined by BulletSim | 260 | // Filter groups defined by BulletSim |
261 | BGroundPlaneGroup = 1 << 10, | 261 | BGroundPlaneGroup = 1 << 10, // 0400 |
262 | BTerrainGroup = 1 << 11, | 262 | BTerrainGroup = 1 << 11, // 0800 |
263 | BRaycastGroup = 1 << 12, | 263 | BRaycastGroup = 1 << 12, // 1000 |
264 | BSolidGroup = 1 << 13, | 264 | BSolidGroup = 1 << 13, // 2000 |
265 | // BLinksetGroup = xx // a linkset proper is either static or dynamic | 265 | // BLinksetGroup = xx // a linkset proper is either static or dynamic |
266 | BLinksetChildGroup = 1 << 14, | 266 | BLinksetChildGroup = 1 << 14, // 4000 |
267 | }; | 267 | }; |
268 | 268 | ||
269 | // CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0 | 269 | // CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0 |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs index 36d38d4..5ad6746 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs | |||
@@ -72,12 +72,12 @@ public struct BulletBody | |||
72 | public bool HasPhysicalBody { get { return ptr != IntPtr.Zero; } } | 72 | public bool HasPhysicalBody { get { return ptr != IntPtr.Zero; } } |
73 | 73 | ||
74 | // Apply the specificed collision mask into the physical world | 74 | // Apply the specificed collision mask into the physical world |
75 | public void ApplyCollisionMask() | 75 | public bool ApplyCollisionMask() |
76 | { | 76 | { |
77 | // Should assert the body has been added to the physical world. | 77 | // Should assert the body has been added to the physical world. |
78 | // (The collision masks are stored in the collision proxy cache which only exists for | 78 | // (The collision masks are stored in the collision proxy cache which only exists for |
79 | // a collision body that is in the world.) | 79 | // a collision body that is in the world.) |
80 | BulletSimAPI.SetCollisionGroupMask2(ptr, | 80 | return BulletSimAPI.SetCollisionGroupMask2(ptr, |
81 | BulletSimData.CollisionTypeMasks[collisionType].group, | 81 | BulletSimData.CollisionTypeMasks[collisionType].group, |
82 | BulletSimData.CollisionTypeMasks[collisionType].mask); | 82 | BulletSimData.CollisionTypeMasks[collisionType].mask); |
83 | } | 83 | } |
@@ -207,26 +207,6 @@ public struct CollisionTypeFilterGroup | |||
207 | public uint mask; | 207 | public uint mask; |
208 | }; | 208 | }; |
209 | 209 | ||
210 | /* NOTE: old definitions kept for reference. Delete when things are working. | ||
211 | // The collsion filters and masked are defined in one place -- don't want them scattered | ||
212 | AvatarGroup = BCharacterGroup, | ||
213 | AvatarMask = BAllGroup, | ||
214 | ObjectGroup = BSolidGroup, | ||
215 | ObjectMask = BAllGroup, | ||
216 | StaticObjectGroup = BStaticGroup, | ||
217 | StaticObjectMask = AvatarGroup | ObjectGroup, // static things don't interact with much | ||
218 | LinksetGroup = BLinksetGroup, | ||
219 | LinksetMask = BAllGroup, | ||
220 | LinksetChildGroup = BLinksetChildGroup, | ||
221 | LinksetChildMask = BNoneGroup, // Linkset children disappear from the world | ||
222 | VolumeDetectGroup = BSensorTrigger, | ||
223 | VolumeDetectMask = ~BSensorTrigger, | ||
224 | TerrainGroup = BTerrainGroup, | ||
225 | TerrainMask = BAllGroup & ~BStaticGroup, // static objects on the ground don't collide | ||
226 | GroundPlaneGroup = BGroundPlaneGroup, | ||
227 | GroundPlaneMask = BAllGroup | ||
228 | */ | ||
229 | |||
230 | public static class BulletSimData | 210 | public static class BulletSimData |
231 | { | 211 | { |
232 | 212 | ||
@@ -269,8 +249,9 @@ public static Dictionary<CollisionType, CollisionTypeFilterGroup> CollisionTypeM | |||
269 | }, | 249 | }, |
270 | { CollisionType.LinksetChild, | 250 | { CollisionType.LinksetChild, |
271 | new CollisionTypeFilterGroup(CollisionType.LinksetChild, | 251 | new CollisionTypeFilterGroup(CollisionType.LinksetChild, |
272 | (uint)CollisionFilterGroups.BTerrainGroup, | 252 | (uint)CollisionFilterGroups.BLinksetChildGroup, |
273 | (uint)(CollisionFilterGroups.BNoneGroup)) | 253 | (uint)(CollisionFilterGroups.BNoneGroup)) |
254 | // (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup)) | ||
274 | }, | 255 | }, |
275 | }; | 256 | }; |
276 | 257 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt index 35cb8f3..f805836 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt | |||
@@ -1,22 +1,22 @@ | |||
1 | CURRENT PRIORITIES | 1 | CURRENT PRIORITIES |
2 | ================================================= | 2 | ================================================= |
3 | Smooth avatar movement with motor (DONE) | 3 | Redo BulletSimAPI to allow native C# implementation of Bullet option. |
4 | Should motor update be all at taint-time? (Yes, DONE) | 4 | Avatar movement |
5 | Fix avatar slowly sliding when standing (zero motion when stopped) | 5 | flying into a wall doesn't stop avatar who keeps appearing to move through the obstacle |
6 | llApplyImpulse() | 6 | walking up stairs is not calibrated correctly (stairs out of Kepler cabin) |
7 | Compare mass/movement in OS and SL. Calibrate actions. | 7 | avatar capsule rotation completed |
8 | llSetBuoyancy() | 8 | llMoveToTarget |
9 | Boats float low in the water | ||
10 | Enable vehicle border crossings (at least as poorly as ODE) | 9 | Enable vehicle border crossings (at least as poorly as ODE) |
11 | Terrain skirts | 10 | Terrain skirts |
12 | Avatar created in previous region and not new region when crossing border | 11 | Avatar created in previous region and not new region when crossing border |
13 | Vehicle recreated in new sim at small Z value (offset from root value?) (DONE) | 12 | Vehicle recreated in new sim at small Z value (offset from root value?) (DONE) |
14 | Add material densities to the material types. | ||
15 | Vehicle movement on terrain smoothness | 13 | Vehicle movement on terrain smoothness |
16 | Vehicle script tuning/debugging | 14 | Vehicle script tuning/debugging |
17 | Avanti speed script | 15 | Avanti speed script |
18 | Weapon shooter script | 16 | Weapon shooter script |
19 | limitMotorUp calibration (more down?) | 17 | limitMotorUp calibration (more down?) |
18 | Boats float low in the water | ||
19 | Add material densities to the material types. | ||
20 | 20 | ||
21 | CRASHES | 21 | CRASHES |
22 | ================================================= | 22 | ================================================= |
@@ -35,6 +35,8 @@ Border crossing with linked vehicle causes crash | |||
35 | Vehicles (Move smoothly) | 35 | Vehicles (Move smoothly) |
36 | Add vehicle collisions so IsColliding is properly reported. | 36 | Add vehicle collisions so IsColliding is properly reported. |
37 | Needed for banking, limitMotorUp, movementLimiting, ... | 37 | Needed for banking, limitMotorUp, movementLimiting, ... |
38 | VehicleAddForce is not scaled by the simulation step but it is only | ||
39 | applied for one step. Should it be scaled? | ||
38 | Some vehicles should not be able to turn if no speed or off ground. | 40 | Some vehicles should not be able to turn if no speed or off ground. |
39 | Cannot edit/move a vehicle being ridden: it jumps back to the origional position. | 41 | Cannot edit/move a vehicle being ridden: it jumps back to the origional position. |
40 | Neb car jiggling left and right | 42 | Neb car jiggling left and right |
@@ -58,7 +60,6 @@ Incorporate inter-relationship of angular corrections. For instance, angularDefl | |||
58 | 60 | ||
59 | BULLETSIM TODO LIST: | 61 | BULLETSIM TODO LIST: |
60 | ================================================= | 62 | ================================================= |
61 | In SL, perfect spheres don't seem to have rolling friction. Add special case. | ||
62 | Avatar density is WAY off. Compare and calibrate with what's in SL. | 63 | Avatar density is WAY off. Compare and calibrate with what's in SL. |
63 | Revisit CollisionMargin. Builders notice the 0.04 spacing between prims. | 64 | Revisit CollisionMargin. Builders notice the 0.04 spacing between prims. |
64 | Duplicating a physical prim causes old prim to jump away | 65 | Duplicating a physical prim causes old prim to jump away |
@@ -93,6 +94,9 @@ Should the different PID factors have non-equal contributions for different | |||
93 | Selecting and deselecting physical objects causes CPU processing time to jump | 94 | Selecting and deselecting physical objects causes CPU processing time to jump |
94 | http://www.youtube.com/watch?v=Hjg57fWg8yI&hd=1 | 95 | http://www.youtube.com/watch?v=Hjg57fWg8yI&hd=1 |
95 | put thousand physical objects, select and deselect same. CPU time will be large. | 96 | put thousand physical objects, select and deselect same. CPU time will be large. |
97 | Re-implement buoyancy as a separate force on the object rather than diddling gravity. | ||
98 | Register a pre-step event to add the force. | ||
99 | More efficient memory usage when passing hull information from BSPrim to BulletSim | ||
96 | 100 | ||
97 | LINKSETS | 101 | LINKSETS |
98 | ====================================================== | 102 | ====================================================== |
@@ -146,6 +150,8 @@ Is there are more efficient method of implementing pre and post step actions? | |||
146 | See http://www.codeproject.com/Articles/29922/Weak-Events-in-C | 150 | See http://www.codeproject.com/Articles/29922/Weak-Events-in-C |
147 | 151 | ||
148 | Physics Arena central pyramid: why is one side permiable? | 152 | Physics Arena central pyramid: why is one side permiable? |
153 | |||
154 | In SL, perfect spheres don't seem to have rolling friction. Add special case. | ||
149 | Enforce physical parameter min/max: | 155 | Enforce physical parameter min/max: |
150 | Gravity: [-1, 28] | 156 | Gravity: [-1, 28] |
151 | Friction: [0, 255] | 157 | Friction: [0, 255] |
@@ -188,6 +194,7 @@ Should taints check for existance or activeness of target? | |||
188 | actually gone when the taint happens. Crashes don't happen because the taint closure | 194 | actually gone when the taint happens. Crashes don't happen because the taint closure |
189 | keeps the object from being freed, but that is just an accident. | 195 | keeps the object from being freed, but that is just an accident. |
190 | Possibly have and 'active' flag that is checked by the taint processor? | 196 | Possibly have and 'active' flag that is checked by the taint processor? |
197 | Parameters for physics logging should be moved from BSScene to BSParam (at least boolean ones) | ||
191 | 198 | ||
192 | THREADING | 199 | THREADING |
193 | ================================================= | 200 | ================================================= |
@@ -237,3 +244,12 @@ Should vehicle angular/linear movement friction happen after all the components | |||
237 | What is expected by some vehicles (turning up friction to moderate speed)) | 244 | What is expected by some vehicles (turning up friction to moderate speed)) |
238 | Tune terrain/object friction to be closer to SL. | 245 | Tune terrain/object friction to be closer to SL. |
239 | (Resolution: added material type with friction and resolution) | 246 | (Resolution: added material type with friction and resolution) |
247 | Smooth avatar movement with motor (DONE) | ||
248 | Should motor update be all at taint-time? (Yes, DONE) | ||
249 | Fix avatar slowly sliding when standing (zero motion when stopped) (DONE) | ||
250 | (Resolution: added BSVMotor for avatar starting and stopping) | ||
251 | llApplyImpulse() | ||
252 | Compare mass/movement in OS and SL. Calibrate actions. (DONE) | ||
253 | (Resolution: tested on SL and OS. AddForce scales the force for timestep) | ||
254 | llSetBuoyancy() (DONE) | ||
255 | (Resolution: Bullet resets object gravity when added to world. Moved set gravity) | ||