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 +++++++++++++++++++++ OpenSim/Region/Physics/BulletSPlugin/BSActors.cs | 123 +++++++++++++++ .../Region/Physics/BulletSPlugin/BSPhysObject.cs | 11 ++ OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 83 ++-------- 4 files changed, 311 insertions(+), 74 deletions(-) create mode 100755 OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs create mode 100755 OpenSim/Region/Physics/BulletSPlugin/BSActors.cs (limited to 'OpenSim') 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); + } + } +} +} diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs new file mode 100755 index 0000000..b9b5ce1 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs @@ -0,0 +1,123 @@ +/* + * 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.Text; + +namespace OpenSim.Region.Physics.BulletSPlugin +{ +public class BSActorCollection +{ + private BSScene PhysicsScene { get; set; } + private Dictionary m_actors; + + public BSActorCollection(BSScene physicsScene) + { + PhysicsScene = physicsScene; + m_actors = new Dictionary(); + } + public void Add(string name, BSActor actor) + { + m_actors[name] = actor; + } + public bool RemoveAndRelease(string name) + { + bool ret = false; + if (m_actors.ContainsKey(name)) + { + BSActor beingRemoved = m_actors[name]; + beingRemoved.Release(); + m_actors.Remove(name); + ret = true; + } + return ret; + } + public void Clear() + { + Release(); + m_actors.Clear(); + } + public bool HasActor(string name) + { + return m_actors.ContainsKey(name); + } + public void ForEachActor(Action act) + { + foreach (KeyValuePair kvp in m_actors) + act(kvp.Value); + } + + public void Release() + { + ForEachActor(a => a.Release()); + } + public void Refresh() + { + ForEachActor(a => a.Refresh()); + } + public void RemoveBodyDependencies() + { + ForEachActor(a => a.RemoveBodyDependencies()); + } +} + +// ============================================================================= +public abstract class BSActor +{ + protected BSScene PhysicsScene { get; private set; } + protected BSPhysObject Prim { get; private set; } + protected bool Enabled { get; set; } + public string ActorName { get; private set; } + + public BSActor(BSScene physicsScene, BSPhysObject pObj, string actorName) + { + PhysicsScene = physicsScene; + Prim = pObj; + ActorName = actorName; + Enabled = true; + } + + // Return 'true' if activily updating the prim + public virtual bool isActive + { + get { return Enabled; } + } + // Turn the actor on an off. + public virtual void Enable(bool setEnabled) + { + Enabled = setEnabled; + } + // Release any connections and resources used by the actor. + public abstract void Release(); + // Called when physical parameters (properties set in Bullet) need to be re-applied. + public abstract void Refresh(); + // 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. + public abstract void RemoveBodyDependencies(); + +} +} diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 6bb88c7..cba2646 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -78,6 +78,9 @@ public abstract class BSPhysObject : PhysicsActor Name = name; // PhysicsActor also has the name of the object. Someday consolidate. TypeName = typeName; + // The collection of things that push me around + PhysicalActors = new BSActorCollection(PhysicsScene); + // Initialize variables kept in base. GravModifier = 1.0f; Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity); @@ -109,6 +112,10 @@ public abstract class BSPhysObject : PhysicsActor { UnRegisterAllPreStepActions(); UnRegisterAllPostStepActions(); + PhysicsScene.TaintedObject("BSPhysObject.Destroy", delegate() + { + PhysicalActors.Release(); + }); } public BSScene PhysicsScene { get; protected set; } @@ -230,6 +237,7 @@ public abstract class BSPhysObject : PhysicsActor public OMV.Vector3 LockedAxis { get; set; } // zero means locked. one means free. public readonly OMV.Vector3 LockedAxisFree = new OMV.Vector3(1f, 1f, 1f); // All axis are free + public readonly String LockedAxisActorName = "BSPrim.LockedAxis"; #region Collisions @@ -413,6 +421,9 @@ public abstract class BSPhysObject : PhysicsActor #endregion // Collisions #region Per Simulation Step actions + + public BSActorCollection PhysicalActors; + // There are some actions that must be performed for a physical object before each simulation step. // These actions are optional so, rather than scanning all the physical objects and asking them // if they have anything to do, a physical object registers for an event call before the step is performed. diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 6a5461a..68a6c41 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -126,7 +126,7 @@ public class BSPrim : BSPhysObject // Undo any vehicle properties this.VehicleType = (int)Vehicle.TYPE_NONE; - PhysicsScene.TaintedObject("BSPrim.destroy", delegate() + PhysicsScene.TaintedObject("BSPrim.Destroy", delegate() { DetailLog("{0},BSPrim.Destroy,taint,", LocalID); // If there are physical body and shape, release my use of same. @@ -257,98 +257,31 @@ public class BSPrim : BSPhysObject }); } - bool TryExperimentalLockAxisCode = false; - BSConstraint LockAxisConstraint = null; public override void LockAngularMotion(OMV.Vector3 axis) { DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis); // "1" means free, "0" means locked - OMV.Vector3 locking = new OMV.Vector3(1f, 1f, 1f); + OMV.Vector3 locking = LockedAxisFree; if (axis.X != 1) locking.X = 0f; if (axis.Y != 1) locking.Y = 0f; if (axis.Z != 1) locking.Z = 0f; LockedAxis = locking; - if (TryExperimentalLockAxisCode && LockedAxis != LockedAxisFree) + if (LockedAxis != LockedAxisFree) { - // 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 - PhysicsScene.TaintedObject("BSPrim.LockAngularMotion", delegate() { - CleanUpLockAxisPhysicals(true /* inTaintTime */); - - BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(PhysicsScene.World, PhysBody, - OMV.Vector3.Zero, OMV.Quaternion.Inverse(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 (LockedAxis.X != 1f) - { - angularLow.X = 0f; - angularHigh.X = 0f; - } - if (LockedAxis.Y != 1f) - { - angularLow.Y = 0f; - angularHigh.Y = 0f; - } - if (LockedAxis.Z != 1f) + // If there is not already an axis locker, make one + if (!PhysicalActors.HasActor(LockedAxisActorName)) { - angularLow.Z = 0f; - angularHigh.Z = 0f; + PhysicalActors.Add(LockedAxisActorName, new BSActorLockAxis(PhysicsScene, this, LockedAxisActorName)); } - axisConstrainer.SetAngularLimits(angularLow, angularHigh); - - DetailLog("{0},BSPrim.LockAngularMotion,create,linLow={1},linHi={2},angLow={3},angHi={4}", - 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(RawMass); + UpdatePhysicalParameters(); }); } - else - { - // Everything seems unlocked - CleanUpLockAxisPhysicals(false /* inTaintTime */); - } - return; } - // Get rid of any constraint built for LockAxis - // Most often the constraint is removed when the constraint collection is cleaned for this prim. - private void CleanUpLockAxisPhysicals(bool inTaintTime) - { - if (LockAxisConstraint != null) - { - PhysicsScene.TaintedObject(inTaintTime, "BSPrim.CleanUpLockAxisPhysicals", delegate() - { - if (LockAxisConstraint != null) - { - PhysicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); - LockAxisConstraint = null; - DetailLog("{0},BSPrim.CleanUpLockAxisPhysicals,destroyingConstraint", LocalID); - } - }); - } - } public override OMV.Vector3 RawPosition { @@ -916,6 +849,7 @@ public class BSPrim : BSPhysObject // Update vehicle specific parameters (after MakeDynamic() so can change physical parameters) VehicleController.Refresh(); + PhysicalActors.Refresh(); // Arrange for collision events if the simulator wants them EnableCollisions(SubscribedEvents()); @@ -1753,6 +1687,7 @@ public class BSPrim : BSPhysObject protected virtual void RemoveBodyDependencies() { VehicleController.RemoveBodyDependencies(this); + PhysicalActors.RemoveBodyDependencies(); } // The physics engine says that properties have updated. Update same and inform -- cgit v1.1 From 747ece59d20370115fdaf90a5a08ab77f5605b1c Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 31 Mar 2013 17:36:15 -0700 Subject: BulletSim: convert BSDynamic to a BSActor and change BSPrim to set up the vehicle actor. --- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 199 +++++++++++++-------- .../Region/Physics/BulletSPlugin/BSPhysObject.cs | 2 +- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 46 ++--- OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 2 +- .../Physics/BulletSPlugin/Tests/BasicVehicles.cs | 12 +- 5 files changed, 149 insertions(+), 112 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 65df741..8b5da0d 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -40,13 +40,14 @@ using OpenSim.Region.Physics.Manager; namespace OpenSim.Region.Physics.BulletSPlugin { - public sealed class BSDynamics + public sealed class BSDynamics : BSActor { private static string LogHeader = "[BULLETSIM VEHICLE]"; - private BSScene PhysicsScene { get; set; } // the prim this dynamic controller belongs to - private BSPrim Prim { get; set; } + private BSPrim ControllingPrim { get; set; } + + private bool m_haveRegisteredForSceneEvents; // mass of the vehicle fetched each time we're calles private float m_vehicleMass; @@ -129,11 +130,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin public bool enableAngularDeflection; public bool enableAngularBanking; - public BSDynamics(BSScene myScene, BSPrim myPrim) + public BSDynamics(BSScene myScene, BSPrim myPrim, string actorName) + : base(myScene, myPrim, actorName) { - PhysicsScene = myScene; - Prim = myPrim; + ControllingPrim = myPrim; Type = Vehicle.TYPE_NONE; + m_haveRegisteredForSceneEvents = false; SetupVehicleDebugging(); } @@ -155,7 +157,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Return 'true' if this vehicle is doing vehicle things public bool IsActive { - get { return (Type != Vehicle.TYPE_NONE && Prim.IsPhysicallyActive); } + get { return (Type != Vehicle.TYPE_NONE && ControllingPrim.IsPhysicallyActive); } } // Return 'true' if this a vehicle that should be sitting on the ground @@ -167,7 +169,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin #region Vehicle parameter setting public void ProcessFloatVehicleParam(Vehicle pParam, float pValue) { - VDetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue); + VDetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", ControllingPrim.LocalID, pParam, pValue); switch (pParam) { case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY: @@ -195,7 +197,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin break; case Vehicle.BUOYANCY: m_VehicleBuoyancy = ClampInRange(-1f, pValue, 1f); - m_VehicleGravity = Prim.ComputeGravity(m_VehicleBuoyancy); + m_VehicleGravity = ControllingPrim.ComputeGravity(m_VehicleBuoyancy); break; case Vehicle.HOVER_EFFICIENCY: m_VhoverEfficiency = ClampInRange(0f, pValue, 1f); @@ -258,7 +260,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin internal void ProcessVectorVehicleParam(Vehicle pParam, Vector3 pValue) { - VDetailLog("{0},ProcessVectorVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue); + VDetailLog("{0},ProcessVectorVehicleParam,param={1},val={2}", ControllingPrim.LocalID, pParam, pValue); switch (pParam) { case Vehicle.ANGULAR_FRICTION_TIMESCALE: @@ -294,7 +296,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin internal void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue) { - VDetailLog("{0},ProcessRotationalVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue); + VDetailLog("{0},ProcessRotationalVehicleParam,param={1},val={2}", ControllingPrim.LocalID, pParam, pValue); switch (pParam) { case Vehicle.REFERENCE_FRAME: @@ -308,7 +310,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin internal void ProcessVehicleFlags(int pParam, bool remove) { - VDetailLog("{0},ProcessVehicleFlags,param={1},remove={2}", Prim.LocalID, pParam, remove); + VDetailLog("{0},ProcessVehicleFlags,param={1},remove={2}", ControllingPrim.LocalID, pParam, remove); VehicleFlag parm = (VehicleFlag)pParam; if (pParam == -1) m_flags = (VehicleFlag)0; @@ -323,7 +325,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin public void ProcessTypeChange(Vehicle pType) { - VDetailLog("{0},ProcessTypeChange,type={1}", Prim.LocalID, pType); + VDetailLog("{0},ProcessTypeChange,type={1}", ControllingPrim.LocalID, pType); // Set Defaults For Type Type = pType; switch (pType) @@ -578,13 +580,23 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_verticalAttractionMotor.FrictionTimescale = new Vector3(BSMotor.Infinite, BSMotor.Infinite, 0.1f); m_verticalAttractionMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging) */ + + if (this.Type == Vehicle.TYPE_NONE) + { + UnregisterForSceneEvents(); + } + else + { + RegisterForSceneEvents(); + } } #endregion // Vehicle parameter setting - public void Refresh() + // BSActor.Refresh() + public override void Refresh() { // If asking for a refresh, reset the physical parameters before the next simulation step. - PhysicsScene.PostTaintObject("BSDynamics.Refresh", Prim.LocalID, delegate() + PhysicsScene.PostTaintObject("BSDynamics.Refresh", ControllingPrim.LocalID, delegate() { SetPhysicalParameters(); }); @@ -597,49 +609,90 @@ namespace OpenSim.Region.Physics.BulletSPlugin if (IsActive) { // Remember the mass so we don't have to fetch it every step - m_vehicleMass = Prim.TotalMass; + m_vehicleMass = ControllingPrim.TotalMass; // Friction affects are handled by this vehicle code - PhysicsScene.PE.SetFriction(Prim.PhysBody, BSParam.VehicleFriction); - PhysicsScene.PE.SetRestitution(Prim.PhysBody, BSParam.VehicleRestitution); + PhysicsScene.PE.SetFriction(ControllingPrim.PhysBody, BSParam.VehicleFriction); + PhysicsScene.PE.SetRestitution(ControllingPrim.PhysBody, BSParam.VehicleRestitution); // Moderate angular movement introduced by Bullet. // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle. // Maybe compute linear and angular factor and damping from params. - PhysicsScene.PE.SetAngularDamping(Prim.PhysBody, BSParam.VehicleAngularDamping); - PhysicsScene.PE.SetLinearFactor(Prim.PhysBody, BSParam.VehicleLinearFactor); - PhysicsScene.PE.SetAngularFactorV(Prim.PhysBody, BSParam.VehicleAngularFactor); + PhysicsScene.PE.SetAngularDamping(ControllingPrim.PhysBody, BSParam.VehicleAngularDamping); + PhysicsScene.PE.SetLinearFactor(ControllingPrim.PhysBody, BSParam.VehicleLinearFactor); + PhysicsScene.PE.SetAngularFactorV(ControllingPrim.PhysBody, BSParam.VehicleAngularFactor); // Vehicles report collision events so we know when it's on the ground - PhysicsScene.PE.AddToCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); + PhysicsScene.PE.AddToCollisionFlags(ControllingPrim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); - Prim.Inertia = PhysicsScene.PE.CalculateLocalInertia(Prim.PhysShape, m_vehicleMass); - PhysicsScene.PE.SetMassProps(Prim.PhysBody, m_vehicleMass, Prim.Inertia); - PhysicsScene.PE.UpdateInertiaTensor(Prim.PhysBody); + ControllingPrim.Inertia = PhysicsScene.PE.CalculateLocalInertia(ControllingPrim.PhysShape, m_vehicleMass); + PhysicsScene.PE.SetMassProps(ControllingPrim.PhysBody, m_vehicleMass, ControllingPrim.Inertia); + PhysicsScene.PE.UpdateInertiaTensor(ControllingPrim.PhysBody); // Set the gravity for the vehicle depending on the buoyancy // TODO: what should be done if prim and vehicle buoyancy differ? - m_VehicleGravity = Prim.ComputeGravity(m_VehicleBuoyancy); + m_VehicleGravity = ControllingPrim.ComputeGravity(m_VehicleBuoyancy); // The actual vehicle gravity is set to zero in Bullet so we can do all the application of same. - PhysicsScene.PE.SetGravity(Prim.PhysBody, Vector3.Zero); + PhysicsScene.PE.SetGravity(ControllingPrim.PhysBody, Vector3.Zero); VDetailLog("{0},BSDynamics.SetPhysicalParameters,mass={1},inert={2},vehGrav={3},aDamp={4},frict={5},rest={6},lFact={7},aFact={8}", - Prim.LocalID, m_vehicleMass, Prim.Inertia, m_VehicleGravity, + ControllingPrim.LocalID, m_vehicleMass, ControllingPrim.Inertia, m_VehicleGravity, BSParam.VehicleAngularDamping, BSParam.VehicleFriction, BSParam.VehicleRestitution, BSParam.VehicleLinearFactor, BSParam.VehicleAngularFactor ); } else { - if (Prim.PhysBody.HasPhysicalBody) - PhysicsScene.PE.RemoveFromCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); + if (ControllingPrim.PhysBody.HasPhysicalBody) + PhysicsScene.PE.RemoveFromCollisionFlags(ControllingPrim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); } } - public bool RemoveBodyDependencies(BSPhysObject prim) + // BSActor.RemoveBodyDependencies + public override void RemoveBodyDependencies() { Refresh(); - return IsActive; + } + + // BSActor.Release() + public override void Dispose() + { + UnregisterForSceneEvents(); + Type = Vehicle.TYPE_NONE; + Enabled = false; + return; + } + + private void RegisterForSceneEvents() + { + if (!m_haveRegisteredForSceneEvents) + { + PhysicsScene.BeforeStep += this.Step; + PhysicsScene.AfterStep += this.PostStep; + ControllingPrim.OnPreUpdateProperty += this.PreUpdateProperty; + m_haveRegisteredForSceneEvents = true; + } + } + + private void UnregisterForSceneEvents() + { + if (m_haveRegisteredForSceneEvents) + { + PhysicsScene.BeforeStep -= this.Step; + PhysicsScene.AfterStep -= this.PostStep; + ControllingPrim.OnPreUpdateProperty -= this.PreUpdateProperty; + m_haveRegisteredForSceneEvents = false; + } + } + + private void PreUpdateProperty(ref EntityProperties entprop) + { + // A temporary kludge to suppress the rotational effects introduced on vehicles by Bullet + // TODO: handle physics introduced by Bullet with computed vehicle physics. + if (IsActive) + { + entprop.RotationalVelocity = Vector3.Zero; + } } #region Known vehicle value functions @@ -686,14 +739,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin if (m_knownChanged != 0) { if ((m_knownChanged & m_knownChangedPosition) != 0) - Prim.ForcePosition = m_knownPosition; + ControllingPrim.ForcePosition = m_knownPosition; if ((m_knownChanged & m_knownChangedOrientation) != 0) - Prim.ForceOrientation = m_knownOrientation; + ControllingPrim.ForceOrientation = m_knownOrientation; if ((m_knownChanged & m_knownChangedVelocity) != 0) { - Prim.ForceVelocity = m_knownVelocity; + ControllingPrim.ForceVelocity = m_knownVelocity; // Fake out Bullet by making it think the velocity is the same as last time. // Bullet does a bunch of smoothing for changing parameters. // Since the vehicle is demanding this setting, we override Bullet's smoothing @@ -702,28 +755,28 @@ namespace OpenSim.Region.Physics.BulletSPlugin } if ((m_knownChanged & m_knownChangedForce) != 0) - Prim.AddForce((Vector3)m_knownForce, false /*pushForce*/, true /*inTaintTime*/); + ControllingPrim.AddForce((Vector3)m_knownForce, false /*pushForce*/, true /*inTaintTime*/); if ((m_knownChanged & m_knownChangedForceImpulse) != 0) - Prim.AddForceImpulse((Vector3)m_knownForceImpulse, false /*pushforce*/, true /*inTaintTime*/); + ControllingPrim.AddForceImpulse((Vector3)m_knownForceImpulse, false /*pushforce*/, true /*inTaintTime*/); if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0) { - Prim.ForceRotationalVelocity = m_knownRotationalVelocity; + ControllingPrim.ForceRotationalVelocity = m_knownRotationalVelocity; // PhysicsScene.PE.SetInterpolationAngularVelocity(Prim.PhysBody, m_knownRotationalVelocity); } if ((m_knownChanged & m_knownChangedRotationalImpulse) != 0) - Prim.ApplyTorqueImpulse((Vector3)m_knownRotationalImpulse, true /*inTaintTime*/); + ControllingPrim.ApplyTorqueImpulse((Vector3)m_knownRotationalImpulse, true /*inTaintTime*/); if ((m_knownChanged & m_knownChangedRotationalForce) != 0) { - Prim.AddAngularForce((Vector3)m_knownRotationalForce, false /*pushForce*/, true /*inTaintTime*/); + ControllingPrim.AddAngularForce((Vector3)m_knownRotationalForce, false /*pushForce*/, true /*inTaintTime*/); } // If we set one of the values (ie, the physics engine didn't do it) we must force // an UpdateProperties event to send the changes up to the simulator. - PhysicsScene.PE.PushUpdate(Prim.PhysBody); + PhysicsScene.PE.PushUpdate(ControllingPrim.PhysBody); } m_knownChanged = 0; } @@ -736,7 +789,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin if ((m_knownHas & m_knownChangedTerrainHeight) == 0 || pos != lastRememberedHeightPos) { lastRememberedHeightPos = pos; - m_knownTerrainHeight = Prim.PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos); + m_knownTerrainHeight = ControllingPrim.PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos); m_knownHas |= m_knownChangedTerrainHeight; } return m_knownTerrainHeight; @@ -748,7 +801,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin { if ((m_knownHas & m_knownChangedWaterLevel) == 0) { - m_knownWaterLevel = Prim.PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(pos); + m_knownWaterLevel = ControllingPrim.PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(pos); m_knownHas |= m_knownChangedWaterLevel; } return (float)m_knownWaterLevel; @@ -760,7 +813,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin { if ((m_knownHas & m_knownChangedPosition) == 0) { - m_knownPosition = Prim.ForcePosition; + m_knownPosition = ControllingPrim.ForcePosition; m_knownHas |= m_knownChangedPosition; } return m_knownPosition; @@ -779,7 +832,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin { if ((m_knownHas & m_knownChangedOrientation) == 0) { - m_knownOrientation = Prim.ForceOrientation; + m_knownOrientation = ControllingPrim.ForceOrientation; m_knownHas |= m_knownChangedOrientation; } return m_knownOrientation; @@ -798,7 +851,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin { if ((m_knownHas & m_knownChangedVelocity) == 0) { - m_knownVelocity = Prim.ForceVelocity; + m_knownVelocity = ControllingPrim.ForceVelocity; m_knownHas |= m_knownChangedVelocity; } return m_knownVelocity; @@ -839,7 +892,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin { if ((m_knownHas & m_knownChangedRotationalVelocity) == 0) { - m_knownRotationalVelocity = Prim.ForceRotationalVelocity; + m_knownRotationalVelocity = ControllingPrim.ForceRotationalVelocity; m_knownHas |= m_knownChangedRotationalVelocity; } return (Vector3)m_knownRotationalVelocity; @@ -915,10 +968,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin PushKnownChanged(); if (PhysicsScene.VehiclePhysicalLoggingEnabled) - PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody); + PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, ControllingPrim.PhysBody); VDetailLog("{0},BSDynamics.Step,done,pos={1}, force={2},velocity={3},angvel={4}", - Prim.LocalID, VehiclePosition, m_knownForce, VehicleVelocity, VehicleRotationalVelocity); + ControllingPrim.LocalID, VehiclePosition, m_knownForce, VehicleVelocity, VehicleRotationalVelocity); } // Called after the simulation step @@ -927,7 +980,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin if (!IsActive) return; if (PhysicsScene.VehiclePhysicalLoggingEnabled) - PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody); + PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, ControllingPrim.PhysBody); } // Apply the effect of the linear motor and other linear motions (like hover and float). @@ -967,12 +1020,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin VehicleVelocity /= VehicleVelocity.Length(); VehicleVelocity *= BSParam.VehicleMaxLinearVelocity; VDetailLog("{0}, MoveLinear,clampMax,origVelW={1},lenSq={2},maxVelSq={3},,newVelW={4}", - Prim.LocalID, origVelW, newVelocityLengthSq, BSParam.VehicleMaxLinearVelocitySquared, VehicleVelocity); + ControllingPrim.LocalID, origVelW, newVelocityLengthSq, BSParam.VehicleMaxLinearVelocitySquared, VehicleVelocity); } else if (newVelocityLengthSq < 0.001f) VehicleVelocity = Vector3.Zero; - VDetailLog("{0}, MoveLinear,done,isColl={1},newVel={2}", Prim.LocalID, Prim.IsColliding, VehicleVelocity ); + VDetailLog("{0}, MoveLinear,done,isColl={1},newVel={2}", ControllingPrim.LocalID, ControllingPrim.IsColliding, VehicleVelocity ); } // end MoveLinear() @@ -997,7 +1050,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin VehicleVelocity += linearMotorVelocityW; VDetailLog("{0}, MoveLinear,velocity,origVelW={1},velV={2},correctV={3},correctW={4},newVelW={5}", - Prim.LocalID, origVelW, currentVelV, linearMotorCorrectionV, linearMotorVelocityW, VehicleVelocity); + ControllingPrim.LocalID, origVelW, currentVelV, linearMotorCorrectionV, linearMotorVelocityW, VehicleVelocity); } public void ComputeLinearTerrainHeightCorrection(float pTimestep) @@ -1011,7 +1064,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin newPosition.Z = GetTerrainHeight(VehiclePosition) + 1f; VehiclePosition = newPosition; VDetailLog("{0}, MoveLinear,terrainHeight,terrainHeight={1},pos={2}", - Prim.LocalID, GetTerrainHeight(VehiclePosition), VehiclePosition); + ControllingPrim.LocalID, GetTerrainHeight(VehiclePosition), VehiclePosition); } } @@ -1050,7 +1103,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin pos.Z = m_VhoverTargetHeight; VehiclePosition = pos; - VDetailLog("{0}, MoveLinear,hover,pos={1},lockHoverHeight", Prim.LocalID, pos); + VDetailLog("{0}, MoveLinear,hover,pos={1},lockHoverHeight", ControllingPrim.LocalID, pos); } } else @@ -1079,7 +1132,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin */ VDetailLog("{0}, MoveLinear,hover,pos={1},eff={2},hoverTS={3},height={4},target={5},err={6},corr={7}", - Prim.LocalID, VehiclePosition, m_VhoverEfficiency, + ControllingPrim.LocalID, VehiclePosition, m_VhoverEfficiency, m_VhoverTimescale, m_VhoverHeight, m_VhoverTargetHeight, verticalError, verticalCorrection); } @@ -1124,7 +1177,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin { VehiclePosition = pos; VDetailLog("{0}, MoveLinear,blockingEndPoint,block={1},origPos={2},pos={3}", - Prim.LocalID, m_BlockingEndPoint, posChange, pos); + ControllingPrim.LocalID, m_BlockingEndPoint, posChange, pos); } } return changed; @@ -1164,7 +1217,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Another approach is to measure if we're going up. If going up and not colliding, // the vehicle is in the air. Fix that by pushing down. - if (!Prim.IsColliding && VehicleVelocity.Z > 0.1) + if (!ControllingPrim.IsColliding && VehicleVelocity.Z > 0.1) { // Get rid of any of the velocity vector that is pushing us up. float upVelocity = VehicleVelocity.Z; @@ -1186,7 +1239,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin } */ VDetailLog("{0}, MoveLinear,limitMotorUp,collide={1},upVel={2},newVel={3}", - Prim.LocalID, Prim.IsColliding, upVelocity, VehicleVelocity); + ControllingPrim.LocalID, ControllingPrim.IsColliding, upVelocity, VehicleVelocity); } } } @@ -1196,14 +1249,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin Vector3 appliedGravity = m_VehicleGravity * m_vehicleMass; // Hack to reduce downward force if the vehicle is probably sitting on the ground - if (Prim.IsColliding && IsGroundVehicle) + if (ControllingPrim.IsColliding && IsGroundVehicle) appliedGravity *= BSParam.VehicleGroundGravityFudge; VehicleAddForce(appliedGravity); VDetailLog("{0}, MoveLinear,applyGravity,vehGrav={1},collid={2},fudge={3},mass={4},appliedForce={3}", - Prim.LocalID, m_VehicleGravity, - Prim.IsColliding, BSParam.VehicleGroundGravityFudge, m_vehicleMass, appliedGravity); + ControllingPrim.LocalID, m_VehicleGravity, + ControllingPrim.IsColliding, BSParam.VehicleGroundGravityFudge, m_vehicleMass, appliedGravity); } // ======================================================================= @@ -1227,11 +1280,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin { // The vehicle is not adding anything angular wise. VehicleRotationalVelocity = Vector3.Zero; - VDetailLog("{0}, MoveAngular,done,zero", Prim.LocalID); + VDetailLog("{0}, MoveAngular,done,zero", ControllingPrim.LocalID); } else { - VDetailLog("{0}, MoveAngular,done,nonZero,angVel={1}", Prim.LocalID, VehicleRotationalVelocity); + VDetailLog("{0}, MoveAngular,done,nonZero,angVel={1}", ControllingPrim.LocalID, VehicleRotationalVelocity); } // ================================================================== @@ -1262,7 +1315,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin torqueFromOffset.Z = 0; VehicleAddAngularForce(torqueFromOffset * m_vehicleMass); - VDetailLog("{0}, BSDynamic.MoveAngular,motorOffset,applyTorqueImpulse={1}", Prim.LocalID, torqueFromOffset); + VDetailLog("{0}, BSDynamic.MoveAngular,motorOffset,applyTorqueImpulse={1}", ControllingPrim.LocalID, torqueFromOffset); } } @@ -1288,7 +1341,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin // } VehicleRotationalVelocity += angularMotorContributionV * VehicleOrientation; - VDetailLog("{0}, MoveAngular,angularTurning,angularMotorContrib={1}", Prim.LocalID, angularMotorContributionV); + VDetailLog("{0}, MoveAngular,angularTurning,angularMotorContrib={1}", ControllingPrim.LocalID, angularMotorContributionV); } // From http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial: @@ -1334,7 +1387,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin VehicleRotationalVelocity += vertContributionV; VDetailLog("{0}, MoveAngular,verticalAttraction,diffAxis={1},diffAng={2},corrRot={3},contrib={4}", - Prim.LocalID, + ControllingPrim.LocalID, differenceAxis, differenceAngle, correctionRotation, @@ -1433,9 +1486,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin VehicleRotationalVelocity += deflectContributionV * VehicleOrientation; VDetailLog("{0}, MoveAngular,Deflection,movingDir={1},pointingDir={2},deflectError={3},ret={4}", - Prim.LocalID, movingDirection, pointingDirection, deflectionError, deflectContributionV); + ControllingPrim.LocalID, movingDirection, pointingDirection, deflectionError, deflectContributionV); VDetailLog("{0}, MoveAngular,Deflection,fwdSpd={1},defEff={2},defTS={3}", - Prim.LocalID, VehicleForwardSpeed, m_angularDeflectionEfficiency, m_angularDeflectionTimescale); + ControllingPrim.LocalID, VehicleForwardSpeed, m_angularDeflectionEfficiency, m_angularDeflectionTimescale); } } @@ -1501,7 +1554,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin VDetailLog("{0}, MoveAngular,Banking,rollComp={1},speed={2},rollComp={3},yAng={4},mYAng={5},ret={6}", - Prim.LocalID, rollComponents, VehicleForwardSpeed, rollComponents, yawAngle, mixedYawAngle, bankingContributionV); + ControllingPrim.LocalID, rollComponents, VehicleForwardSpeed, rollComponents, yawAngle, mixedYawAngle, bankingContributionV); } } @@ -1540,7 +1593,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin if (rotq != m_rot) { VehicleOrientation = m_rot; - VDetailLog("{0}, LimitRotation,done,orig={1},new={2}", Prim.LocalID, rotq, m_rot); + VDetailLog("{0}, LimitRotation,done,orig={1},new={2}", ControllingPrim.LocalID, rotq, m_rot); } } @@ -1554,8 +1607,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Invoke the detailed logger and output something if it's enabled. private void VDetailLog(string msg, params Object[] args) { - if (Prim.PhysicsScene.VehicleLoggingEnabled) - Prim.PhysicsScene.DetailLog(msg, args); + if (ControllingPrim.PhysicsScene.VehicleLoggingEnabled) + ControllingPrim.PhysicsScene.DetailLog(msg, args); } } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index cba2646..98ea833 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -187,7 +187,7 @@ public abstract class BSPhysObject : PhysicsActor Friction = matAttrib.friction; Restitution = matAttrib.restitution; Density = matAttrib.density / BSParam.DensityScaleFactor; - DetailLog("{0},{1}.SetMaterial,Mat={2},frict={3},rest={4},den={5}", LocalID, TypeName, Material, Friction, Restitution, Density); + // DetailLog("{0},{1}.SetMaterial,Mat={2},frict={3},rest={4},den={5}", LocalID, TypeName, Material, Friction, Restitution, Density); } // Stop all physical motion. diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 68a6c41..ec78fdc 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -72,7 +72,8 @@ public class BSPrim : BSPhysObject private int CrossingFailures { get; set; } - public BSDynamics VehicleController { get; private set; } + public BSDynamics VehicleActor; + public string VehicleActorName = "BasicVehicle"; private BSVMotor _targetMotor; private OMV.Vector3 _PIDTarget; @@ -100,11 +101,12 @@ public class BSPrim : BSPhysObject _isPhysical = pisPhysical; _isVolumeDetect = false; - VehicleController = new BSDynamics(PhysicsScene, this); // add vehicleness + VehicleActor = new BSDynamics(PhysicsScene, this, VehicleActorName); + PhysicalActors.Add(VehicleActorName, VehicleActor); _mass = CalculateMass(); - DetailLog("{0},BSPrim.constructor,call", LocalID); + // DetailLog("{0},BSPrim.constructor,call", LocalID); // do the actual object creation at taint time PhysicsScene.TaintedObject("BSPrim.create", delegate() { @@ -272,6 +274,7 @@ public class BSPrim : BSPhysObject { PhysicsScene.TaintedObject("BSPrim.LockAngularMotion", delegate() { + DetailLog("{0},BSPrim.LockAngularMotion,taint,registeringLockAxisActor", LocalID); // If there is not already an axis locker, make one if (!PhysicalActors.HasActor(LockedAxisActorName)) { @@ -537,7 +540,7 @@ public class BSPrim : BSPhysObject public override int VehicleType { get { - return (int)VehicleController.Type; // if we are a vehicle, return that type + return (int)VehicleActor.Type; // if we are a vehicle, return that type } set { Vehicle type = (Vehicle)value; @@ -546,20 +549,8 @@ public class BSPrim : BSPhysObject { // Done at taint time so we're sure the physics engine is not using the variables // Vehicle code changes the parameters for this vehicle type. - VehicleController.ProcessTypeChange(type); + VehicleActor.ProcessTypeChange(type); ActivateIfPhysical(false); - - // If an active vehicle, register the vehicle code to be called before each step - if (VehicleController.Type == Vehicle.TYPE_NONE) - { - UnRegisterPreStepAction("BSPrim.Vehicle", LocalID); - UnRegisterPostStepAction("BSPrim.Vehicle", LocalID); - } - else - { - RegisterPreStepAction("BSPrim.Vehicle", LocalID, VehicleController.Step); - RegisterPostStepAction("BSPrim.Vehicle", LocalID, VehicleController.PostStep); - } }); } } @@ -567,7 +558,7 @@ public class BSPrim : BSPhysObject { PhysicsScene.TaintedObject("BSPrim.VehicleFloatParam", delegate() { - VehicleController.ProcessFloatVehicleParam((Vehicle)param, value); + VehicleActor.ProcessFloatVehicleParam((Vehicle)param, value); ActivateIfPhysical(false); }); } @@ -575,7 +566,7 @@ public class BSPrim : BSPhysObject { PhysicsScene.TaintedObject("BSPrim.VehicleVectorParam", delegate() { - VehicleController.ProcessVectorVehicleParam((Vehicle)param, value); + VehicleActor.ProcessVectorVehicleParam((Vehicle)param, value); ActivateIfPhysical(false); }); } @@ -583,7 +574,7 @@ public class BSPrim : BSPhysObject { PhysicsScene.TaintedObject("BSPrim.VehicleRotationParam", delegate() { - VehicleController.ProcessRotationVehicleParam((Vehicle)param, rotation); + VehicleActor.ProcessRotationVehicleParam((Vehicle)param, rotation); ActivateIfPhysical(false); }); } @@ -591,7 +582,7 @@ public class BSPrim : BSPhysObject { PhysicsScene.TaintedObject("BSPrim.VehicleFlags", delegate() { - VehicleController.ProcessVehicleFlags(param, remove); + VehicleActor.ProcessVehicleFlags(param, remove); }); } @@ -848,7 +839,7 @@ public class BSPrim : BSPhysObject MakeDynamic(IsStatic); // Update vehicle specific parameters (after MakeDynamic() so can change physical parameters) - VehicleController.Refresh(); + VehicleActor.Refresh(); PhysicalActors.Refresh(); // Arrange for collision events if the simulator wants them @@ -1655,9 +1646,9 @@ public class BSPrim : BSPhysObject volume *= (profileEnd - profileBegin); returnMass = Density * BSParam.DensityScaleFactor * volume; - DetailLog("{0},BSPrim.CalculateMass,den={1},vol={2},mass={3}", LocalID, Density, volume, returnMass); returnMass = Util.Clamp(returnMass, BSParam.MinimumObjectMass, BSParam.MaximumObjectMass); + // DetailLog("{0},BSPrim.CalculateMass,den={1},vol={2},mass={3}", LocalID, Density, volume, returnMass); return returnMass; }// end CalculateMass @@ -1686,7 +1677,7 @@ public class BSPrim : BSPhysObject protected virtual void RemoveBodyDependencies() { - VehicleController.RemoveBodyDependencies(this); + VehicleActor.RemoveBodyDependencies(); PhysicalActors.RemoveBodyDependencies(); } @@ -1696,13 +1687,6 @@ public class BSPrim : BSPhysObject { TriggerPreUpdatePropertyAction(ref entprop); - // A temporary kludge to suppress the rotational effects introduced on vehicles by Bullet - // TODO: handle physics introduced by Bullet with computed vehicle physics. - if (VehicleController.IsActive) - { - entprop.RotationalVelocity = OMV.Vector3.Zero; - } - // DetailLog("{0},BSPrim.UpdateProperties,entry,entprop={1}", LocalID, entprop); // DEBUG DEBUG // Assign directly to the local variables so the normal set actions do not happen diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index e6aefd5..9818b05 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -463,7 +463,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters if (!m_initialized) return null; - DetailLog("{0},BSScene.AddPrimShape,call", localID); + // DetailLog("{0},BSScene.AddPrimShape,call", localID); BSPhysObject prim = new BSPrimLinkable(localID, primName, this, position, size, rotation, pbs, isPhysical); lock (PhysObjects) PhysObjects.Add(localID, prim); diff --git a/OpenSim/Region/Physics/BulletSPlugin/Tests/BasicVehicles.cs b/OpenSim/Region/Physics/BulletSPlugin/Tests/BasicVehicles.cs index 33232bd..b040e21 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/Tests/BasicVehicles.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/Tests/BasicVehicles.cs @@ -114,9 +114,9 @@ public class BasicVehicles : OpenSimTestCase // Instead the appropriate values are set and calls are made just the parts of the // controller we want to exercise. Stepping the physics engine then applies // the actions of that one feature. - TestVehicle.VehicleController.ProcessFloatVehicleParam(Vehicle.VERTICAL_ATTRACTION_EFFICIENCY, efficiency); - TestVehicle.VehicleController.ProcessFloatVehicleParam(Vehicle.VERTICAL_ATTRACTION_TIMESCALE, timeScale); - TestVehicle.VehicleController.enableAngularVerticalAttraction = true; + TestVehicle.VehicleActor.ProcessFloatVehicleParam(Vehicle.VERTICAL_ATTRACTION_EFFICIENCY, efficiency); + TestVehicle.VehicleActor.ProcessFloatVehicleParam(Vehicle.VERTICAL_ATTRACTION_TIMESCALE, timeScale); + TestVehicle.VehicleActor.enableAngularVerticalAttraction = true; TestVehicle.IsPhysical = true; PhysicsScene.ProcessTaints(); @@ -124,9 +124,9 @@ public class BasicVehicles : OpenSimTestCase // Step the simulator a bunch of times and vertical attraction should orient the vehicle up for (int ii = 0; ii < simSteps; ii++) { - TestVehicle.VehicleController.ForgetKnownVehicleProperties(); - TestVehicle.VehicleController.ComputeAngularVerticalAttraction(); - TestVehicle.VehicleController.PushKnownChanged(); + TestVehicle.VehicleActor.ForgetKnownVehicleProperties(); + TestVehicle.VehicleActor.ComputeAngularVerticalAttraction(); + TestVehicle.VehicleActor.PushKnownChanged(); PhysicsScene.Simulate(simulationTimeStep); } -- 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 +++++++++++---------- OpenSim/Region/Physics/BulletSPlugin/BSActors.cs | 254 +++++++-------- 2 files changed, 302 insertions(+), 291 deletions(-) (limited to 'OpenSim') 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); + } + } +} +} diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs index b9b5ce1..3163440 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs @@ -1,123 +1,131 @@ -/* - * 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.Text; - -namespace OpenSim.Region.Physics.BulletSPlugin -{ -public class BSActorCollection -{ - private BSScene PhysicsScene { get; set; } - private Dictionary m_actors; - - public BSActorCollection(BSScene physicsScene) - { - PhysicsScene = physicsScene; - m_actors = new Dictionary(); - } - public void Add(string name, BSActor actor) - { - m_actors[name] = actor; - } - public bool RemoveAndRelease(string name) - { - bool ret = false; - if (m_actors.ContainsKey(name)) - { - BSActor beingRemoved = m_actors[name]; - beingRemoved.Release(); - m_actors.Remove(name); - ret = true; - } - return ret; - } - public void Clear() - { - Release(); - m_actors.Clear(); - } - public bool HasActor(string name) - { - return m_actors.ContainsKey(name); - } - public void ForEachActor(Action act) - { - foreach (KeyValuePair kvp in m_actors) - act(kvp.Value); - } - - public void Release() - { - ForEachActor(a => a.Release()); - } - public void Refresh() - { - ForEachActor(a => a.Refresh()); - } - public void RemoveBodyDependencies() - { - ForEachActor(a => a.RemoveBodyDependencies()); - } -} - -// ============================================================================= -public abstract class BSActor -{ - protected BSScene PhysicsScene { get; private set; } - protected BSPhysObject Prim { get; private set; } - protected bool Enabled { get; set; } - public string ActorName { get; private set; } - - public BSActor(BSScene physicsScene, BSPhysObject pObj, string actorName) - { - PhysicsScene = physicsScene; - Prim = pObj; - ActorName = actorName; - Enabled = true; - } - - // Return 'true' if activily updating the prim - public virtual bool isActive - { - get { return Enabled; } - } - // Turn the actor on an off. - public virtual void Enable(bool setEnabled) - { - Enabled = setEnabled; - } - // Release any connections and resources used by the actor. - public abstract void Release(); - // Called when physical parameters (properties set in Bullet) need to be re-applied. - public abstract void Refresh(); - // 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. - public abstract void RemoveBodyDependencies(); - -} -} +/* + * 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.Text; + +namespace OpenSim.Region.Physics.BulletSPlugin +{ +public class BSActorCollection +{ + private BSScene PhysicsScene { get; set; } + private Dictionary m_actors; + + public BSActorCollection(BSScene physicsScene) + { + PhysicsScene = physicsScene; + m_actors = new Dictionary(); + } + public void Add(string name, BSActor actor) + { + m_actors[name] = actor; + } + public bool RemoveAndRelease(string name) + { + bool ret = false; + if (m_actors.ContainsKey(name)) + { + BSActor beingRemoved = m_actors[name]; + beingRemoved.Dispose(); + m_actors.Remove(name); + ret = true; + } + return ret; + } + public void Clear() + { + Release(); + m_actors.Clear(); + } + public bool HasActor(string name) + { + return m_actors.ContainsKey(name); + } + public void ForEachActor(Action act) + { + foreach (KeyValuePair kvp in m_actors) + act(kvp.Value); + } + + public void Release() + { + ForEachActor(a => a.Dispose()); + } + public void Refresh() + { + ForEachActor(a => a.Refresh()); + } + public void RemoveBodyDependencies() + { + ForEachActor(a => a.RemoveBodyDependencies()); + } +} + +// ============================================================================= +/// +/// Each physical object can have 'actors' who are pushing the object around. +/// This can be used for hover, locking axis, making vehicles, etc. +/// Each physical object can have multiple actors acting on it. +/// +/// An actor usually registers itself with physics scene events (pre-step action) +/// and modifies the parameters on the host physical object. +/// +public abstract class BSActor +{ + protected BSScene PhysicsScene { get; private set; } + protected BSPhysObject Prim { get; private set; } + protected bool Enabled { get; set; } + public string ActorName { get; private set; } + + public BSActor(BSScene physicsScene, BSPhysObject pObj, string actorName) + { + PhysicsScene = physicsScene; + Prim = pObj; + ActorName = actorName; + Enabled = true; + } + + // Return 'true' if activily updating the prim + public virtual bool isActive + { + get { return Enabled; } + } + // Turn the actor on an off. + public virtual void Enable(bool setEnabled) + { + Enabled = setEnabled; + } + // Release any connections and resources used by the actor. + public abstract void Dispose(); + // Called when physical parameters (properties set in Bullet) need to be re-applied. + public abstract void Refresh(); + // 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. + public abstract void RemoveBodyDependencies(); + +} +} -- cgit v1.1 From 7d50015a74da4c0c4c5bf9777d1d328a4ee9b7b0 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 31 Mar 2013 20:37:02 -0700 Subject: BulletSim: start the renaming of local variables to m_ form to match the OpenSim coding conventions. --- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 46 +++++++++++----------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 8b5da0d..0fd1f73 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -565,12 +565,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_linearMotor = new BSVMotor("LinearMotor", m_linearMotorTimescale, m_linearMotorDecayTimescale, m_linearFrictionTimescale, 1f); - m_linearMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging) + m_linearMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG DEBUG (enables detail logging) m_angularMotor = new BSVMotor("AngularMotor", m_angularMotorTimescale, m_angularMotorDecayTimescale, m_angularFrictionTimescale, 1f); - m_angularMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG DEBUG (enables detail logging) + m_angularMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG DEBUG (enables detail logging) /* Not implemented m_verticalAttractionMotor = new BSVMotor("VerticalAttraction", m_verticalAttractionTimescale, @@ -596,7 +596,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin public override void Refresh() { // If asking for a refresh, reset the physical parameters before the next simulation step. - PhysicsScene.PostTaintObject("BSDynamics.Refresh", ControllingPrim.LocalID, delegate() + m_physicsScene.PostTaintObject("BSDynamics.Refresh", ControllingPrim.LocalID, delegate() { SetPhysicalParameters(); }); @@ -612,28 +612,28 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_vehicleMass = ControllingPrim.TotalMass; // Friction affects are handled by this vehicle code - PhysicsScene.PE.SetFriction(ControllingPrim.PhysBody, BSParam.VehicleFriction); - PhysicsScene.PE.SetRestitution(ControllingPrim.PhysBody, BSParam.VehicleRestitution); + m_physicsScene.PE.SetFriction(ControllingPrim.PhysBody, BSParam.VehicleFriction); + m_physicsScene.PE.SetRestitution(ControllingPrim.PhysBody, BSParam.VehicleRestitution); // Moderate angular movement introduced by Bullet. // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle. // Maybe compute linear and angular factor and damping from params. - PhysicsScene.PE.SetAngularDamping(ControllingPrim.PhysBody, BSParam.VehicleAngularDamping); - PhysicsScene.PE.SetLinearFactor(ControllingPrim.PhysBody, BSParam.VehicleLinearFactor); - PhysicsScene.PE.SetAngularFactorV(ControllingPrim.PhysBody, BSParam.VehicleAngularFactor); + m_physicsScene.PE.SetAngularDamping(ControllingPrim.PhysBody, BSParam.VehicleAngularDamping); + m_physicsScene.PE.SetLinearFactor(ControllingPrim.PhysBody, BSParam.VehicleLinearFactor); + m_physicsScene.PE.SetAngularFactorV(ControllingPrim.PhysBody, BSParam.VehicleAngularFactor); // Vehicles report collision events so we know when it's on the ground - PhysicsScene.PE.AddToCollisionFlags(ControllingPrim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); + m_physicsScene.PE.AddToCollisionFlags(ControllingPrim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); - ControllingPrim.Inertia = PhysicsScene.PE.CalculateLocalInertia(ControllingPrim.PhysShape, m_vehicleMass); - PhysicsScene.PE.SetMassProps(ControllingPrim.PhysBody, m_vehicleMass, ControllingPrim.Inertia); - PhysicsScene.PE.UpdateInertiaTensor(ControllingPrim.PhysBody); + ControllingPrim.Inertia = m_physicsScene.PE.CalculateLocalInertia(ControllingPrim.PhysShape, m_vehicleMass); + m_physicsScene.PE.SetMassProps(ControllingPrim.PhysBody, m_vehicleMass, ControllingPrim.Inertia); + m_physicsScene.PE.UpdateInertiaTensor(ControllingPrim.PhysBody); // Set the gravity for the vehicle depending on the buoyancy // TODO: what should be done if prim and vehicle buoyancy differ? m_VehicleGravity = ControllingPrim.ComputeGravity(m_VehicleBuoyancy); // The actual vehicle gravity is set to zero in Bullet so we can do all the application of same. - PhysicsScene.PE.SetGravity(ControllingPrim.PhysBody, Vector3.Zero); + m_physicsScene.PE.SetGravity(ControllingPrim.PhysBody, Vector3.Zero); VDetailLog("{0},BSDynamics.SetPhysicalParameters,mass={1},inert={2},vehGrav={3},aDamp={4},frict={5},rest={6},lFact={7},aFact={8}", ControllingPrim.LocalID, m_vehicleMass, ControllingPrim.Inertia, m_VehicleGravity, @@ -644,7 +644,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin else { if (ControllingPrim.PhysBody.HasPhysicalBody) - PhysicsScene.PE.RemoveFromCollisionFlags(ControllingPrim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); + m_physicsScene.PE.RemoveFromCollisionFlags(ControllingPrim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); } } @@ -667,8 +667,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin { if (!m_haveRegisteredForSceneEvents) { - PhysicsScene.BeforeStep += this.Step; - PhysicsScene.AfterStep += this.PostStep; + m_physicsScene.BeforeStep += this.Step; + m_physicsScene.AfterStep += this.PostStep; ControllingPrim.OnPreUpdateProperty += this.PreUpdateProperty; m_haveRegisteredForSceneEvents = true; } @@ -678,8 +678,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin { if (m_haveRegisteredForSceneEvents) { - PhysicsScene.BeforeStep -= this.Step; - PhysicsScene.AfterStep -= this.PostStep; + m_physicsScene.BeforeStep -= this.Step; + m_physicsScene.AfterStep -= this.PostStep; ControllingPrim.OnPreUpdateProperty -= this.PreUpdateProperty; m_haveRegisteredForSceneEvents = false; } @@ -776,7 +776,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin // If we set one of the values (ie, the physics engine didn't do it) we must force // an UpdateProperties event to send the changes up to the simulator. - PhysicsScene.PE.PushUpdate(ControllingPrim.PhysBody); + m_physicsScene.PE.PushUpdate(ControllingPrim.PhysBody); } m_knownChanged = 0; } @@ -967,8 +967,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin // for the physics engine to note the changes so an UpdateProperties event will happen. PushKnownChanged(); - if (PhysicsScene.VehiclePhysicalLoggingEnabled) - PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, ControllingPrim.PhysBody); + if (m_physicsScene.VehiclePhysicalLoggingEnabled) + m_physicsScene.PE.DumpRigidBody(m_physicsScene.World, ControllingPrim.PhysBody); VDetailLog("{0},BSDynamics.Step,done,pos={1}, force={2},velocity={3},angvel={4}", ControllingPrim.LocalID, VehiclePosition, m_knownForce, VehicleVelocity, VehicleRotationalVelocity); @@ -979,8 +979,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin { if (!IsActive) return; - if (PhysicsScene.VehiclePhysicalLoggingEnabled) - PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, ControllingPrim.PhysBody); + if (m_physicsScene.VehiclePhysicalLoggingEnabled) + m_physicsScene.PE.DumpRigidBody(m_physicsScene.World, ControllingPrim.PhysBody); } // Apply the effect of the linear motor and other linear motions (like hover and float). -- 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 ++++++++++++---------- OpenSim/Region/Physics/BulletSPlugin/BSActors.cs | 8 +-- .../Region/Physics/BulletSPlugin/BSConstraint.cs | 2 + .../Physics/BulletSPlugin/BSConstraint6Dof.cs | 4 +- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 2 +- 5 files changed, 43 insertions(+), 35 deletions(-) (limited to 'OpenSim') 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); } } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs index 3163440..5a19ba4 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs @@ -96,15 +96,15 @@ public class BSActorCollection /// public abstract class BSActor { - protected BSScene PhysicsScene { get; private set; } - protected BSPhysObject Prim { get; private set; } + protected BSScene m_physicsScene { get; private set; } + protected BSPhysObject m_controllingPrim { get; private set; } protected bool Enabled { get; set; } public string ActorName { get; private set; } public BSActor(BSScene physicsScene, BSPhysObject pObj, string actorName) { - PhysicsScene = physicsScene; - Prim = pObj; + m_physicsScene = physicsScene; + m_controllingPrim = pObj; ActorName = actorName; Enabled = true; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs index b813974..42b5c49 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs @@ -85,7 +85,9 @@ public abstract class BSConstraint : IDisposable { bool ret = false; if (m_enabled) + { ret = PhysicsScene.PE.SetAngularLimits(m_constraint, low, high); + } return ret; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs index 476a0e5..d0949f5 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs @@ -97,14 +97,14 @@ public sealed class BSConstraint6Dof : BSConstraint // A 6 Dof constraint that is fixed in the world and constrained to a on-the-fly created static object public BSConstraint6Dof(BulletWorld world, BulletBody obj1, Vector3 frameInBloc, Quaternion frameInBrot, - bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) + bool useLinearReferenceFrameB, bool disableCollisionsBetweenLinkedBodies) : base(world) { m_body1 = obj1; m_body2 = obj1; // Look out for confusion down the road m_constraint = PhysicsScene.PE.Create6DofConstraintFixed(m_world, m_body1, frameInBloc, frameInBrot, - useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); + useLinearReferenceFrameB, disableCollisionsBetweenLinkedBodies); m_enabled = true; world.physicsScene.DetailLog("{0},BS6DofConstraint,createFixed,wID={1},rID={2},rBody={3}", BSScene.DetailLogZero, world.worldID, obj1.ID, obj1.AddrString); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index ec78fdc..e56276a 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -274,10 +274,10 @@ public class BSPrim : BSPhysObject { PhysicsScene.TaintedObject("BSPrim.LockAngularMotion", delegate() { - DetailLog("{0},BSPrim.LockAngularMotion,taint,registeringLockAxisActor", LocalID); // If there is not already an axis locker, make one if (!PhysicalActors.HasActor(LockedAxisActorName)) { + DetailLog("{0},BSPrim.LockAngularMotion,taint,registeringLockAxisActor", LocalID); PhysicalActors.Add(LockedAxisActorName, new BSActorLockAxis(PhysicsScene, this, LockedAxisActorName)); } UpdatePhysicalParameters(); -- cgit v1.1 From 84eb25da23765b3a4f7ae5513e8a238680bb99f2 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 31 Mar 2013 22:16:34 -0700 Subject: BulletSim: stop an avatar from moving if standing on a stationary object. This will stop avatars from sliding down steep terrains or objects while still allowing an avatar to be moved if standing on a moving object. --- OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 90c2d9c..25be416 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -61,6 +61,7 @@ public sealed class BSCharacter : BSPhysObject private OMV.Vector3 _rotationalVelocity; private bool _kinematic; private float _buoyancy; + private bool _isStationaryStanding; // true is standing on a stationary object private BSVMotor _velocityMotor; @@ -84,6 +85,7 @@ public sealed class BSCharacter : BSPhysObject _buoyancy = ComputeBuoyancyFromFlying(isFlying); Friction = BSParam.AvatarStandingFriction; Density = BSParam.AvatarDensity / BSParam.DensityScaleFactor; + _isStationaryStanding = false; // Old versions of ScenePresence passed only the height. If width and/or depth are zero, // replace with the default values. @@ -208,6 +210,7 @@ public sealed class BSCharacter : BSPhysObject // The code below uses whether the collider is static or moving to decide whether to zero motion. _velocityMotor.Step(timeStep); + _isStationaryStanding = false; // If we're not supposed to be moving, make sure things are zero. if (_velocityMotor.ErrorIsZero() && _velocityMotor.TargetValue == OMV.Vector3.Zero) @@ -221,6 +224,7 @@ public sealed class BSCharacter : BSPhysObject if (!ColliderIsMoving) { DetailLog("{0},BSCharacter.MoveMotor,collidingWithStationary,zeroingMotion", LocalID); + _isStationaryStanding = true; ZeroMotion(true /* inTaintTime */); } @@ -882,7 +886,10 @@ public sealed class BSCharacter : BSPhysObject // the world that things have changed. public override void UpdateProperties(EntityProperties entprop) { - _position = entprop.Position; + // Don't change position if standing on a stationary object. + if (!_isStationaryStanding) + _position = entprop.Position; + _orientation = entprop.Rotation; // Smooth velocity. OpenSimulator is VERY sensitive to changes in velocity of the avatar -- cgit v1.1 From 4153cfbf14132931b981168b7b3e7c5b8d5be8b5 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 2 Apr 2013 00:45:29 +0100 Subject: Change recent MSSQL migrations to drop COLUMN from ALTER TABLE which is either not syntactical or unnecessary. May fix http://opensimulator.org/mantis/view.php?id=6593 --- OpenSim/Data/MSSQL/Resources/RegionStore.migrations | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Data/MSSQL/Resources/RegionStore.migrations b/OpenSim/Data/MSSQL/Resources/RegionStore.migrations index b84c2a4..4549801 100644 --- a/OpenSim/Data/MSSQL/Resources/RegionStore.migrations +++ b/OpenSim/Data/MSSQL/Resources/RegionStore.migrations @@ -1153,7 +1153,7 @@ COMMIT BEGIN TRANSACTION -ALTER TABLE prims ADD COLUMN DynAttrs TEXT; +ALTER TABLE prims ADD DynAttrs TEXT; COMMIT @@ -1161,10 +1161,10 @@ COMMIT BEGIN TRANSACTION -ALTER TABLE prims ADD COLUMN `PhysicsShapeType` tinyint(4) NOT NULL default '0'; -ALTER TABLE prims ADD COLUMN `Density` double NOT NULL default '1000'; -ALTER TABLE prims ADD COLUMN `GravityModifier` double NOT NULL default '1'; -ALTER TABLE prims ADD COLUMN `Friction` double NOT NULL default '0.6'; -ALTER TABLE prims ADD COLUMN `Restitution` double NOT NULL default '0.5'; +ALTER TABLE prims ADD `PhysicsShapeType` tinyint(4) NOT NULL default '0'; +ALTER TABLE prims ADD `Density` double NOT NULL default '1000'; +ALTER TABLE prims ADD `GravityModifier` double NOT NULL default '1'; +ALTER TABLE prims ADD `Friction` double NOT NULL default '0.6'; +ALTER TABLE prims ADD `Restitution` double NOT NULL default '0.5'; COMMIT -- cgit v1.1 From 0dce4964991c24f9ae47fe04f52a92dcfd22dc1b Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 2 Apr 2013 00:53:06 +0100 Subject: Fix what appears to be a bug in HGUserManagementModule where it enables on the base.Name rather than its own Name. --- .../CoreModules/Framework/UserManagement/HGUserManagementModule.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/HGUserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/HGUserManagementModule.cs index 4ef57fe..8ce20e9 100644 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/HGUserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/HGUserManagementModule.cs @@ -50,12 +50,11 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - #region ISharedRegionModule public new void Initialise(IConfigSource config) { - string umanmod = config.Configs["Modules"].GetString("UserManagementModule", base.Name); + string umanmod = config.Configs["Modules"].GetString("UserManagementModule", Name); if (umanmod == Name) { m_Enabled = true; -- cgit v1.1 From 69bc37acd66e9ac9938d4a657dc6b9a0ba9f021e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 2 Apr 2013 01:00:55 +0100 Subject: minor: Remove unnecessary call to GetAttachments() in AttachmentsModule.UpdateUserInventoryWithAttachment() --- OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs | 2 -- 1 file changed, 2 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index eec7ee5..7d16635 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -434,8 +434,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments private void UpdateUserInventoryWithAttachment(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool append) { - List attachments = sp.GetAttachments(attachmentPt); - // Add the new attachment to inventory if we don't already have it. UUID newAttachmentItemID = group.FromItemID; if (newAttachmentItemID == UUID.Zero) -- cgit v1.1 From 2bfe60e2fb2a3baf16b16c571c725a360cfec6c5 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 2 Apr 2013 01:28:16 +0100 Subject: Use Output instead of OutputFormat in appropriate places of XEngine status reporting. --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 8931be4..0d9babb 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -541,7 +541,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_Scene)) return; - MainConsole.Instance.OutputFormat(GetStatusReport()); + MainConsole.Instance.Output(GetStatusReport()); } public string GetStatusReport() @@ -640,7 +640,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine sb.AppendFormat("Containing part UUID: {0}\n", instance.ObjectID); sb.AppendFormat("Position : {0}\n", sop.AbsolutePosition); - MainConsole.Instance.OutputFormat(sb.ToString()); + MainConsole.Instance.Output(sb.ToString()); } private void HandleSuspendScript(IScriptInstance instance) -- cgit v1.1 From ebc1209fc97b835a46c53d33add1e390d2bb42e6 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 1 Apr 2013 08:40:15 -0700 Subject: BulletSim: rearrange mega-region terrain code to make the thread flow a little clearer. --- .../Physics/BulletSPlugin/BSTerrainManager.cs | 33 ++++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs index b2fb835..cd15850 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs @@ -199,15 +199,8 @@ public sealed class BSTerrainManager : IDisposable if (MegaRegionParentPhysicsScene is BSScene) { DetailLog("{0},SetTerrain.ToParent,offset={1},worldMax={2}", BSScene.DetailLogZero, m_worldOffset, m_worldMax); - // This looks really odd but this region is passing its terrain to its mega-region root region - // and the creation of the terrain must happen on the root region's taint thread and not - // my taint thread. - ((BSScene)MegaRegionParentPhysicsScene).PostTaintObject("TerrainManager.SetTerrain.Mega-" + m_worldOffset.ToString(), 0, delegate() - { - ((BSScene)MegaRegionParentPhysicsScene).TerrainManager.UpdateTerrain( - BSScene.CHILDTERRAIN_ID, localHeightMap, - m_worldOffset, m_worldOffset + DefaultRegionSize, true /* inTaintTime */); - }); + ((BSScene)MegaRegionParentPhysicsScene).TerrainManager.AddMegaRegionChildTerrain( + BSScene.CHILDTERRAIN_ID, localHeightMap, m_worldOffset, m_worldOffset + DefaultRegionSize); } } else @@ -215,12 +208,23 @@ public sealed class BSTerrainManager : IDisposable // If not doing the mega-prim thing, just change the terrain DetailLog("{0},SetTerrain.Existing", BSScene.DetailLogZero); - UpdateTerrain(BSScene.TERRAIN_ID, localHeightMap, - m_worldOffset, m_worldOffset + DefaultRegionSize, true /* inTaintTime */); + UpdateTerrain(BSScene.TERRAIN_ID, localHeightMap, m_worldOffset, m_worldOffset + DefaultRegionSize); } }); } + // Another region is calling this region passing a terrain. + // A region that is not the mega-region root will pass its terrain to the root region so the root region + // physics engine will have all the terrains. + private void AddMegaRegionChildTerrain(uint id, float[] heightMap, Vector3 minCoords, Vector3 maxCoords) + { + // Since we are called by another region's thread, the action must be rescheduled onto our processing thread. + PhysicsScene.PostTaintObject("TerrainManager.AddMegaRegionChild" + m_worldOffset.ToString(), 0, delegate() + { + UpdateTerrain(id, heightMap, minCoords, maxCoords); + }); + } + // If called for terrain has has not been previously allocated, a new terrain will be built // based on the passed information. The 'id' should be either the terrain id or // BSScene.CHILDTERRAIN_ID. If the latter, a new child terrain ID will be allocated and used. @@ -230,11 +234,10 @@ public sealed class BSTerrainManager : IDisposable // This call is most often used to update the heightMap and parameters of the terrain. // (The above does suggest that some simplification/refactoring is in order.) // Called during taint-time. - private void UpdateTerrain(uint id, float[] heightMap, - Vector3 minCoords, Vector3 maxCoords, bool inTaintTime) + private void UpdateTerrain(uint id, float[] heightMap, Vector3 minCoords, Vector3 maxCoords) { - DetailLog("{0},BSTerrainManager.UpdateTerrain,call,id={1},minC={2},maxC={3},inTaintTime={4}", - BSScene.DetailLogZero, id, minCoords, maxCoords, inTaintTime); + DetailLog("{0},BSTerrainManager.UpdateTerrain,call,id={1},minC={2},maxC={3}", + BSScene.DetailLogZero, id, minCoords, maxCoords); // Find high and low points of passed heightmap. // The min and max passed in is usually the area objects can be in (maximum -- cgit v1.1 From 17aef1c883aa81edba9a272e0a6897ad9a3a3983 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 1 Apr 2013 11:10:05 -0700 Subject: BulletSim: update unmanaged API for HACD parameter passing. Bullet HACD mesh to hull conversion calls in place but code not working. Update BulletSim DLLs and SOs for new API and HACD code. --- OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 6 +++--- OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs | 3 +-- OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 6 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs index 77ea3ed..f5b84d4 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs @@ -259,12 +259,12 @@ public override BulletShape CreateHullShape(BulletWorld world, int hullCount, fl BSPhysicsShapeType.SHAPE_HULL); } -public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape) +public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape, HACDParams parms) { BulletWorldUnman worldu = world as BulletWorldUnman; BulletShapeUnman shapeu = meshShape as BulletShapeUnman; return new BulletShapeUnman( - BSAPICPP.BuildHullShapeFromMesh2(worldu.ptr, shapeu.ptr), + BSAPICPP.BuildHullShapeFromMesh2(worldu.ptr, shapeu.ptr, parms), BSPhysicsShapeType.SHAPE_HULL); } @@ -1411,7 +1411,7 @@ public static extern IntPtr CreateHullShape2(IntPtr world, int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape); +public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape, HACDParams parms); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs index 6fc10e9..f6b4359 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs @@ -1773,10 +1773,9 @@ private sealed class BulletConstraintXNA : BulletConstraint return new BulletShapeXNA(compoundshape, BSPhysicsShapeType.SHAPE_HULL); } - public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape) + public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape, HACDParams parms) { /* TODO */ return null; - } public override BulletShape CreateMeshShape(BulletWorld pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs index 5765b0d..d0d9f34 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs @@ -191,6 +191,21 @@ public struct ConfigurationParameters public const float numericFalse = 0f; } +// Parameters passed for the conversion of a mesh to a hull using Bullet's HACD library. +[StructLayout(LayoutKind.Sequential)] +public struct HACDParams +{ + // usual default values + public float maxVerticesPerHull; // 100 + public float minClusters; // 2 + public float compacityWeight; // 0.1 + public float volumeWeight; // 0.0 + public float concavity; // 100 + public float addExtraDistPoints; // false + public float addNeighboursDistPoints; // false + public float addFacesPoints; // false + public float shouldAdjustCollisionMargin; // false +} // The states a bullet collision object can have public enum ActivationState : uint @@ -308,7 +323,7 @@ public abstract BulletShape CreateMeshShape(BulletWorld world, public abstract BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls); -public abstract BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape); +public abstract BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape, HACDParams parms); public abstract BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData); -- 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') 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 a3c723ee30db61e4c2c5375fa3c8c677336ca113 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 2 Apr 2013 23:48:55 +0100 Subject: Fix minor race condition where SOP.GetGeometricCenter() and GetCenterOfMass() could return results which were never the case if these values were changed whilst the method was running No need to create new Vector3s since these are structs. --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index ec9e87e..2fcb199 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -2136,9 +2136,9 @@ namespace OpenSim.Region.Framework.Scenes PhysicsActor pa = PhysActor; if (pa != null) - return new Vector3(pa.GeometricCenter.X, pa.GeometricCenter.Y, pa.GeometricCenter.Z); + return pa.GeometricCenter; else - return new Vector3(0, 0, 0); + return Vector3.Zero; } public Vector3 GetCenterOfMass() @@ -2146,9 +2146,9 @@ namespace OpenSim.Region.Framework.Scenes PhysicsActor pa = PhysActor; if (pa != null) - return new Vector3(pa.CenterOfMass.X, pa.CenterOfMass.Y, pa.CenterOfMass.Z); + return pa.CenterOfMass; else - return new Vector3(0, 0, 0); + return Vector3.Zero; } public float GetMass() -- cgit v1.1 From 3332af4060960a4b649d3d5237988e0f410b54e3 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 3 Apr 2013 00:01:06 +0100 Subject: minor: Make SOP.UpdateOffset() more consistent by checking against the same old OffsetPosition rather than one which may vary if it simultaneously changes. --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 2fcb199..d412702 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -3915,17 +3915,17 @@ namespace OpenSim.Region.Framework.Scenes } /// - /// + /// Update this part's offset position. /// /// - public void UpdateOffSet(Vector3 pos) + public void UpdateOffSet(Vector3 newPos) { - if ((pos.X != OffsetPosition.X) || - (pos.Y != OffsetPosition.Y) || - (pos.Z != OffsetPosition.Z)) - { - Vector3 newPos = new Vector3(pos.X, pos.Y, pos.Z); + Vector3 oldPos = OffsetPosition; + if ((newPos.X != oldPos.X) || + (newPos.Y != oldPos.Y) || + (newPos.Z != oldPos.Z)) + { if (ParentGroup.RootPart.GetStatusSandbox()) { if (Util.GetDistanceTo(ParentGroup.RootPart.StatusSandboxPos, newPos) > 10) -- cgit v1.1 From c0319daa403f68427bb80b4845a92eb37f21a7b7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 3 Apr 2013 00:09:28 +0100 Subject: fix minor race condition in SOP.SitTargetPositionLL where inconsistency could occur if the sit target position changed whilst the property was fetched --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index d412702..3e816fc 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -1146,7 +1146,7 @@ namespace OpenSim.Region.Framework.Scenes // the mappings more consistant. public Vector3 SitTargetPositionLL { - get { return new Vector3(m_sitTargetPosition.X, m_sitTargetPosition.Y,m_sitTargetPosition.Z); } + get { return m_sitTargetPosition; } set { m_sitTargetPosition = value; } } -- cgit v1.1 From 97f0c9da84f9a3a73a63c209012260fa2c59c0de Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 3 Apr 2013 00:23:20 +0100 Subject: Use consistent GroupPosition value Make SOP.UpdateGroupPosition() rather than one that could change whilst the method is being executed. --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 3e816fc..7697411 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -3902,13 +3902,14 @@ namespace OpenSim.Region.Framework.Scenes } } - public void UpdateGroupPosition(Vector3 pos) + public void UpdateGroupPosition(Vector3 newPos) { - if ((pos.X != GroupPosition.X) || - (pos.Y != GroupPosition.Y) || - (pos.Z != GroupPosition.Z)) + Vector3 oldPos = GroupPosition; + + if ((newPos.X != oldPos.X) || + (newPos.Y != oldPos.Y) || + (newPos.Z != oldPos.Z)) { - Vector3 newPos = new Vector3(pos.X, pos.Y, pos.Z); GroupPosition = newPos; ScheduleTerseUpdate(); } -- cgit v1.1 From 7bf1986e9138df4629aa9323d3ba9fab5c884400 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 3 Apr 2013 00:24:33 +0100 Subject: Fix minor race condition in SOP.SitTargetOrientationLL where inconsistent values could be returned if the sit orientation was changed whilst the property was being fetched. --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 7697411..93d4da0 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -1152,17 +1152,8 @@ namespace OpenSim.Region.Framework.Scenes public Quaternion SitTargetOrientationLL { - get - { - return new Quaternion( - m_sitTargetOrientation.X, - m_sitTargetOrientation.Y, - m_sitTargetOrientation.Z, - m_sitTargetOrientation.W - ); - } - - set { m_sitTargetOrientation = new Quaternion(value.X, value.Y, value.Z, value.W); } + get { return m_sitTargetOrientation; } + set { m_sitTargetOrientation = value; } } public bool Stopped -- cgit v1.1 From 94d44142e37a9191162a426f28dd23f40b0cf4aa Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 3 Apr 2013 00:48:36 +0100 Subject: minor: Stop falsely logging that a teleport was being aborted on client logout even when no teleport was active. --- .../CoreModules/Framework/EntityTransfer/EntityTransferModule.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index 3e69bf2..ca0cef1 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -280,10 +280,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer private void OnConnectionClosed(IClientAPI client) { - if (client.IsLoggingOut) + if (client.IsLoggingOut && m_entityTransferStateMachine.UpdateInTransit(client.AgentId, AgentTransferState.Aborting)) { - m_entityTransferStateMachine.UpdateInTransit(client.AgentId, AgentTransferState.Aborting); - m_log.DebugFormat( "[ENTITY TRANSFER MODULE]: Aborted teleport request from {0} in {1} due to simultaneous logout", client.Name, Scene.Name); -- cgit v1.1 From 831e4c38506140e9ece2db4b96b4f0960a0276a8 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 4 Apr 2013 00:36:15 +0100 Subject: Fix bug where outstanding llHTTPRequests for scripts were not being aborted when they were deleted. This was because AsyncCommandManager was handing an item ID to IHttpRequestModule.StopHttpRequest() rather than the expected request ID. This commit also makes the http request asynchronous using BeginGetResponse() rather than doing this by launching a new thread so that we can more safely abort it via HttpWebRequest.Abort() rather than aborting the thread itself. This also renames StopHttpRequest() to StopHttpRequestsForScript() since any outstanding requests are now aborted and/or removed. --- .../Scripting/HttpRequest/ScriptsHttpRequests.cs | 92 +++++++++++++++------- .../Region/Framework/Interfaces/IHttpRequests.cs | 8 +- .../Api/Implementation/AsyncCommandManager.cs | 8 +- 3 files changed, 76 insertions(+), 32 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs index c2e37c4..1c251b8 100644 --- a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs +++ b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs @@ -28,12 +28,15 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Net; using System.Net.Mail; using System.Net.Security; +using System.Reflection; using System.Text; using System.Threading; using System.Security.Cryptography.X509Certificates; +using log4net; using Nini.Config; using OpenMetaverse; using OpenSim.Framework; @@ -250,18 +253,29 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest return reqID; } - public void StopHttpRequest(uint m_localID, UUID m_itemID) + public void StopHttpRequestsForScript(UUID id) { if (m_pendingRequests != null) { + List keysToRemove = null; + lock (HttpListLock) { - HttpRequestClass tmpReq; - if (m_pendingRequests.TryGetValue(m_itemID, out tmpReq)) + foreach (HttpRequestClass req in m_pendingRequests.Values) { - tmpReq.Stop(); - m_pendingRequests.Remove(m_itemID); + if (req.ItemID == id) + { + req.Stop(); + + if (keysToRemove == null) + keysToRemove = new List(); + + keysToRemove.Add(req.ReqID); + } } + + if (keysToRemove != null) + keysToRemove.ForEach(keyToRemove => m_pendingRequests.Remove(keyToRemove)); } } } @@ -362,6 +376,8 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest public class HttpRequestClass: IServiceRequest { +// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + // Constants for parameters // public const int HTTP_BODY_MAXLENGTH = 2; // public const int HTTP_METHOD = 0; @@ -419,12 +435,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest public void Process() { - httpThread = new Thread(SendRequest); - httpThread.Name = "HttpRequestThread"; - httpThread.Priority = ThreadPriority.BelowNormal; - httpThread.IsBackground = true; - _finished = false; - httpThread.Start(); + SendRequest(); } /* @@ -435,10 +446,6 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest public void SendRequest() { HttpWebResponse response = null; - StringBuilder sb = new StringBuilder(); - byte[] buf = new byte[8192]; - string tempString = null; - int count = 0; try { @@ -497,11 +504,12 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest bstream.Close(); } - Request.Timeout = HttpTimeout; try { - // execute the request - response = (HttpWebResponse) Request.GetResponse(); + IAsyncResult result = (IAsyncResult)Request.BeginGetResponse(ResponseCallback, null); + + ThreadPool.RegisterWaitForSingleObject( + result.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), null, HttpTimeout, true); } catch (WebException e) { @@ -510,11 +518,31 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest throw; } response = (HttpWebResponse)e.Response; + _finished = true; } + } + catch (Exception e) + { + Status = (int)OSHttpStatusCode.ClientErrorJoker; + ResponseBody = e.Message; + _finished = true; + } + } + private void ResponseCallback(IAsyncResult ar) + { + HttpWebResponse response = null; + + try + { + response = (HttpWebResponse)Request.EndGetResponse(ar); Status = (int)response.StatusCode; Stream resStream = response.GetResponseStream(); + StringBuilder sb = new StringBuilder(); + byte[] buf = new byte[8192]; + string tempString = null; + int count = 0; do { @@ -530,36 +558,40 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest // continue building the string sb.Append(tempString); } - } while (count > 0); // any more data to read? + } + while (count > 0); // any more data to read? - ResponseBody = sb.ToString(); + ResponseBody = sb.ToString(); } catch (Exception e) { Status = (int)OSHttpStatusCode.ClientErrorJoker; ResponseBody = e.Message; - _finished = true; - return; +// m_log.Debug( +// string.Format("[SCRIPTS HTTP REQUESTS]: Exception on response to {0} for {1} ", Url, ItemID), e); } finally { if (response != null) response.Close(); + + _finished = true; } + } - _finished = true; + private void TimeoutCallback(object state, bool timedOut) + { + if (timedOut) + Request.Abort(); } public void Stop() { - try - { - httpThread.Abort(); - } - catch (Exception) - { - } +// m_log.DebugFormat("[SCRIPTS HTTP REQUESTS]: Stopping request to {0} for {1} ", Url, ItemID); + + if (Request != null) + Request.Abort(); } } } diff --git a/OpenSim/Region/Framework/Interfaces/IHttpRequests.cs b/OpenSim/Region/Framework/Interfaces/IHttpRequests.cs index eb6c5ac..113dcd7 100644 --- a/OpenSim/Region/Framework/Interfaces/IHttpRequests.cs +++ b/OpenSim/Region/Framework/Interfaces/IHttpRequests.cs @@ -45,7 +45,13 @@ namespace OpenSim.Region.Framework.Interfaces { UUID MakeHttpRequest(string url, string parameters, string body); UUID StartHttpRequest(uint localID, UUID itemID, string url, List parameters, Dictionary headers, string body); - void StopHttpRequest(uint m_localID, UUID m_itemID); + + /// + /// Stop and remove all http requests for the given script. + /// + /// + void StopHttpRequestsForScript(UUID id); + IServiceRequest GetNextCompletedRequest(); void RemoveCompletedRequest(UUID id); } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs index 47a9cdc..1c59624 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs @@ -28,7 +28,9 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Reflection; using System.Threading; +using log4net; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Framework.Monitoring; @@ -45,6 +47,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api /// public class AsyncCommandManager { +// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static Thread cmdHandlerThread; private static int cmdHandlerThreadCycleSleepms; @@ -225,6 +229,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api /// public static void RemoveScript(IScriptEngine engine, uint localID, UUID itemID) { +// m_log.DebugFormat("[ASYNC COMMAND MANAGER]: Removing facilities for script {0}", itemID); + // Remove a specific script // Remove dataserver events @@ -236,7 +242,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // Remove from: HttpRequest IHttpRequestModule iHttpReq = engine.World.RequestModuleInterface(); if (iHttpReq != null) - iHttpReq.StopHttpRequest(localID, itemID); + iHttpReq.StopHttpRequestsForScript(itemID); IWorldComm comms = engine.World.RequestModuleInterface(); if (comms != null) -- cgit v1.1 From f281a994e8544d95961ef669a0fe14c0cba7f175 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 4 Apr 2013 00:49:07 +0100 Subject: refactor: Simplify ScriptsHttpRequests.GetNextCompletedRequest to more simply iterate through pending requests without unnecessary checks. --- .../Scripting/HttpRequest/ScriptsHttpRequests.cs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs index 1c251b8..ebf56cd 100644 --- a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs +++ b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs @@ -293,19 +293,13 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest { lock (HttpListLock) { - foreach (UUID luid in m_pendingRequests.Keys) + foreach (HttpRequestClass req in m_pendingRequests.Values) { - HttpRequestClass tmpReq; - - if (m_pendingRequests.TryGetValue(luid, out tmpReq)) - { - if (tmpReq.Finished) - { - return tmpReq; - } - } + if (req.Finished) + return req; } } + return null; } -- cgit v1.1 From f064075a85962039f4737ec9ca631c377a6197c9 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 4 Apr 2013 01:06:57 +0100 Subject: Fix XmlRpcAdmin admin_exists_user call so that it actually returns the last user login time rather than serializing the DateTime directly which generates a set of unexpected fields. lastlogin return is in unix timestamp format. --- OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs index 5d44b2a..d19b8b6 100644 --- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs +++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs @@ -1094,7 +1094,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController { GridUserInfo userInfo = m_application.SceneManager.CurrentOrFirstScene.GridUserService.GetGridUserInfo(account.PrincipalID.ToString()); if (userInfo != null) - responseData["lastlogin"] = userInfo.Login; + responseData["lastlogin"] = Util.ToUnixTime(userInfo.Login); else responseData["lastlogin"] = 0; -- cgit v1.1 From d2367968e4227f8a6e37d22ed5904c4f1d87a15e Mon Sep 17 00:00:00 2001 From: teravus Date: Thu, 4 Apr 2013 19:10:23 -0400 Subject: * In between the fog, a moment of clarity. This fixes mantis 6570 --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index dfdd566..96a030b 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -453,7 +453,7 @@ namespace OpenSim.Framework.Servers.HttpServer } OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context); - + resp.ReuseContext = true; HandleRequest(req, resp); -- cgit v1.1