From b44f0e1a00eba7f76401692322e48a3b23a81164 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 16 Jul 2013 10:02:14 -0700 Subject: BulletSim: Add logic to linksets to change physical properties for whole linkset. Override physical property setting for BSLinksetCompound as there are not children to the compound spape. --- OpenSim/Region/Physics/BulletSPlugin/BSActors.cs | 6 +--- OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs | 24 +++++++++++++-- .../Physics/BulletSPlugin/BSLinksetCompound.cs | 36 ++++++++++++++++++++++ 3 files changed, 59 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs index fff63e4..e0ccc50 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs @@ -69,7 +69,7 @@ public class BSActorCollection { lock (m_actors) { - Release(); + ForEachActor(a => a.Dispose()); m_actors.Clear(); } } @@ -98,10 +98,6 @@ public class BSActorCollection { ForEachActor(a => a.SetEnabled(enabl)); } - public void Release() - { - ForEachActor(a => a.Dispose()); - } public void Refresh() { ForEachActor(a => a.Refresh()); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs index 78c0af7..960c0b4 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs @@ -309,14 +309,14 @@ public abstract class BSLinkset } ); } - public virtual void ComputeLocalInertia() + public virtual void ComputeLocalInertia(OMV.Vector3 inertiaFactor) { ForEachMember((member) => { if (member.PhysBody.HasPhysicalBody) { OMV.Vector3 inertia = m_physicsScene.PE.CalculateLocalInertia(member.PhysShape.physShapeInfo, member.Mass); - member.Inertia = inertia * BSParam.VehicleInertiaFactor; + member.Inertia = inertia * inertiaFactor; m_physicsScene.PE.SetMassProps(member.PhysBody, member.Mass, member.Inertia); m_physicsScene.PE.UpdateInertiaTensor(member.PhysBody); } @@ -324,6 +324,26 @@ public abstract class BSLinkset } ); } + public virtual void SetPhysicalCollisionFlags(CollisionFlags collFlags) + { + ForEachMember((member) => + { + if (member.PhysBody.HasPhysicalBody) + m_physicsScene.PE.SetCollisionFlags(member.PhysBody, collFlags); + return false; // 'false' says to continue looping + } + ); + } + public virtual void RemoveFromPhysicalCollisionFlags(CollisionFlags collFlags) + { + ForEachMember((member) => + { + if (member.PhysBody.HasPhysicalBody) + m_physicsScene.PE.RemoveFromCollisionFlags(member.PhysBody, collFlags); + return false; // 'false' says to continue looping + } + ); + } // ================================================================ protected virtual float ComputeLinksetMass() { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index 3668456..33ae5a5 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs @@ -44,6 +44,42 @@ public sealed class BSLinksetCompound : BSLinkset { } + // ================================================================ + // Changing the physical property of the linkset only needs to change the root + public override void SetPhysicalFriction(float friction) + { + if (LinksetRoot.PhysBody.HasPhysicalBody) + m_physicsScene.PE.SetFriction(LinksetRoot.PhysBody, friction); + } + public override void SetPhysicalRestitution(float restitution) + { + if (LinksetRoot.PhysBody.HasPhysicalBody) + m_physicsScene.PE.SetRestitution(LinksetRoot.PhysBody, restitution); + } + public override void SetPhysicalGravity(OMV.Vector3 gravity) + { + if (LinksetRoot.PhysBody.HasPhysicalBody) + m_physicsScene.PE.SetGravity(LinksetRoot.PhysBody, gravity); + } + public override void ComputeLocalInertia(OMV.Vector3 inertiaFactor) + { + OMV.Vector3 inertia = m_physicsScene.PE.CalculateLocalInertia(LinksetRoot.PhysShape.physShapeInfo, LinksetRoot.Mass); + LinksetRoot.Inertia = inertia * inertiaFactor; + m_physicsScene.PE.SetMassProps(LinksetRoot.PhysBody, LinksetRoot.Mass, LinksetRoot.Inertia); + m_physicsScene.PE.UpdateInertiaTensor(LinksetRoot.PhysBody); + } + public override void SetPhysicalCollisionFlags(CollisionFlags collFlags) + { + if (LinksetRoot.PhysBody.HasPhysicalBody) + m_physicsScene.PE.SetCollisionFlags(LinksetRoot.PhysBody, collFlags); + } + public override void RemoveFromPhysicalCollisionFlags(CollisionFlags collFlags) + { + if (LinksetRoot.PhysBody.HasPhysicalBody) + m_physicsScene.PE.RemoveFromCollisionFlags(LinksetRoot.PhysBody, collFlags); + } + // ================================================================ + // When physical properties are changed the linkset needs to recalculate // its internal properties. public override void Refresh(BSPrimLinkable requestor) -- cgit v1.1