From ce5083a504a82712149f5e3dab622d42e260bba3 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 9 Dec 2012 22:10:32 -0800 Subject: BulletSim: adjust friction and restitution based on material type. --- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 4d203ff..627393a 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -683,8 +683,9 @@ public sealed class BSPrim : BSPhysObject ZeroMotion(true); // Set various physical properties so other object interact properly - BulletSimAPI.SetFriction2(PhysBody.ptr, PhysicsScene.Params.defaultFriction); - BulletSimAPI.SetRestitution2(PhysBody.ptr, PhysicsScene.Params.defaultRestitution); + MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); + BulletSimAPI.SetFriction2(PhysBody.ptr, matAttrib.friction); + BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution); // Mass is zero which disables a bunch of physics stuff in Bullet UpdatePhysicalMassProperties(0f); @@ -711,9 +712,10 @@ public sealed class BSPrim : BSPhysObject // Not a Bullet static object CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT); - // Set various physical properties so internal dynamic properties will get computed correctly as they are set - BulletSimAPI.SetFriction2(PhysBody.ptr, PhysicsScene.Params.defaultFriction); - BulletSimAPI.SetRestitution2(PhysBody.ptr, PhysicsScene.Params.defaultRestitution); + // Set various physical properties so other object interact properly + MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true); + BulletSimAPI.SetFriction2(PhysBody.ptr, matAttrib.friction); + BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution); // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 // Since this can be called multiple times, only zero forces when becoming physical -- cgit v1.1 From 9df85eadf4b3719a898fda8769313ae023962c25 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 10 Dec 2012 15:35:53 -0800 Subject: BulletSim: Fix crash on the destruction of physical linksets. While fixing the above, add methods to physical body and shape pointer wrapper so routines won't have to know that IntPtr.Zero means no physical instance. Fix problem with physical linksets failing after a few sits and unsits by properly restoring child prom positions for compound linksets after multiple selection and deselections. --- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 627393a..d1d100d 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -108,8 +108,8 @@ public sealed class BSPrim : BSPhysObject _mass = CalculateMass(); // No body or shape yet - PhysBody = new BulletBody(LocalID, IntPtr.Zero); - PhysShape = new BulletShape(IntPtr.Zero); + PhysBody = new BulletBody(LocalID); + PhysShape = new BulletShape(); DetailLog("{0},BSPrim.constructor,call", LocalID); // do the actual object creation at taint time @@ -143,7 +143,9 @@ public sealed class BSPrim : BSPhysObject DetailLog("{0},BSPrim.Destroy,taint,", LocalID); // If there are physical body and shape, release my use of same. PhysicsScene.Shapes.DereferenceBody(PhysBody, true, null); + PhysBody.Clear(); PhysicsScene.Shapes.DereferenceShape(PhysShape, true, null); + PhysShape.Clear(); }); } -- cgit v1.1 From 63099184dbd2c1c5bcee2c3c87802f78444e7008 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 11 Dec 2012 13:42:23 -0800 Subject: BulletSim: protect prim property setting to remove crash from taints setting properties after the destroy object taint has happened. --- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 54 ++++++++++++++++++-------- 1 file changed, 37 insertions(+), 17 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index d1d100d..1280c25 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -249,7 +249,8 @@ public sealed class BSPrim : BSPhysObject // Zero some other properties in the physics engine PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate() { - BulletSimAPI.ClearAllForces2(PhysBody.ptr); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.ClearAllForces2(PhysBody.ptr); }); } public override void ZeroAngularMotion(bool inTaintTime) @@ -259,8 +260,11 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate() { // DetailLog("{0},BSPrim.ZeroAngularMotion,call,rotVel={1}", LocalID, _rotationalVelocity); - BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, _rotationalVelocity); - BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); + if (PhysBody.HasPhysicalBody) + { + BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, _rotationalVelocity); + BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); + } }); } @@ -297,8 +301,11 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.TaintedObject("BSPrim.setPosition", delegate() { // DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); - BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); - ActivateIfPhysical(false); + if (PhysBody.HasPhysicalBody) + { + BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + ActivateIfPhysical(false); + } }); } } @@ -415,7 +422,8 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.TaintedObject("BSPrim.setForce", delegate() { // DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force); - BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); }); } } @@ -509,7 +517,8 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.TaintedObject("BSPrim.setVelocity", delegate() { // DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity); - BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); }); } } @@ -558,9 +567,12 @@ public sealed class BSPrim : BSPhysObject // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint? PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() { - // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr); - // DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); - BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + if (PhysBody.HasPhysicalBody) + { + // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr); + // DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); + BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); + } }); } } @@ -865,7 +877,8 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate() { DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); - BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); }); } } @@ -900,8 +913,11 @@ public sealed class BSPrim : BSPhysObject _buoyancy = value; // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); // Buoyancy is faked by changing the gravity applied to the object - float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); - BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); + if (PhysBody.HasPhysicalBody) + { + float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); + BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); + } } } @@ -969,7 +985,8 @@ public sealed class BSPrim : BSPhysObject } DetailLog("{0},BSPrim.AddForce,taint,force={1}", LocalID, fSum); if (fSum != OMV.Vector3.Zero) - BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, fSum); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, fSum); }); } @@ -980,7 +997,8 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyForceImpulse", delegate() { DetailLog("{0},BSPrim.ApplyForceImpulse,taint,tImpulse={1}", LocalID, applyImpulse); - BulletSimAPI.ApplyCentralImpulse2(PhysBody.ptr, applyImpulse); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.ApplyCentralImpulse2(PhysBody.ptr, applyImpulse); }); } @@ -1016,7 +1034,8 @@ public sealed class BSPrim : BSPhysObject DetailLog("{0},BSPrim.AddAngularForce,taint,aForce={1}", LocalID, fSum); if (fSum != OMV.Vector3.Zero) { - BulletSimAPI.ApplyTorque2(PhysBody.ptr, fSum); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.ApplyTorque2(PhysBody.ptr, fSum); _torque = fSum; } }); @@ -1030,7 +1049,8 @@ public sealed class BSPrim : BSPhysObject OMV.Vector3 applyImpulse = impulse; PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyTorqueImpulse", delegate() { - BulletSimAPI.ApplyTorqueImpulse2(PhysBody.ptr, applyImpulse); + if (PhysBody.HasPhysicalBody) + BulletSimAPI.ApplyTorqueImpulse2(PhysBody.ptr, applyImpulse); }); } -- cgit v1.1 From d4e0e98c001c3501ac17849ab78e7ac5a59a5c26 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 11 Dec 2012 13:54:26 -0800 Subject: BulletSim: protect character property setting to remove crash from taints setting properties after the destroy character taint. --- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 1280c25..446e44c 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -191,7 +191,8 @@ public sealed class BSPrim : BSPhysObject } } public override bool Selected { - set { + set + { if (value != _isSelected) { _isSelected = value; -- cgit v1.1 From a082ce9da78ffb50454834fde4e3dd19e3b5bc74 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 11 Dec 2012 14:27:09 -0800 Subject: BulletSim: fix crash caused by the creation of a linkset child that is under the terrain. Users can sure find some interesting corner conditions. --- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 446e44c..35d22c0 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -332,12 +332,12 @@ public sealed class BSPrim : BSPhysObject float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(_position); OMV.Vector3 upForce = OMV.Vector3.Zero; - if (Position.Z < terrainHeight) + if (RawPosition.Z < terrainHeight) { DetailLog("{0},BSPrim.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight); float targetHeight = terrainHeight + (Size.Z / 2f); // Upforce proportional to the distance away from the terrain. Correct the error in 1 sec. - upForce.Z = (terrainHeight - Position.Z) * 1f; + upForce.Z = (terrainHeight - RawPosition.Z) * 1f; ret = true; } @@ -345,10 +345,10 @@ public sealed class BSPrim : BSPhysObject { float waterHeight = PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(_position); // TODO: a floating motor so object will bob in the water - if (Math.Abs(Position.Z - waterHeight) > 0.1f) + if (Math.Abs(RawPosition.Z - waterHeight) > 0.1f) { // Upforce proportional to the distance away from the water. Correct the error in 1 sec. - upForce.Z = (waterHeight - Position.Z) * 1f; + upForce.Z = (waterHeight - RawPosition.Z) * 1f; ret = true; } } -- cgit v1.1