From 2c581cae2a77628704ae7ae2f9f0f0a87cbb0072 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 31 Mar 2013 09:12:18 -0700 Subject: BulletSim: Add physical 'actors' that operate on the physical object. Add first 'actor' for locked axis. --- .../Physics/BulletSPlugin/BSActorLockAxis.cs | 168 +++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100755 OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs new file mode 100755 index 0000000..b4af126 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs @@ -0,0 +1,168 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyrightD + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using OMV = OpenMetaverse; + +namespace OpenSim.Region.Physics.BulletSPlugin +{ +public class BSActorLockAxis : BSActor +{ + bool TryExperimentalLockAxisCode = false; + BSConstraint LockAxisConstraint = null; + + public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) + : base(physicsScene, pObj,actorName) + { + LockAxisConstraint = null; + } + + // BSActor.isActive + public override bool isActive + { + get { return Enabled && Prim.IsPhysicallyActive; } + } + + // Release any connections and resources used by the actor. + // BSActor.Release() + public override void Release() + { + RemoveAxisLockConstraint(); + } + + // Called when physical parameters (properties set in Bullet) need to be re-applied. + // Called at taint-time. + // BSActor.Refresh() + public override void Refresh() + { + // If all the axis are free, we don't need to exist + if (Prim.LockedAxis == Prim.LockedAxisFree) + { + Prim.PhysicalActors.RemoveAndRelease(ActorName); + return; + } + // If the object is physically active, add the axis locking constraint + if (Enabled + && Prim.IsPhysicallyActive + && TryExperimentalLockAxisCode + && Prim.LockedAxis != Prim.LockedAxisFree) + { + if (LockAxisConstraint != null) + AddAxisLockConstraint(); + } + else + { + RemoveAxisLockConstraint(); + } + } + + // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). + // Register a prestep action to restore physical requirements before the next simulation step. + // Called at taint-time. + // BSActor.RemoveBodyDependencies() + public override void RemoveBodyDependencies() + { + if (LockAxisConstraint != null) + { + // If a constraint is set up, remove it from the physical scene + RemoveAxisLockConstraint(); + // Schedule a call before the next simulation step to restore the constraint. + PhysicsScene.PostTaintObject(Prim.LockedAxisActorName, Prim.LocalID, delegate() + { + Refresh(); + }); + } + } + + private void AddAxisLockConstraint() + { + // Lock that axis by creating a 6DOF constraint that has one end in the world and + // the other in the object. + // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817 + // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380 + + // Remove any existing axis constraint (just to be sure) + RemoveAxisLockConstraint(); + + BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(PhysicsScene.World, Prim.PhysBody, + OMV.Vector3.Zero, OMV.Quaternion.Inverse(Prim.RawOrientation), + true /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); + LockAxisConstraint = axisConstrainer; + PhysicsScene.Constraints.AddConstraint(LockAxisConstraint); + + // The constraint is tied to the world and oriented to the prim. + + // Free to move linearly + OMV.Vector3 linearLow = OMV.Vector3.Zero; + OMV.Vector3 linearHigh = PhysicsScene.TerrainManager.DefaultRegionSize; + axisConstrainer.SetLinearLimits(linearLow, linearHigh); + + // Angular with some axis locked + float f2PI = (float)Math.PI * 2f; + OMV.Vector3 angularLow = new OMV.Vector3(-f2PI, -f2PI, -f2PI); + OMV.Vector3 angularHigh = new OMV.Vector3(f2PI, f2PI, f2PI); + if (Prim.LockedAxis.X != 1f) + { + angularLow.X = 0f; + angularHigh.X = 0f; + } + if (Prim.LockedAxis.Y != 1f) + { + angularLow.Y = 0f; + angularHigh.Y = 0f; + } + if (Prim.LockedAxis.Z != 1f) + { + angularLow.Z = 0f; + angularHigh.Z = 0f; + } + axisConstrainer.SetAngularLimits(angularLow, angularHigh); + + PhysicsScene.DetailLog("{0},BSPrim.LockAngularMotion,create,linLow={1},linHi={2},angLow={3},angHi={4}", + Prim.LocalID, linearLow, linearHigh, angularLow, angularHigh); + + // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. + axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); + + axisConstrainer.RecomputeConstraintVariables(Prim.RawMass); + } + + private void RemoveAxisLockConstraint() + { + if (LockAxisConstraint != null) + { + PhysicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); + LockAxisConstraint = null; + PhysicsScene.DetailLog("{0},BSPrim.CleanUpLockAxisPhysicals,destroyingConstraint", Prim.LocalID); + } + } +} +} -- cgit v1.1 From 75b8cf428e352b8939bb5e49f583d45dd226cf66 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 31 Mar 2013 17:38:13 -0700 Subject: BulletSim: fix line endings in BSActor* --- .../Physics/BulletSPlugin/BSActorLockAxis.cs | 339 +++++++++++---------- 1 file changed, 171 insertions(+), 168 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs index b4af126..5f74a14 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs @@ -1,168 +1,171 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyrightD - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using OMV = OpenMetaverse; - -namespace OpenSim.Region.Physics.BulletSPlugin -{ -public class BSActorLockAxis : BSActor -{ - bool TryExperimentalLockAxisCode = false; - BSConstraint LockAxisConstraint = null; - - public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) - : base(physicsScene, pObj,actorName) - { - LockAxisConstraint = null; - } - - // BSActor.isActive - public override bool isActive - { - get { return Enabled && Prim.IsPhysicallyActive; } - } - - // Release any connections and resources used by the actor. - // BSActor.Release() - public override void Release() - { - RemoveAxisLockConstraint(); - } - - // Called when physical parameters (properties set in Bullet) need to be re-applied. - // Called at taint-time. - // BSActor.Refresh() - public override void Refresh() - { - // If all the axis are free, we don't need to exist - if (Prim.LockedAxis == Prim.LockedAxisFree) - { - Prim.PhysicalActors.RemoveAndRelease(ActorName); - return; - } - // If the object is physically active, add the axis locking constraint - if (Enabled - && Prim.IsPhysicallyActive - && TryExperimentalLockAxisCode - && Prim.LockedAxis != Prim.LockedAxisFree) - { - if (LockAxisConstraint != null) - AddAxisLockConstraint(); - } - else - { - RemoveAxisLockConstraint(); - } - } - - // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). - // Register a prestep action to restore physical requirements before the next simulation step. - // Called at taint-time. - // BSActor.RemoveBodyDependencies() - public override void RemoveBodyDependencies() - { - if (LockAxisConstraint != null) - { - // If a constraint is set up, remove it from the physical scene - RemoveAxisLockConstraint(); - // Schedule a call before the next simulation step to restore the constraint. - PhysicsScene.PostTaintObject(Prim.LockedAxisActorName, Prim.LocalID, delegate() - { - Refresh(); - }); - } - } - - private void AddAxisLockConstraint() - { - // Lock that axis by creating a 6DOF constraint that has one end in the world and - // the other in the object. - // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817 - // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380 - - // Remove any existing axis constraint (just to be sure) - RemoveAxisLockConstraint(); - - BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(PhysicsScene.World, Prim.PhysBody, - OMV.Vector3.Zero, OMV.Quaternion.Inverse(Prim.RawOrientation), - true /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); - LockAxisConstraint = axisConstrainer; - PhysicsScene.Constraints.AddConstraint(LockAxisConstraint); - - // The constraint is tied to the world and oriented to the prim. - - // Free to move linearly - OMV.Vector3 linearLow = OMV.Vector3.Zero; - OMV.Vector3 linearHigh = PhysicsScene.TerrainManager.DefaultRegionSize; - axisConstrainer.SetLinearLimits(linearLow, linearHigh); - - // Angular with some axis locked - float f2PI = (float)Math.PI * 2f; - OMV.Vector3 angularLow = new OMV.Vector3(-f2PI, -f2PI, -f2PI); - OMV.Vector3 angularHigh = new OMV.Vector3(f2PI, f2PI, f2PI); - if (Prim.LockedAxis.X != 1f) - { - angularLow.X = 0f; - angularHigh.X = 0f; - } - if (Prim.LockedAxis.Y != 1f) - { - angularLow.Y = 0f; - angularHigh.Y = 0f; - } - if (Prim.LockedAxis.Z != 1f) - { - angularLow.Z = 0f; - angularHigh.Z = 0f; - } - axisConstrainer.SetAngularLimits(angularLow, angularHigh); - - PhysicsScene.DetailLog("{0},BSPrim.LockAngularMotion,create,linLow={1},linHi={2},angLow={3},angHi={4}", - Prim.LocalID, linearLow, linearHigh, angularLow, angularHigh); - - // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. - axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); - - axisConstrainer.RecomputeConstraintVariables(Prim.RawMass); - } - - private void RemoveAxisLockConstraint() - { - if (LockAxisConstraint != null) - { - PhysicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); - LockAxisConstraint = null; - PhysicsScene.DetailLog("{0},BSPrim.CleanUpLockAxisPhysicals,destroyingConstraint", Prim.LocalID); - } - } -} -} +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyrightD + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using OMV = OpenMetaverse; + +namespace OpenSim.Region.Physics.BulletSPlugin +{ +public class BSActorLockAxis : BSActor +{ + bool TryExperimentalLockAxisCode = false; + BSConstraint LockAxisConstraint = null; + + public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) + : base(physicsScene, pObj,actorName) + { + PhysicsScene.DetailLog("{0},BSActorLockAxis,constructor", Prim.LocalID); + LockAxisConstraint = null; + } + + // BSActor.isActive + public override bool isActive + { + get { return Enabled && Prim.IsPhysicallyActive; } + } + + // Release any connections and resources used by the actor. + // BSActor.Dispose() + public override void Dispose() + { + RemoveAxisLockConstraint(); + } + + // Called when physical parameters (properties set in Bullet) need to be re-applied. + // Called at taint-time. + // BSActor.Refresh() + public override void Refresh() + { + PhysicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedAxis={1},enabled={2},pActive={3}", + Prim.LocalID, Prim.LockedAxis, Enabled, Prim.IsPhysicallyActive); + // If all the axis are free, we don't need to exist + if (Prim.LockedAxis == Prim.LockedAxisFree) + { + Prim.PhysicalActors.RemoveAndRelease(ActorName); + return; + } + // If the object is physically active, add the axis locking constraint + if (Enabled + && Prim.IsPhysicallyActive + && TryExperimentalLockAxisCode + && Prim.LockedAxis != Prim.LockedAxisFree) + { + if (LockAxisConstraint != null) + AddAxisLockConstraint(); + } + else + { + RemoveAxisLockConstraint(); + } + } + + // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). + // Register a prestep action to restore physical requirements before the next simulation step. + // Called at taint-time. + // BSActor.RemoveBodyDependencies() + public override void RemoveBodyDependencies() + { + if (LockAxisConstraint != null) + { + // If a constraint is set up, remove it from the physical scene + RemoveAxisLockConstraint(); + // Schedule a call before the next simulation step to restore the constraint. + PhysicsScene.PostTaintObject(Prim.LockedAxisActorName, Prim.LocalID, delegate() + { + Refresh(); + }); + } + } + + private void AddAxisLockConstraint() + { + // Lock that axis by creating a 6DOF constraint that has one end in the world and + // the other in the object. + // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817 + // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380 + + // Remove any existing axis constraint (just to be sure) + RemoveAxisLockConstraint(); + + BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(PhysicsScene.World, Prim.PhysBody, + OMV.Vector3.Zero, OMV.Quaternion.Inverse(Prim.RawOrientation), + true /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); + LockAxisConstraint = axisConstrainer; + PhysicsScene.Constraints.AddConstraint(LockAxisConstraint); + + // The constraint is tied to the world and oriented to the prim. + + // Free to move linearly + OMV.Vector3 linearLow = OMV.Vector3.Zero; + OMV.Vector3 linearHigh = PhysicsScene.TerrainManager.DefaultRegionSize; + axisConstrainer.SetLinearLimits(linearLow, linearHigh); + + // Angular with some axis locked + float f2PI = (float)Math.PI * 2f; + OMV.Vector3 angularLow = new OMV.Vector3(-f2PI, -f2PI, -f2PI); + OMV.Vector3 angularHigh = new OMV.Vector3(f2PI, f2PI, f2PI); + if (Prim.LockedAxis.X != 1f) + { + angularLow.X = 0f; + angularHigh.X = 0f; + } + if (Prim.LockedAxis.Y != 1f) + { + angularLow.Y = 0f; + angularHigh.Y = 0f; + } + if (Prim.LockedAxis.Z != 1f) + { + angularLow.Z = 0f; + angularHigh.Z = 0f; + } + axisConstrainer.SetAngularLimits(angularLow, angularHigh); + + PhysicsScene.DetailLog("{0},BSPrim.LockAngularMotion,create,linLow={1},linHi={2},angLow={3},angHi={4}", + Prim.LocalID, linearLow, linearHigh, angularLow, angularHigh); + + // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. + axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); + + axisConstrainer.RecomputeConstraintVariables(Prim.RawMass); + } + + private void RemoveAxisLockConstraint() + { + if (LockAxisConstraint != null) + { + PhysicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); + LockAxisConstraint = null; + PhysicsScene.DetailLog("{0},BSPrim.CleanUpLockAxisPhysicals,destroyingConstraint", Prim.LocalID); + } + } +} +} -- cgit v1.1 From 933ac607468fb160636af601ce83ee1011794ec3 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 31 Mar 2013 22:06:02 -0700 Subject: BulletSim: not quite functional axis lock code. --- .../Physics/BulletSPlugin/BSActorLockAxis.cs | 62 ++++++++++++---------- 1 file changed, 34 insertions(+), 28 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs index 5f74a14..aa75663 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs @@ -42,14 +42,14 @@ public class BSActorLockAxis : BSActor public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) : base(physicsScene, pObj,actorName) { - PhysicsScene.DetailLog("{0},BSActorLockAxis,constructor", Prim.LocalID); + m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID); LockAxisConstraint = null; } // BSActor.isActive public override bool isActive { - get { return Enabled && Prim.IsPhysicallyActive; } + get { return Enabled && m_controllingPrim.IsPhysicallyActive; } } // Release any connections and resources used by the actor. @@ -64,21 +64,22 @@ public class BSActorLockAxis : BSActor // BSActor.Refresh() public override void Refresh() { - PhysicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedAxis={1},enabled={2},pActive={3}", - Prim.LocalID, Prim.LockedAxis, Enabled, Prim.IsPhysicallyActive); + m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedAxis={1},enabled={2},pActive={3}", + m_controllingPrim.LocalID, m_controllingPrim.LockedAxis, Enabled, m_controllingPrim.IsPhysicallyActive); // If all the axis are free, we don't need to exist - if (Prim.LockedAxis == Prim.LockedAxisFree) + if (m_controllingPrim.LockedAxis == m_controllingPrim.LockedAxisFree) { - Prim.PhysicalActors.RemoveAndRelease(ActorName); + m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,allAxisFree,removing={1}", m_controllingPrim.LocalID, ActorName); + m_controllingPrim.PhysicalActors.RemoveAndRelease(ActorName); return; } // If the object is physically active, add the axis locking constraint if (Enabled - && Prim.IsPhysicallyActive + && m_controllingPrim.IsPhysicallyActive && TryExperimentalLockAxisCode - && Prim.LockedAxis != Prim.LockedAxisFree) + && m_controllingPrim.LockedAxis != m_controllingPrim.LockedAxisFree) { - if (LockAxisConstraint != null) + if (LockAxisConstraint == null) AddAxisLockConstraint(); } else @@ -98,7 +99,7 @@ public class BSActorLockAxis : BSActor // If a constraint is set up, remove it from the physical scene RemoveAxisLockConstraint(); // Schedule a call before the next simulation step to restore the constraint. - PhysicsScene.PostTaintObject(Prim.LockedAxisActorName, Prim.LocalID, delegate() + m_physicsScene.PostTaintObject(m_controllingPrim.LockedAxisActorName, m_controllingPrim.LocalID, delegate() { Refresh(); }); @@ -115,56 +116,61 @@ public class BSActorLockAxis : BSActor // Remove any existing axis constraint (just to be sure) RemoveAxisLockConstraint(); - BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(PhysicsScene.World, Prim.PhysBody, - OMV.Vector3.Zero, OMV.Quaternion.Inverse(Prim.RawOrientation), - true /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); + BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(m_physicsScene.World, m_controllingPrim.PhysBody, + // OMV.Vector3.Zero, OMV.Quaternion.Identity, + OMV.Vector3.Zero, OMV.Quaternion.Inverse(m_controllingPrim.RawOrientation), + // OMV.Vector3.Zero, m_controllingPrim.RawOrientation, + false /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); LockAxisConstraint = axisConstrainer; - PhysicsScene.Constraints.AddConstraint(LockAxisConstraint); + m_physicsScene.Constraints.AddConstraint(LockAxisConstraint); // The constraint is tied to the world and oriented to the prim. - // Free to move linearly + // Free to move linearly in the region OMV.Vector3 linearLow = OMV.Vector3.Zero; - OMV.Vector3 linearHigh = PhysicsScene.TerrainManager.DefaultRegionSize; + OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize; axisConstrainer.SetLinearLimits(linearLow, linearHigh); // Angular with some axis locked - float f2PI = (float)Math.PI * 2f; - OMV.Vector3 angularLow = new OMV.Vector3(-f2PI, -f2PI, -f2PI); - OMV.Vector3 angularHigh = new OMV.Vector3(f2PI, f2PI, f2PI); - if (Prim.LockedAxis.X != 1f) + float fPI = (float)Math.PI; + OMV.Vector3 angularLow = new OMV.Vector3(-fPI, -fPI, -fPI); + OMV.Vector3 angularHigh = new OMV.Vector3(fPI, fPI, fPI); + if (m_controllingPrim.LockedAxis.X != 1f) { angularLow.X = 0f; angularHigh.X = 0f; } - if (Prim.LockedAxis.Y != 1f) + if (m_controllingPrim.LockedAxis.Y != 1f) { angularLow.Y = 0f; angularHigh.Y = 0f; } - if (Prim.LockedAxis.Z != 1f) + if (m_controllingPrim.LockedAxis.Z != 1f) { angularLow.Z = 0f; angularHigh.Z = 0f; } - axisConstrainer.SetAngularLimits(angularLow, angularHigh); + if (!axisConstrainer.SetAngularLimits(angularLow, angularHigh)) + { + m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits", m_controllingPrim.LocalID); + } - PhysicsScene.DetailLog("{0},BSPrim.LockAngularMotion,create,linLow={1},linHi={2},angLow={3},angHi={4}", - Prim.LocalID, linearLow, linearHigh, angularLow, angularHigh); + m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}", + m_controllingPrim.LocalID, linearLow, linearHigh, angularLow, angularHigh); // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); - axisConstrainer.RecomputeConstraintVariables(Prim.RawMass); + axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass); } private void RemoveAxisLockConstraint() { if (LockAxisConstraint != null) { - PhysicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); + m_physicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); LockAxisConstraint = null; - PhysicsScene.DetailLog("{0},BSPrim.CleanUpLockAxisPhysicals,destroyingConstraint", Prim.LocalID); + m_physicsScene.DetailLog("{0},BSActorLockAxis.RemoveAxisLockConstraint,destroyingConstraint", m_controllingPrim.LocalID); } } } -- cgit v1.1 From 68c8633ba18f0a11cfc0ed04d1d0c7c59e6cec76 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 2 Apr 2013 06:40:12 -0700 Subject: BulletSim: create axis lock constraint with proper orientation and enable axis lock functionality. --- OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs index aa75663..7219617 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs @@ -36,7 +36,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin { public class BSActorLockAxis : BSActor { - bool TryExperimentalLockAxisCode = false; + bool TryExperimentalLockAxisCode = true; BSConstraint LockAxisConstraint = null; public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) @@ -117,9 +117,7 @@ public class BSActorLockAxis : BSActor RemoveAxisLockConstraint(); BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(m_physicsScene.World, m_controllingPrim.PhysBody, - // OMV.Vector3.Zero, OMV.Quaternion.Identity, - OMV.Vector3.Zero, OMV.Quaternion.Inverse(m_controllingPrim.RawOrientation), - // OMV.Vector3.Zero, m_controllingPrim.RawOrientation, + OMV.Vector3.Zero, OMV.Quaternion.Identity, false /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); LockAxisConstraint = axisConstrainer; m_physicsScene.Constraints.AddConstraint(LockAxisConstraint); -- cgit v1.1 From fe16dc09da3f2736fad5a9e792f5f81098b5f9a1 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 7 Apr 2013 08:27:49 -0700 Subject: BulletSim: complete movement of physical object action code out of the physical object and into actors for setForce, setTorque, hover, lock axis and avatar move. --- OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs index 7219617..c40a499 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs @@ -40,7 +40,7 @@ public class BSActorLockAxis : BSActor BSConstraint LockAxisConstraint = null; public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) - : base(physicsScene, pObj,actorName) + : base(physicsScene, pObj, actorName) { m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID); LockAxisConstraint = null; @@ -99,7 +99,7 @@ public class BSActorLockAxis : BSActor // If a constraint is set up, remove it from the physical scene RemoveAxisLockConstraint(); // Schedule a call before the next simulation step to restore the constraint. - m_physicsScene.PostTaintObject(m_controllingPrim.LockedAxisActorName, m_controllingPrim.LocalID, delegate() + m_physicsScene.PostTaintObject("BSActorLockAxis:" + ActorName, m_controllingPrim.LocalID, delegate() { Refresh(); }); -- cgit v1.1 From a7a1b8b7e9269b446e3396a35153b00942c1e35b Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 7 Apr 2013 14:05:35 -0700 Subject: BulletSim: clean up actor code so routines use the same coding pattern. Fix a few enabling problems. --- .../Physics/BulletSPlugin/BSActorLockAxis.cs | 105 ++++++++++----------- 1 file changed, 51 insertions(+), 54 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs index c40a499..09ee32b 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs @@ -36,7 +36,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin { public class BSActorLockAxis : BSActor { - bool TryExperimentalLockAxisCode = true; BSConstraint LockAxisConstraint = null; public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) @@ -69,18 +68,13 @@ public class BSActorLockAxis : BSActor // If all the axis are free, we don't need to exist if (m_controllingPrim.LockedAxis == m_controllingPrim.LockedAxisFree) { - m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,allAxisFree,removing={1}", m_controllingPrim.LocalID, ActorName); - m_controllingPrim.PhysicalActors.RemoveAndRelease(ActorName); - return; + Enabled = false; } + // If the object is physically active, add the axis locking constraint - if (Enabled - && m_controllingPrim.IsPhysicallyActive - && TryExperimentalLockAxisCode - && m_controllingPrim.LockedAxis != m_controllingPrim.LockedAxisFree) + if (isActive) { - if (LockAxisConstraint == null) - AddAxisLockConstraint(); + AddAxisLockConstraint(); } else { @@ -108,58 +102,61 @@ public class BSActorLockAxis : BSActor private void AddAxisLockConstraint() { - // Lock that axis by creating a 6DOF constraint that has one end in the world and - // the other in the object. - // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817 - // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380 + if (LockAxisConstraint == null) + { + // Lock that axis by creating a 6DOF constraint that has one end in the world and + // the other in the object. + // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817 + // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380 - // Remove any existing axis constraint (just to be sure) - RemoveAxisLockConstraint(); + // Remove any existing axis constraint (just to be sure) + RemoveAxisLockConstraint(); - BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(m_physicsScene.World, m_controllingPrim.PhysBody, - OMV.Vector3.Zero, OMV.Quaternion.Identity, - false /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); - LockAxisConstraint = axisConstrainer; - m_physicsScene.Constraints.AddConstraint(LockAxisConstraint); + BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(m_physicsScene.World, m_controllingPrim.PhysBody, + OMV.Vector3.Zero, OMV.Quaternion.Identity, + false /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); + LockAxisConstraint = axisConstrainer; + m_physicsScene.Constraints.AddConstraint(LockAxisConstraint); - // The constraint is tied to the world and oriented to the prim. + // The constraint is tied to the world and oriented to the prim. - // Free to move linearly in the region - OMV.Vector3 linearLow = OMV.Vector3.Zero; - OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize; - axisConstrainer.SetLinearLimits(linearLow, linearHigh); + // Free to move linearly in the region + OMV.Vector3 linearLow = OMV.Vector3.Zero; + OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize; + axisConstrainer.SetLinearLimits(linearLow, linearHigh); - // Angular with some axis locked - float fPI = (float)Math.PI; - OMV.Vector3 angularLow = new OMV.Vector3(-fPI, -fPI, -fPI); - OMV.Vector3 angularHigh = new OMV.Vector3(fPI, fPI, fPI); - if (m_controllingPrim.LockedAxis.X != 1f) - { - angularLow.X = 0f; - angularHigh.X = 0f; - } - if (m_controllingPrim.LockedAxis.Y != 1f) - { - angularLow.Y = 0f; - angularHigh.Y = 0f; - } - if (m_controllingPrim.LockedAxis.Z != 1f) - { - angularLow.Z = 0f; - angularHigh.Z = 0f; - } - if (!axisConstrainer.SetAngularLimits(angularLow, angularHigh)) - { - m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits", m_controllingPrim.LocalID); - } + // Angular with some axis locked + float fPI = (float)Math.PI; + OMV.Vector3 angularLow = new OMV.Vector3(-fPI, -fPI, -fPI); + OMV.Vector3 angularHigh = new OMV.Vector3(fPI, fPI, fPI); + if (m_controllingPrim.LockedAxis.X != 1f) + { + angularLow.X = 0f; + angularHigh.X = 0f; + } + if (m_controllingPrim.LockedAxis.Y != 1f) + { + angularLow.Y = 0f; + angularHigh.Y = 0f; + } + if (m_controllingPrim.LockedAxis.Z != 1f) + { + angularLow.Z = 0f; + angularHigh.Z = 0f; + } + if (!axisConstrainer.SetAngularLimits(angularLow, angularHigh)) + { + m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits", m_controllingPrim.LocalID); + } - m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}", - m_controllingPrim.LocalID, linearLow, linearHigh, angularLow, angularHigh); + m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}", + m_controllingPrim.LocalID, linearLow, linearHigh, angularLow, angularHigh); - // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. - axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); + // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. + axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); - axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass); + axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass); + } } private void RemoveAxisLockConstraint() -- cgit v1.1 From e5582939fd8d78b61c6f1eeda6de45d94f4b4926 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 28 Apr 2013 14:44:21 -0700 Subject: BulletSim: massive refactor of shape classes. Removed shape specific code from BSShapeCollection. Using BSShape* classes to hold references to shape. Simplified shape dependency callbacks. Remove 'PreferredShape' methods and have each class specify shape type. Disable compound shape linkset for a later commit that will simplify linkset implementation. --- OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs index 09ee32b..6059af5 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs @@ -85,8 +85,8 @@ public class BSActorLockAxis : BSActor // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). // Register a prestep action to restore physical requirements before the next simulation step. // Called at taint-time. - // BSActor.RemoveBodyDependencies() - public override void RemoveBodyDependencies() + // BSActor.RemoveDependencies() + public override void RemoveDependencies() { if (LockAxisConstraint != null) { -- cgit v1.1 From 92ee288d666963aae2a058cc964be009a504f084 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 29 Apr 2013 07:54:50 -0700 Subject: BulletSim: remove trailing white space to make git happier. No functional changes. --- OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs index 6059af5..7801d8e 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs @@ -63,7 +63,7 @@ public class BSActorLockAxis : BSActor // BSActor.Refresh() public override void Refresh() { - m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedAxis={1},enabled={2},pActive={3}", + m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedAxis={1},enabled={2},pActive={3}", m_controllingPrim.LocalID, m_controllingPrim.LockedAxis, Enabled, m_controllingPrim.IsPhysicallyActive); // If all the axis are free, we don't need to exist if (m_controllingPrim.LockedAxis == m_controllingPrim.LockedAxisFree) -- cgit v1.1 From f9fb1484aa00f8bfadead06ce71d004502fb564e Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Fri, 3 May 2013 15:46:35 -0700 Subject: BulletSim: extend BSActorLockAxis to allow locking linear movement in addition to angular movement. Not enabled by anything yet. --- .../Physics/BulletSPlugin/BSActorLockAxis.cs | 25 +++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs index 7801d8e..8b0fdeb 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs @@ -64,9 +64,9 @@ public class BSActorLockAxis : BSActor public override void Refresh() { m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedAxis={1},enabled={2},pActive={3}", - m_controllingPrim.LocalID, m_controllingPrim.LockedAxis, Enabled, m_controllingPrim.IsPhysicallyActive); + m_controllingPrim.LocalID, m_controllingPrim.LockedAngularAxis, Enabled, m_controllingPrim.IsPhysicallyActive); // If all the axis are free, we don't need to exist - if (m_controllingPrim.LockedAxis == m_controllingPrim.LockedAxisFree) + if (m_controllingPrim.LockedAngularAxis == m_controllingPrim.LockedAxisFree) { Enabled = false; } @@ -123,23 +123,38 @@ public class BSActorLockAxis : BSActor // Free to move linearly in the region OMV.Vector3 linearLow = OMV.Vector3.Zero; OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize; + if (m_controllingPrim.LockedLinearAxis.X != BSPhysObject.FreeAxis) + { + linearLow.X = m_controllingPrim.RawPosition.X; + linearHigh.X = m_controllingPrim.RawPosition.X; + } + if (m_controllingPrim.LockedLinearAxis.Y != BSPhysObject.FreeAxis) + { + linearLow.Y = m_controllingPrim.RawPosition.Y; + linearHigh.Y = m_controllingPrim.RawPosition.Y; + } + if (m_controllingPrim.LockedLinearAxis.Z != BSPhysObject.FreeAxis) + { + linearLow.Z = m_controllingPrim.RawPosition.Z; + linearHigh.Z = m_controllingPrim.RawPosition.Z; + } axisConstrainer.SetLinearLimits(linearLow, linearHigh); // Angular with some axis locked float fPI = (float)Math.PI; OMV.Vector3 angularLow = new OMV.Vector3(-fPI, -fPI, -fPI); OMV.Vector3 angularHigh = new OMV.Vector3(fPI, fPI, fPI); - if (m_controllingPrim.LockedAxis.X != 1f) + if (m_controllingPrim.LockedAngularAxis.X != BSPhysObject.FreeAxis) { angularLow.X = 0f; angularHigh.X = 0f; } - if (m_controllingPrim.LockedAxis.Y != 1f) + if (m_controllingPrim.LockedAngularAxis.Y != BSPhysObject.FreeAxis) { angularLow.Y = 0f; angularHigh.Y = 0f; } - if (m_controllingPrim.LockedAxis.Z != 1f) + if (m_controllingPrim.LockedAngularAxis.Z != BSPhysObject.FreeAxis) { angularLow.Z = 0f; angularHigh.Z = 0f; -- cgit v1.1 From b0cb0ec02f5f567539b340727727bee1a43836e6 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 23 Mar 2014 13:08:31 -0700 Subject: BulletSim: fix problem where axis constraints were also constraining linear motion. The code was limiting linear motion to be only in the positive direction for any axis that was constrained. --- OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs index 8b0fdeb..7e61007 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) Contributors, http://opensimulator.org/ * See CONTRIBUTORS.TXT for a full list of copyright holders. * @@ -121,8 +121,10 @@ public class BSActorLockAxis : BSActor // The constraint is tied to the world and oriented to the prim. // Free to move linearly in the region - OMV.Vector3 linearLow = OMV.Vector3.Zero; - OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize; + // OMV.Vector3 linearLow = OMV.Vector3.Zero; + // OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize; + OMV.Vector3 linearLow = new OMV.Vector3(-10000f, -10000f, -10000f); + OMV.Vector3 linearHigh = new OMV.Vector3(10000f, 10000f, 10000f); if (m_controllingPrim.LockedLinearAxis.X != BSPhysObject.FreeAxis) { linearLow.X = m_controllingPrim.RawPosition.X; -- cgit v1.1 From 291c7cdbcc80dc270418a4959ccfa0ed8cc0c190 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 31 Dec 2014 12:43:26 -0800 Subject: BulletSim: Add axis locking enabled through the ExtendedPhysics module. Allows locking of prim/linkset relative moving in each of the linear and angular axis. Limits on movement or rotation can be set. --- .../Physics/BulletSPlugin/BSActorLockAxis.cs | 121 ++++++++++++--------- 1 file changed, 70 insertions(+), 51 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs index 7e61007..48cab64 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs @@ -37,12 +37,19 @@ namespace OpenSim.Region.Physics.BulletSPlugin public class BSActorLockAxis : BSActor { BSConstraint LockAxisConstraint = null; + // The lock access flags (which axises were locked) when the contraint was built. + // Used to see if locking has changed since when the constraint was built. + OMV.Vector3 LockAxisLinearFlags; + OMV.Vector3 LockAxisAngularFlags; public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) : base(physicsScene, pObj, actorName) { m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID); LockAxisConstraint = null; + + // we place our constraint just before the simulation step to make sure the linkset is complete + m_physicsScene.BeforeStep += PhysicsScene_BeforeStep; } // BSActor.isActive @@ -55,6 +62,7 @@ public class BSActorLockAxis : BSActor // BSActor.Dispose() public override void Dispose() { + m_physicsScene.BeforeStep -= PhysicsScene_BeforeStep; RemoveAxisLockConstraint(); } @@ -63,10 +71,18 @@ public class BSActorLockAxis : BSActor // BSActor.Refresh() public override void Refresh() { - m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedAxis={1},enabled={2},pActive={3}", - m_controllingPrim.LocalID, m_controllingPrim.LockedAngularAxis, Enabled, m_controllingPrim.IsPhysicallyActive); + // Since the axis logging is done with a constraint, Refresh() time is good for + // changing parameters but this needs to wait until the prim/linkset is physically + // constructed. Therefore, the constraint itself is placed at pre-step time. + /* + m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedLinear={1},lockedAngular={2},enabled={3},pActive={4}", + m_controllingPrim.LocalID, + m_controllingPrim.LockedLinearAxis, + m_controllingPrim.LockedAngularAxis, + Enabled, m_controllingPrim.IsPhysicallyActive); // If all the axis are free, we don't need to exist - if (m_controllingPrim.LockedAngularAxis == m_controllingPrim.LockedAxisFree) + if (m_controllingPrim.LockedAngularAxis == m_controllingPrim.LockedAxisFree + && m_controllingPrim.LockedLinearAxis == m_controllingPrim.LockedAxisFree) { Enabled = false; } @@ -74,12 +90,21 @@ public class BSActorLockAxis : BSActor // If the object is physically active, add the axis locking constraint if (isActive) { + // Check to see if the locking parameters have changed + if (m_controllingPrim.LockedLinearAxis != this.LockAxisLinearFlags + || m_controllingPrim.LockedAngularAxis != this.LockAxisAngularFlags) + { + // The locking has changed. Remove the old constraint and build a new one + RemoveAxisLockConstraint(); + } + AddAxisLockConstraint(); } else { RemoveAxisLockConstraint(); } + */ } // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). @@ -88,15 +113,35 @@ public class BSActorLockAxis : BSActor // BSActor.RemoveDependencies() public override void RemoveDependencies() { - if (LockAxisConstraint != null) + RemoveAxisLockConstraint(); + // The pre-step action will restore the constraint of needed + } + + private void PhysicsScene_BeforeStep(float timestep) + { + // If all the axis are free, we don't need to exist + if (m_controllingPrim.LockedAngularAxis == m_controllingPrim.LockedAxisFree + && m_controllingPrim.LockedLinearAxis == m_controllingPrim.LockedAxisFree) { - // If a constraint is set up, remove it from the physical scene - RemoveAxisLockConstraint(); - // Schedule a call before the next simulation step to restore the constraint. - m_physicsScene.PostTaintObject("BSActorLockAxis:" + ActorName, m_controllingPrim.LocalID, delegate() + Enabled = false; + } + + // If the object is physically active, add the axis locking constraint + if (isActive) + { + // Check to see if the locking parameters have changed + if (m_controllingPrim.LockedLinearAxis != this.LockAxisLinearFlags + || m_controllingPrim.LockedAngularAxis != this.LockAxisAngularFlags) { - Refresh(); - }); + // The locking has changed. Remove the old constraint and build a new one + RemoveAxisLockConstraint(); + } + + AddAxisLockConstraint(); + } + else + { + RemoveAxisLockConstraint(); } } @@ -118,56 +163,30 @@ public class BSActorLockAxis : BSActor LockAxisConstraint = axisConstrainer; m_physicsScene.Constraints.AddConstraint(LockAxisConstraint); + // Remember the clocking being inforced so we can notice if they have changed + LockAxisLinearFlags = m_controllingPrim.LockedLinearAxis; + LockAxisAngularFlags = m_controllingPrim.LockedAngularAxis; + // The constraint is tied to the world and oriented to the prim. - // Free to move linearly in the region - // OMV.Vector3 linearLow = OMV.Vector3.Zero; - // OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize; - OMV.Vector3 linearLow = new OMV.Vector3(-10000f, -10000f, -10000f); - OMV.Vector3 linearHigh = new OMV.Vector3(10000f, 10000f, 10000f); - if (m_controllingPrim.LockedLinearAxis.X != BSPhysObject.FreeAxis) - { - linearLow.X = m_controllingPrim.RawPosition.X; - linearHigh.X = m_controllingPrim.RawPosition.X; - } - if (m_controllingPrim.LockedLinearAxis.Y != BSPhysObject.FreeAxis) + if (!axisConstrainer.SetLinearLimits(m_controllingPrim.LockedLinearAxisLow, m_controllingPrim.LockedLinearAxisHigh)) { - linearLow.Y = m_controllingPrim.RawPosition.Y; - linearHigh.Y = m_controllingPrim.RawPosition.Y; + m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetLinearLimits", + m_controllingPrim.LocalID); } - if (m_controllingPrim.LockedLinearAxis.Z != BSPhysObject.FreeAxis) - { - linearLow.Z = m_controllingPrim.RawPosition.Z; - linearHigh.Z = m_controllingPrim.RawPosition.Z; - } - axisConstrainer.SetLinearLimits(linearLow, linearHigh); - // Angular with some axis locked - float fPI = (float)Math.PI; - OMV.Vector3 angularLow = new OMV.Vector3(-fPI, -fPI, -fPI); - OMV.Vector3 angularHigh = new OMV.Vector3(fPI, fPI, fPI); - if (m_controllingPrim.LockedAngularAxis.X != BSPhysObject.FreeAxis) - { - angularLow.X = 0f; - angularHigh.X = 0f; - } - if (m_controllingPrim.LockedAngularAxis.Y != BSPhysObject.FreeAxis) - { - angularLow.Y = 0f; - angularHigh.Y = 0f; - } - if (m_controllingPrim.LockedAngularAxis.Z != BSPhysObject.FreeAxis) - { - angularLow.Z = 0f; - angularHigh.Z = 0f; - } - if (!axisConstrainer.SetAngularLimits(angularLow, angularHigh)) + if (!axisConstrainer.SetAngularLimits(m_controllingPrim.LockedAngularAxisLow, m_controllingPrim.LockedAngularAxisHigh)) { - m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits", m_controllingPrim.LocalID); + m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits", + m_controllingPrim.LocalID); } m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}", - m_controllingPrim.LocalID, linearLow, linearHigh, angularLow, angularHigh); + m_controllingPrim.LocalID, + m_controllingPrim.LockedLinearAxisLow, + m_controllingPrim.LockedLinearAxisHigh, + m_controllingPrim.LockedAngularAxisLow, + m_controllingPrim.LockedAngularAxisHigh); // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); -- cgit v1.1 From fe86df0ec9582c61ad3a50b53a73398393b13c87 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 9 Aug 2015 15:34:06 -0700 Subject: BulletSim: update the motion actors so they completely clean themselves when Dispose() is called. This reduces chance of object leakage when destroying objects. Rearrange initialization and shut down of BSActorLockAxis so it is consistant with other actors. --- .../Physics/BulletSPlugin/BSActorLockAxis.cs | 59 +++++++++++++--------- 1 file changed, 35 insertions(+), 24 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs index 48cab64..3b3c161 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs @@ -36,7 +36,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin { public class BSActorLockAxis : BSActor { - BSConstraint LockAxisConstraint = null; + private BSConstraint LockAxisConstraint = null; + private bool HaveRegisteredForBeforeStepCallback = false; + // The lock access flags (which axises were locked) when the contraint was built. // Used to see if locking has changed since when the constraint was built. OMV.Vector3 LockAxisLinearFlags; @@ -47,9 +49,7 @@ public class BSActorLockAxis : BSActor { m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID); LockAxisConstraint = null; - - // we place our constraint just before the simulation step to make sure the linkset is complete - m_physicsScene.BeforeStep += PhysicsScene_BeforeStep; + HaveRegisteredForBeforeStepCallback = false; } // BSActor.isActive @@ -62,7 +62,8 @@ public class BSActorLockAxis : BSActor // BSActor.Dispose() public override void Dispose() { - m_physicsScene.BeforeStep -= PhysicsScene_BeforeStep; + Enabled = false; + UnRegisterForBeforeStepCallback(); RemoveAxisLockConstraint(); } @@ -74,37 +75,26 @@ public class BSActorLockAxis : BSActor // Since the axis logging is done with a constraint, Refresh() time is good for // changing parameters but this needs to wait until the prim/linkset is physically // constructed. Therefore, the constraint itself is placed at pre-step time. - /* - m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedLinear={1},lockedAngular={2},enabled={3},pActive={4}", - m_controllingPrim.LocalID, - m_controllingPrim.LockedLinearAxis, - m_controllingPrim.LockedAngularAxis, - Enabled, m_controllingPrim.IsPhysicallyActive); + // If all the axis are free, we don't need to exist + // Refresh() only turns off. Enabling is done by InitializeAxisActor() + // whenever parameters are changed. + // This leaves 'enable' free to turn off an actor when it is not wanted to run. if (m_controllingPrim.LockedAngularAxis == m_controllingPrim.LockedAxisFree && m_controllingPrim.LockedLinearAxis == m_controllingPrim.LockedAxisFree) { Enabled = false; } - // If the object is physically active, add the axis locking constraint if (isActive) { - // Check to see if the locking parameters have changed - if (m_controllingPrim.LockedLinearAxis != this.LockAxisLinearFlags - || m_controllingPrim.LockedAngularAxis != this.LockAxisAngularFlags) - { - // The locking has changed. Remove the old constraint and build a new one - RemoveAxisLockConstraint(); - } - - AddAxisLockConstraint(); + RegisterForBeforeStepCallback(); } else { - RemoveAxisLockConstraint(); + RemoveDependencies(); + UnRegisterForBeforeStepCallback(); } - */ } // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). @@ -114,7 +104,24 @@ public class BSActorLockAxis : BSActor public override void RemoveDependencies() { RemoveAxisLockConstraint(); - // The pre-step action will restore the constraint of needed + } + + private void RegisterForBeforeStepCallback() + { + if (!HaveRegisteredForBeforeStepCallback) + { + m_physicsScene.BeforeStep += PhysicsScene_BeforeStep; + HaveRegisteredForBeforeStepCallback = true; + } + } + + private void UnRegisterForBeforeStepCallback() + { + if (HaveRegisteredForBeforeStepCallback) + { + m_physicsScene.BeforeStep -= PhysicsScene_BeforeStep; + HaveRegisteredForBeforeStepCallback = false; + } } private void PhysicsScene_BeforeStep(float timestep) @@ -145,6 +152,7 @@ public class BSActorLockAxis : BSActor } } + // Note that this relies on being called at TaintTime private void AddAxisLockConstraint() { if (LockAxisConstraint == null) @@ -192,11 +200,14 @@ public class BSActorLockAxis : BSActor axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass); + + RegisterForBeforeStepCallback(); } } private void RemoveAxisLockConstraint() { + UnRegisterForBeforeStepCallback(); if (LockAxisConstraint != null) { m_physicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); -- cgit v1.1