From 776cc33541d5b0576f28c02953be728ab3154e22 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 27 Jan 2013 01:07:37 +0000 Subject: Prevent items being destroyed by rename operations. Renaming of a wearable also sends an asset transaciton but it is empty. So we can't ignore name data when a transaction is present and can't treat every transaction as valid. Conflicts: OpenSim/Region/Framework/Scenes/Scene.Inventory.cs --- .../CoreModules/Agent/AssetTransaction/AssetXferUploader.cs | 3 ++- OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs index 8add4bb..11efe6d 100644 --- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs +++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs @@ -321,7 +321,8 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction // to avoid a race condition when the appearance module retrieves the item to set the asset id in // the AvatarAppearance structure. item.AssetID = m_asset.FullID; - m_Scene.InventoryService.UpdateItem(item); + if (item.AssetID != UUID.Zero) + m_Scene.InventoryService.UpdateItem(item); if (m_uploadState == UploadState.Complete) { diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 92bf85a..6808017 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -407,16 +407,16 @@ namespace OpenSim.Region.Framework.Scenes if (item.Owner != remoteClient.AgentId) return; - if (UUID.Zero == transactionID) - { - item.Name = itemUpd.Name; - item.Description = itemUpd.Description; + item.Name = itemUpd.Name; + item.Description = itemUpd.Description; // m_log.DebugFormat( // "[USER INVENTORY]: itemUpd {0} {1} {2} {3}, item {4} {5} {6} {7}", // itemUpd.NextPermissions, itemUpd.GroupPermissions, itemUpd.EveryOnePermissions, item.Flags, // item.NextPermissions, item.GroupPermissions, item.EveryOnePermissions, item.CurrentPermissions); + if (itemUpd.NextPermissions != 0) // Use this to determine validity. Can never be 0 if valid + { if (item.NextPermissions != (itemUpd.NextPermissions & item.BasePermissions)) item.Flags |= (uint)InventoryItemFlags.ObjectOverwriteNextOwner; item.NextPermissions = itemUpd.NextPermissions & item.BasePermissions; @@ -451,7 +451,8 @@ namespace OpenSim.Region.Framework.Scenes InventoryService.UpdateItem(item); } - else + + if (UUID.Zero != transactionID) { if (AgentTransactionsModule != null) { -- cgit v1.1 From c44a8e9f925c0195c4754c5e763af06dae657b53 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Fri, 25 Jan 2013 10:17:20 -0800 Subject: BulletSim: finish the post step event for physical object actions. Modify vehicle to use post step event for logging. --- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 14 ++++- .../Region/Physics/BulletSPlugin/BSPhysObject.cs | 66 ++++++++++++++++++---- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 6 ++ 3 files changed, 73 insertions(+), 13 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 7ad7c89..a369c1f 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -583,6 +583,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Some of the properties of this prim may have changed. // Do any updating needed for a vehicle + Vector3 m_physicsLinearFactor = new Vector3(0.2f, 0.2f, 0.2f); // DEBUG DEBUG + Vector3 m_physicsAngularFactor = new Vector3(0.2f, 0.2f, 0.2f); // DEBUG DEBUG public void Refresh() { if (IsActive) @@ -599,6 +601,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Maybe compute linear and angular factor and damping from params. float angularDamping = BSParam.VehicleAngularDamping; PhysicsScene.PE.SetAngularDamping(Prim.PhysBody, angularDamping); + PhysicsScene.PE.SetLinearFactor(Prim.PhysBody, m_physicsLinearFactor); // DEBUG DEBUG + PhysicsScene.PE.SetAngularFactorV(Prim.PhysBody, m_physicsAngularFactor); // DEBUG DEBUG // Vehicles report collision events so we know when it's on the ground PhysicsScene.PE.AddToCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); @@ -898,9 +902,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin { if (!IsActive) return; - if (PhysicsScene.VehiclePhysicalLoggingEnabled) - PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody); - ForgetKnownVehicleProperties(); MoveLinear(pTimestep); @@ -922,6 +923,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin Prim.LocalID, VehiclePosition, m_knownForce, VehicleVelocity, VehicleRotationalVelocity); } + // Called after the simulation step + internal void PostStep(float pTimestep) + { + if (PhysicsScene.VehiclePhysicalLoggingEnabled) + PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody); + } + // Apply the effect of the linear motor and other linear motions (like hover and float). private void MoveLinear(float pTimestep) { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 027c786..285d4a2 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -101,6 +101,7 @@ public abstract class BSPhysObject : PhysicsActor public virtual void Destroy() { UnRegisterAllPreStepActions(); + UnRegisterAllPostStepActions(); } public BSScene PhysicsScene { get; protected set; } @@ -393,17 +394,18 @@ public abstract class BSPhysObject : PhysicsActor // 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. // This bookkeeping makes it easy to add, remove and clean up after all these registrations. - private Dictionary RegisteredActions = new Dictionary(); + private Dictionary RegisteredPrestepActions = new Dictionary(); + private Dictionary RegisteredPoststepActions = new Dictionary(); protected void RegisterPreStepAction(string op, uint id, BSScene.PreStepAction actn) { string identifier = op + "-" + id.ToString(); - lock (RegisteredActions) + lock (RegisteredPrestepActions) { // Clean out any existing action UnRegisterPreStepAction(op, id); - RegisteredActions[identifier] = actn; + RegisteredPrestepActions[identifier] = actn; } PhysicsScene.BeforeStep += actn; DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier); @@ -414,12 +416,12 @@ public abstract class BSPhysObject : PhysicsActor { string identifier = op + "-" + id.ToString(); bool removed = false; - lock (RegisteredActions) + lock (RegisteredPrestepActions) { - if (RegisteredActions.ContainsKey(identifier)) + if (RegisteredPrestepActions.ContainsKey(identifier)) { - PhysicsScene.BeforeStep -= RegisteredActions[identifier]; - RegisteredActions.Remove(identifier); + PhysicsScene.BeforeStep -= RegisteredPrestepActions[identifier]; + RegisteredPrestepActions.Remove(identifier); removed = true; } } @@ -428,17 +430,61 @@ public abstract class BSPhysObject : PhysicsActor protected void UnRegisterAllPreStepActions() { - lock (RegisteredActions) + lock (RegisteredPrestepActions) { - foreach (KeyValuePair kvp in RegisteredActions) + foreach (KeyValuePair kvp in RegisteredPrestepActions) { PhysicsScene.BeforeStep -= kvp.Value; } - RegisteredActions.Clear(); + RegisteredPrestepActions.Clear(); } DetailLog("{0},BSPhysObject.UnRegisterAllPreStepActions,", LocalID); } + + protected void RegisterPostStepAction(string op, uint id, BSScene.PostStepAction actn) + { + string identifier = op + "-" + id.ToString(); + + lock (RegisteredPoststepActions) + { + // Clean out any existing action + UnRegisterPostStepAction(op, id); + + RegisteredPoststepActions[identifier] = actn; + } + PhysicsScene.AfterStep += actn; + DetailLog("{0},BSPhysObject.RegisterPostStepAction,id={1}", LocalID, identifier); + } + + // Unregister a pre step action. Safe to call if the action has not been registered. + protected void UnRegisterPostStepAction(string op, uint id) + { + string identifier = op + "-" + id.ToString(); + bool removed = false; + lock (RegisteredPoststepActions) + { + if (RegisteredPoststepActions.ContainsKey(identifier)) + { + PhysicsScene.AfterStep -= RegisteredPoststepActions[identifier]; + RegisteredPoststepActions.Remove(identifier); + removed = true; + } + } + DetailLog("{0},BSPhysObject.UnRegisterPostStepAction,id={1},removed={2}", LocalID, identifier, removed); + } + protected void UnRegisterAllPostStepActions() + { + lock (RegisteredPoststepActions) + { + foreach (KeyValuePair kvp in RegisteredPoststepActions) + { + PhysicsScene.AfterStep -= kvp.Value; + } + RegisteredPoststepActions.Clear(); + } + DetailLog("{0},BSPhysObject.UnRegisterAllPostStepActions,", LocalID); + } #endregion // Per Simulation Step actions diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 8b00a33..99903f5 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -527,9 +527,15 @@ public sealed class BSPrim : BSPhysObject // If an active vehicle, register the vehicle code to be called before each step if (_vehicle.Type == Vehicle.TYPE_NONE) + { UnRegisterPreStepAction("BSPrim.Vehicle", LocalID); + PhysicsScene.AfterStep -= _vehicle.PostStep; + } else + { RegisterPreStepAction("BSPrim.Vehicle", LocalID, _vehicle.Step); + PhysicsScene.AfterStep += _vehicle.PostStep; + } }); } } -- cgit v1.1 From dd08e1fba6e154002a7fe8f46c8c01e6e61d39db Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Fri, 25 Jan 2013 12:00:19 -0800 Subject: BulletSim: parameterize several vehicle debugging values: physical linear and angular force factors now default to less than 1 (0.2) vehicle friction and restitution now default to low values --- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 12 +++--- OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 45 ++++++++++++++++++++++ .../Region/Physics/BulletSPlugin/BulletSimTODO.txt | 9 ++++- 3 files changed, 57 insertions(+), 9 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index a369c1f..5c531fc 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -583,8 +583,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Some of the properties of this prim may have changed. // Do any updating needed for a vehicle - Vector3 m_physicsLinearFactor = new Vector3(0.2f, 0.2f, 0.2f); // DEBUG DEBUG - Vector3 m_physicsAngularFactor = new Vector3(0.2f, 0.2f, 0.2f); // DEBUG DEBUG public void Refresh() { if (IsActive) @@ -593,16 +591,16 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_vehicleMass = Prim.Linkset.LinksetMass; // Friction affects are handled by this vehicle code - float friction = 0f; - PhysicsScene.PE.SetFriction(Prim.PhysBody, friction); + PhysicsScene.PE.SetFriction(Prim.PhysBody, BSParam.VehicleFriction); + PhysicsScene.PE.SetRestitution(Prim.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. float angularDamping = BSParam.VehicleAngularDamping; PhysicsScene.PE.SetAngularDamping(Prim.PhysBody, angularDamping); - PhysicsScene.PE.SetLinearFactor(Prim.PhysBody, m_physicsLinearFactor); // DEBUG DEBUG - PhysicsScene.PE.SetAngularFactorV(Prim.PhysBody, m_physicsAngularFactor); // DEBUG DEBUG + PhysicsScene.PE.SetLinearFactor(Prim.PhysBody, BSParam.VehicleLinearFactorV); + PhysicsScene.PE.SetAngularFactorV(Prim.PhysBody, BSParam.VehicleAngularFactorV); // Vehicles report collision events so we know when it's on the ground PhysicsScene.PE.AddToCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); @@ -618,7 +616,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin PhysicsScene.PE.SetGravity(Prim.PhysBody, Vector3.Zero); VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4},grav={5}", - Prim.LocalID, m_vehicleMass, friction, Prim.Inertia, angularDamping, m_VehicleGravity); + Prim.LocalID, m_vehicleMass, Prim.Inertia, angularDamping, m_VehicleGravity); } else { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index 06186b0..8de8905 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs @@ -82,9 +82,34 @@ public static class BSParam public static float AvatarStepApproachFactor { get; private set; } public static float AvatarStepForceFactor { get; private set; } + // Vehicle parameters public static float VehicleMaxLinearVelocity { get; private set; } public static float VehicleMaxAngularVelocity { get; private set; } public static float VehicleAngularDamping { get; private set; } + public static float VehicleFriction { get; private set; } + public static float VehicleRestitution { get; private set; } + public static float VehicleLinearFactor { get; private set; } + private static Vector3? vehicleLinearFactorV; + public static Vector3 VehicleLinearFactorV + { + get + { + if (!vehicleLinearFactorV.HasValue) + vehicleLinearFactorV = new Vector3(VehicleLinearFactor, VehicleLinearFactor, VehicleLinearFactor); + return (Vector3)vehicleLinearFactorV; + } + } + public static float VehicleAngularFactor { get; private set; } + private static Vector3? vehicleAngularFactorV; + public static Vector3 VehicleAngularFactorV + { + get + { + if (!vehicleAngularFactorV.HasValue) + vehicleAngularFactorV = new Vector3(VehicleAngularFactor, VehicleAngularFactor, VehicleAngularFactor); + return (Vector3)vehicleAngularFactorV; + } + } public static float VehicleDebuggingEnabled { get; private set; } public static float LinksetImplementation { get; private set; } @@ -454,6 +479,26 @@ public static class BSParam (s,cf,p,v) => { VehicleAngularDamping = cf.GetFloat(p, v); }, (s) => { return VehicleAngularDamping; }, (s,p,l,v) => { VehicleAngularDamping = v; } ), + new ParameterDefn("VehicleLinearFactor", "Fraction of physical linear changes applied to vehicle (0.0 - 1.0)", + 0.2f, + (s,cf,p,v) => { VehicleLinearFactor = cf.GetFloat(p, v); }, + (s) => { return VehicleLinearFactor; }, + (s,p,l,v) => { VehicleLinearFactor = v; } ), + new ParameterDefn("VehicleAngularFactor", "Fraction of physical angular changes applied to vehicle (0.0 - 1.0)", + 0.2f, + (s,cf,p,v) => { VehicleAngularFactor = cf.GetFloat(p, v); }, + (s) => { return VehicleAngularFactor; }, + (s,p,l,v) => { VehicleAngularFactor = v; } ), + new ParameterDefn("VehicleFriction", "Friction of vehicle on the ground (0.0 - 1.0)", + 0.0f, + (s,cf,p,v) => { VehicleFriction = cf.GetFloat(p, v); }, + (s) => { return VehicleFriction; }, + (s,p,l,v) => { VehicleFriction = v; } ), + new ParameterDefn("VehicleRestitution", "Bouncyness factor for vehicles (0.0 - 1.0)", + 0.0f, + (s,cf,p,v) => { VehicleRestitution = cf.GetFloat(p, v); }, + (s) => { return VehicleRestitution; }, + (s,p,l,v) => { VehicleRestitution = v; } ), new ParameterDefn("VehicleDebuggingEnable", "Turn on/off vehicle debugging", ConfigurationParameters.numericFalse, (s,cf,p,v) => { VehicleDebuggingEnabled = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); }, diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt index 801f690..7917795 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt @@ -2,7 +2,6 @@ CURRENT PRIORITIES ================================================= Deleting a linkset while standing on the root will leave the physical shape of the root behind. Not sure if it is because standing on it. Done with large prim linksets. -Child movement in linkset (don't rebuild linkset) Vehicle angular vertical attraction vehicle angular banking Center-of-gravity @@ -12,6 +11,7 @@ when should angular and linear motor targets be zeroed? when selected? Need a vehicle.clear()? Or an 'else' in prestep if not physical. Teravus llMoveToTarget script debug Mixing of hover, buoyancy/gravity, moveToTarget, into one force + Setting hover height to zero disables hover even if hover flags are on (from SL wiki) Nebadon vehicles turning funny in arena limitMotorUp calibration (more down?) llRotLookAt @@ -72,7 +72,11 @@ Incorporate inter-relationship of angular corrections. For instance, angularDefl GENERAL TODO LIST: ================================================= +Avatar standing on a moving object should start to move with the object. llMoveToTarget objects are not effected by gravity until target is removed. +Compute CCD parameters based on body size +Can solver iterations be changed per body/shape? Can be for constraints but what + about regular vehicles? Implement llSetPhysicalMaterial. extend it with Center-of-mass, rolling friction, density Implement llSetForceAndTorque. @@ -321,4 +325,5 @@ Mantis 6040 script http://opensimulator.org/mantis/view.php?id=6040 (DONE) Boats float low in the water (DONE) Boats floating at proper level (DONE) When is force introduced by SetForce removed? The prestep action could go forever. (DONE) - (Resolution: setForce registers a prestep action which keeps applying the force) \ No newline at end of file + (Resolution: setForce registers a prestep action which keeps applying the force) +Child movement in linkset (don't rebuild linkset) (DONE 20130122)) \ No newline at end of file -- cgit v1.1 From ddef8f16e58471d19baa63f14134b25309cf2570 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Fri, 25 Jan 2013 16:00:17 -0800 Subject: BulletSim: first attempt at reporting top colliders --- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 10 ++++++---- OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 17 +++++++++++++++++ OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 6 ------ OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 17 ++++++++++++++++- OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt | 4 ++++ 5 files changed, 43 insertions(+), 11 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 5c531fc..06b4620 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -597,8 +597,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin // 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. - float angularDamping = BSParam.VehicleAngularDamping; - PhysicsScene.PE.SetAngularDamping(Prim.PhysBody, angularDamping); + PhysicsScene.PE.SetAngularDamping(Prim.PhysBody, BSParam.VehicleAngularDamping); PhysicsScene.PE.SetLinearFactor(Prim.PhysBody, BSParam.VehicleLinearFactorV); PhysicsScene.PE.SetAngularFactorV(Prim.PhysBody, BSParam.VehicleAngularFactorV); @@ -615,8 +614,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin // 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); - VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4},grav={5}", - Prim.LocalID, m_vehicleMass, Prim.Inertia, angularDamping, m_VehicleGravity); + VDetailLog("{0},BSDynamics.Refresh,mass={1},inert={2},grav={3},aDamp={4},frict={5},rest={6},lFact={7},aFact={8}", + Prim.LocalID, m_vehicleMass, Prim.Inertia, m_VehicleGravity, + BSParam.VehicleAngularDamping, BSParam.VehicleFriction, BSParam.VehicleRestitution, + BSParam.VehicleLinearFactor, BSParam.VehicleAngularFactor + ); } else { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 285d4a2..5e8143c 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -95,6 +95,8 @@ public abstract class BSPhysObject : PhysicsActor SubscribedEventsMs = 0; CollidingStep = 0; CollidingGroundStep = 0; + CollisionAccumulation = 0; + CollisionScore = 0; } // Tell the object to clean up. @@ -239,6 +241,9 @@ public abstract class BSPhysObject : PhysicsActor // The collision flags we think are set in Bullet protected CollisionFlags CurrentCollisionFlags { get; set; } + // Count of collisions for this object + protected long CollisionAccumulation { get; set; } + public override bool IsColliding { get { return (CollidingStep == PhysicsScene.SimulationStep); } set { @@ -300,6 +305,8 @@ public abstract class BSPhysObject : PhysicsActor return ret; } + CollisionAccumulation++; + // if someone has subscribed for collision events.... if (SubscribedEvents()) { CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); @@ -386,6 +393,16 @@ public abstract class BSPhysObject : PhysicsActor public override bool SubscribedEvents() { return (SubscribedEventsMs > 0); } + // Because 'CollisionScore' is calls many times while sorting it should not be recomputed + // each time called. So this is built to be light weight for each collision and to do + // all the processing when the user asks for the info. + public void ComputeCollisionScore() + { + // Scale the collision count by the time since the last collision + long timeAgo = PhysicsScene.SimulationStep - CollidingStep + 1; + CollisionScore = CollisionAccumulation / timeAgo; + } + public override float CollisionScore { get; set; } #endregion // Collisions diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 99903f5..17fddd7 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -59,7 +59,6 @@ public sealed class BSPrim : BSPhysObject private OMV.Vector3 _force; private OMV.Vector3 _velocity; private OMV.Vector3 _torque; - private float _collisionScore; private OMV.Vector3 _acceleration; private OMV.Quaternion _orientation; private int _physicsActorType; @@ -644,11 +643,6 @@ public sealed class BSPrim : BSPhysObject // DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque); } } - public override float CollisionScore { - get { return _collisionScore; } - set { _collisionScore = value; - } - } public override OMV.Vector3 Acceleration { get { return _acceleration; } set { _acceleration = value; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index cb304b6..4442650 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -26,6 +26,7 @@ */ using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Text; @@ -697,7 +698,21 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters public override Dictionary GetTopColliders() { - return new Dictionary(); + Dictionary topColliders; + + lock (PhysObjects) + { + foreach (KeyValuePair kvp in PhysObjects) + { + kvp.Value.ComputeCollisionScore(); + } + + List orderedPrims = new List(PhysObjects.Values); + orderedPrims.OrderByDescending(p => p.CollisionScore).Take(25); + topColliders = orderedPrims.ToDictionary(p => p.LocalID, p => p.CollisionScore); + } + + return topColliders; } public override bool IsThreaded { get { return false; } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt index 7917795..a95e169 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt @@ -1,5 +1,9 @@ CURRENT PRIORITIES ================================================= +One sided meshes? Should terrain be built into a closed shape? + When meshes get partially wedged into the terrain, they cannot push themselves out. + It is possible that Bullet processes collisions whether entering or leaving a mesh. + Ref: http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4869 Deleting a linkset while standing on the root will leave the physical shape of the root behind. Not sure if it is because standing on it. Done with large prim linksets. Vehicle angular vertical attraction -- cgit v1.1 From 36f401d85011b0ffb548e79923381be894dbfabb Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Fri, 25 Jan 2013 16:52:16 -0800 Subject: BulletSim: parameterize the value for gravity reduction for ground vehicles on the ground. Set defaults for vehicle factors to one. Debug logging changes. --- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 15 ++++++++------- OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs | 2 +- OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 12 +++++++++--- 3 files changed, 18 insertions(+), 11 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 06b4620..90482fd 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -976,8 +976,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin public void ComputeLinearVelocity(float pTimestep) { // Step the motor from the current value. Get the correction needed this step. - Vector3 currentVel = VehicleVelocity * Quaternion.Inverse(VehicleOrientation); - Vector3 linearMotorCorrectionV = m_linearMotor.Step(pTimestep, currentVel); + Vector3 origVelW = VehicleVelocity; // DEBUG + Vector3 currentVelV = VehicleVelocity * Quaternion.Inverse(VehicleOrientation); + Vector3 linearMotorCorrectionV = m_linearMotor.Step(pTimestep, currentVelV); // Motor is vehicle coordinates. Rotate it to world coordinates Vector3 linearMotorVelocityW = linearMotorCorrectionV * VehicleOrientation; @@ -992,8 +993,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Add this correction to the velocity to make it faster/slower. VehicleVelocity += linearMotorVelocityW; - VDetailLog("{0}, MoveLinear,velocity,vehVel={1},correction={2},force={3}", - Prim.LocalID, VehicleVelocity, linearMotorCorrectionV, linearMotorVelocityW); + VDetailLog("{0}, MoveLinear,velocity,origVelW={1},velV={2},correctV={3},correctW={4},newVelW={5}", + Prim.LocalID, origVelW, currentVelV, linearMotorCorrectionV, linearMotorVelocityW, VehicleVelocity); } public void ComputeLinearTerrainHeightCorrection(float pTimestep) @@ -1193,12 +1194,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Hack to reduce downward force if the vehicle is probably sitting on the ground if (Prim.IsColliding && IsGroundVehicle) - appliedGravity *= 0.2f; + appliedGravity *= BSParam.VehicleGroundGravityFudge; VehicleAddForce(appliedGravity); - VDetailLog("{0}, MoveLinear,applyGravity,vehGrav={1},appliedForce-{2}", - Prim.LocalID, m_VehicleGravity, appliedGravity); + VDetailLog("{0}, MoveLinear,applyGravity,vehGrav={1},collid={2},appliedForce={3}", + Prim.LocalID, m_VehicleGravity, Prim.IsColliding, appliedGravity); } // ======================================================================= diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index 2c8dd23..6c53c50 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs @@ -232,7 +232,7 @@ public sealed class BSLinksetCompound : BSLinkset newLsi.OffsetFromCenterOfMass, newLsi.OffsetRot, true /* shouldRecalculateLocalAabb */); - DetailLog("{0},BSLinksetCompound.UpdateProperties,changeChildPosRot,whichUpdated={1}newLsi={2}", + DetailLog("{0},BSLinksetCompound.UpdateProperties,changeChildPosRot,whichUpdated={1},newLsi={2}", updated.LocalID, whichUpdated, newLsi); updated.LinksetInfo = newLsi; updatedChild = true; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index 8de8905..75eed86 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs @@ -110,6 +110,7 @@ public static class BSParam return (Vector3)vehicleAngularFactorV; } } + public static float VehicleGroundGravityFudge { get; private set; } public static float VehicleDebuggingEnabled { get; private set; } public static float LinksetImplementation { get; private set; } @@ -480,12 +481,12 @@ public static class BSParam (s) => { return VehicleAngularDamping; }, (s,p,l,v) => { VehicleAngularDamping = v; } ), new ParameterDefn("VehicleLinearFactor", "Fraction of physical linear changes applied to vehicle (0.0 - 1.0)", - 0.2f, + 1.0f, (s,cf,p,v) => { VehicleLinearFactor = cf.GetFloat(p, v); }, (s) => { return VehicleLinearFactor; }, (s,p,l,v) => { VehicleLinearFactor = v; } ), new ParameterDefn("VehicleAngularFactor", "Fraction of physical angular changes applied to vehicle (0.0 - 1.0)", - 0.2f, + 1.0f, (s,cf,p,v) => { VehicleAngularFactor = cf.GetFloat(p, v); }, (s) => { return VehicleAngularFactor; }, (s,p,l,v) => { VehicleAngularFactor = v; } ), @@ -495,10 +496,15 @@ public static class BSParam (s) => { return VehicleFriction; }, (s,p,l,v) => { VehicleFriction = v; } ), new ParameterDefn("VehicleRestitution", "Bouncyness factor for vehicles (0.0 - 1.0)", - 0.0f, + 0.2f, (s,cf,p,v) => { VehicleRestitution = cf.GetFloat(p, v); }, (s) => { return VehicleRestitution; }, (s,p,l,v) => { VehicleRestitution = v; } ), + new ParameterDefn("VehicleGroundGravityFudge", "Factor to multiple gravity if a ground vehicle is probably on the ground (0.0 - 1.0)", + 1.0f, + (s,cf,p,v) => { VehicleGroundGravityFudge = cf.GetFloat(p, v); }, + (s) => { return VehicleGroundGravityFudge; }, + (s,p,l,v) => { VehicleGroundGravityFudge = v; } ), new ParameterDefn("VehicleDebuggingEnable", "Turn on/off vehicle debugging", ConfigurationParameters.numericFalse, (s,cf,p,v) => { VehicleDebuggingEnabled = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); }, -- cgit v1.1 From 80f0a978db50f8fa3a36e012f92d7ff3755be332 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 27 Jan 2013 09:00:47 -0800 Subject: BulletSim: fix compile error from last commit --- OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 4442650..86eb773 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -88,7 +88,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters public delegate void PreStepAction(float timeStep); public delegate void PostStepAction(float timeStep); public event PreStepAction BeforeStep; - public event PreStepAction AfterStep; + public event PostStepAction AfterStep; // A value of the time now so all the collision and update routines do not have to get their own // Set to 'now' just before all the prims and actors are called for collisions and updates @@ -763,7 +763,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters private void TriggerPostStepEvent(float timeStep) { - PreStepAction actions = AfterStep; + PostStepAction actions = AfterStep; if (actions != null) actions(timeStep); -- cgit v1.1 From 05adf4b30f2a7cdb63c63a178bd44b0fecbe9c45 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 27 Jan 2013 09:01:24 -0800 Subject: BulletSim: disable center-of-mass computation because it does not work yet --- OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index 6c53c50..54dc458 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs @@ -377,7 +377,7 @@ public sealed class BSLinksetCompound : BSLinkset // Constraint linksets are rebuilt every time. // Note that this works for rebuilding just the root after a linkset is taken apart. // Called at taint time!! - private bool disableCOM = false; // disable until we get this debugged + private bool disableCOM = true; // disable until we get this debugged private void RecomputeLinksetCompound() { try -- cgit v1.1 From a345a2feb794d05dcb628aa916569b19394c2337 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 27 Jan 2013 10:31:08 -0800 Subject: BulletSim: add framework for BulletSim unit tests. No tests yet. --- .../Physics/BulletSPlugin/Tests/BasicVehicles.cs | 56 +++++++++++++++ .../Physics/BulletSPlugin/Tests/BulletSimTests.cs | 56 +++++++++++++++ .../BulletSPlugin/Tests/BulletSimTestsUtil.cs | 81 ++++++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100755 OpenSim/Region/Physics/BulletSPlugin/Tests/BasicVehicles.cs create mode 100755 OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTests.cs create mode 100755 OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/Tests/BasicVehicles.cs b/OpenSim/Region/Physics/BulletSPlugin/Tests/BasicVehicles.cs new file mode 100755 index 0000000..41ef67b --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/Tests/BasicVehicles.cs @@ -0,0 +1,56 @@ +/* + * 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 copyright + * 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 NUnit.Framework; +using log4net; + +using OpenSim.Tests.Common; + +namespace OpenSim.Region.Physics.BulletSPlugin.Tests +{ +[TestFixture] +public class BasicVehicles : OpenSimTestCase +{ + // Documentation on attributes: http://www.nunit.org/index.php?p=attributes&r=2.6.1 + // Documentation on assertions: http://www.nunit.org/index.php?p=assertions&r=2.6.1 + + [TestFixtureSetUp] + public void Init() + { + } + + [TestFixtureTearDown] + public void TearDown() + { + } +} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTests.cs b/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTests.cs new file mode 100755 index 0000000..35cbc1d --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTests.cs @@ -0,0 +1,56 @@ +/* + * 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 copyright + * 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 NUnit.Framework; +using log4net; + +using OpenSim.Tests.Common; + +namespace OpenSim.Region.Physics.BulletSPlugin.Tests +{ +[TestFixture] +public class BulletSimTests : OpenSimTestCase +{ + // Documentation on attributes: http://www.nunit.org/index.php?p=attributes&r=2.6.1 + // Documentation on assertions: http://www.nunit.org/index.php?p=assertions&r=2.6.1 + + [TestFixtureSetUp] + public void Init() + { + } + + [TestFixtureTearDown] + public void TearDown() + { + } +} +} diff --git a/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs b/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs new file mode 100755 index 0000000..6c2247a --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs @@ -0,0 +1,81 @@ +/* + * 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 copyright + * 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 Nini.Config; + +using OpenSim.Framework; +using OpenSim.Region.Physics.BulletSPlugin; +using OpenSim.Region.Physics.Meshing; + +namespace OpenSim.Region.Physics.BulletSPlugin.Tests +{ +// Utility functions for building up and tearing down the sample physics environments +public static class BulletSimTestsUtil +{ + // 'engineName' is the Bullet engine to use. Either null (for unmanaged), "BulletUnmanaged" or "BulletXNA" + // 'params' is a set of keyValue pairs to set in the engine's configuration file (override defaults) + // May be 'null' if there are no overrides. + public static BSScene CreateBasicPhysicsEngine(string engineName, Dictionary paramOverrides) + { + if (engineName == null) + engineName = "BulletUnmanaged"; + + IConfigSource openSimINI = new IniConfigSource(); + IConfig startupConfig = openSimINI.AddConfig("StartUp"); + startupConfig.Set("meshing", "Meshmerizer"); + startupConfig.Set("physics", "BulletSim"); + + IConfig bulletSimConfig = openSimINI.AddConfig("BulletSim"); + bulletSimConfig.Set("BulletEngine", engineName); + if (paramOverrides != null) + { + foreach (KeyValuePair kvp in paramOverrides) + { + bulletSimConfig.Set(kvp.Key, kvp.Value); + } + } + // bulletSimConfig.Set("PhysicsLoggingEnabled","True"); + // bulletSimConfig.Set("PhysicsLoggingDoFlush","True"); + // bulletSimConfig.Set("VehicleLoggingEnabled","True"); + + BSPlugin bsPlugin = new BSPlugin(); + + BSScene bsScene = (BSScene)bsPlugin.GetScene("BSTestRegion"); + + Meshing.Meshmerizer mesher = new Meshmerizer(openSimINI); + bsScene.Initialise(mesher, openSimINI); + + return bsScene; + } + +} +} -- cgit v1.1 From 26d4596080295d7509ef16bce9eb571d326c3ba6 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 27 Jan 2013 12:48:16 -0800 Subject: BulletSim: reinstate the supression of rotational velocity for vehicles --- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 17fddd7..998836c 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -1620,7 +1620,7 @@ public sealed class BSPrim : BSPhysObject // TODO: handle physics introduced by Bullet with computed vehicle physics. if (_vehicle.IsActive) { - // entprop.RotationalVelocity = OMV.Vector3.Zero; + entprop.RotationalVelocity = OMV.Vector3.Zero; } // DetailLog("{0},BSPrim.UpdateProperties,entry,entprop={1}", LocalID, entprop); // DEBUG DEBUG -- cgit v1.1 From b546af9ac290951f22e8c8e56798adb176076591 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 27 Jan 2013 12:48:36 -0800 Subject: BulletSim: simplify the initialization of some of the parameters. Disable vertical attraction for vehicles by default (for the moment). Fix bug where vehicle would go crazy when velocity got above a certain speed. --- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 19 ++++++++---- OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 36 ++++++---------------- 2 files changed, 23 insertions(+), 32 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 90482fd..94194b0 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -141,7 +141,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin // in changes by making enablement of debugging flags from INI file. public void SetupVehicleDebugging() { - enableAngularVerticalAttraction = true; + enableAngularVerticalAttraction = false; enableAngularDeflection = false; enableAngularBanking = false; if (BSParam.VehicleDebuggingEnabled != ConfigurationParameters.numericFalse) @@ -803,7 +803,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin m_knownVelocity = Prim.ForceVelocity; m_knownHas |= m_knownChangedVelocity; } - return (Vector3)m_knownVelocity; + return m_knownVelocity; } set { @@ -926,6 +926,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Called after the simulation step internal void PostStep(float pTimestep) { + if (!IsActive) return; + if (PhysicsScene.VehiclePhysicalLoggingEnabled) PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody); } @@ -961,10 +963,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin // ================================================================== // Clamp high or low velocities float newVelocityLengthSq = VehicleVelocity.LengthSquared(); - if (newVelocityLengthSq > BSParam.VehicleMaxLinearVelocity) + if (newVelocityLengthSq > BSParam.VehicleMaxLinearVelocitySq) { + Vector3 origVelW = VehicleVelocity; // DEBUG DEBUG VehicleVelocity /= VehicleVelocity.Length(); VehicleVelocity *= BSParam.VehicleMaxLinearVelocity; + VDetailLog("{0}, MoveLinear,clampMax,origVelW={1},lenSq={2},maxVelSq={3},,newVelW={4}", + Prim.LocalID, origVelW, newVelocityLengthSq, BSParam.VehicleMaxLinearVelocitySq, VehicleVelocity); } else if (newVelocityLengthSq < 0.001f) VehicleVelocity = Vector3.Zero; @@ -1301,6 +1306,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin if (enableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff) { Vector3 vertContributionV = Vector3.Zero; + Vector3 origRotVelW = VehicleRotationalVelocity; // DEBUG DEBUG // Take a vector pointing up and convert it from world to vehicle relative coords. Vector3 verticalError = Vector3.UnitZ * VehicleOrientation; @@ -1328,13 +1334,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin // 'vertContrbution' is now the necessary angular correction to correct tilt in one second. // Correction happens over a number of seconds. - Vector3 unscaledContrib = vertContributionV; // DEBUG DEBUG + Vector3 unscaledContribVerticalErrorV = vertContributionV; // DEBUG DEBUG vertContributionV /= m_verticalAttractionTimescale; VehicleRotationalVelocity += vertContributionV * VehicleOrientation; - VDetailLog("{0}, MoveAngular,verticalAttraction,,verticalError={1},unscaled={2},eff={3},ts={4},vertAttr={5}", - Prim.LocalID, verticalError, unscaledContrib, m_verticalAttractionEfficiency, m_verticalAttractionTimescale, vertContributionV); + VDetailLog("{0}, MoveAngular,verticalAttraction,,origRotVW={1},vertError={2},unscaledV={3},eff={4},ts={5},vertContribV={6}", + Prim.LocalID, origRotVelW, verticalError, unscaledContribVerticalErrorV, + m_verticalAttractionEfficiency, m_verticalAttractionTimescale, vertContributionV); } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index 75eed86..4ece944 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs @@ -84,32 +84,16 @@ public static class BSParam // Vehicle parameters public static float VehicleMaxLinearVelocity { get; private set; } + public static float VehicleMaxLinearVelocitySq { get; private set; } public static float VehicleMaxAngularVelocity { get; private set; } + public static float VehicleMaxAngularVelocitySq { get; private set; } public static float VehicleAngularDamping { get; private set; } public static float VehicleFriction { get; private set; } public static float VehicleRestitution { get; private set; } public static float VehicleLinearFactor { get; private set; } - private static Vector3? vehicleLinearFactorV; - public static Vector3 VehicleLinearFactorV - { - get - { - if (!vehicleLinearFactorV.HasValue) - vehicleLinearFactorV = new Vector3(VehicleLinearFactor, VehicleLinearFactor, VehicleLinearFactor); - return (Vector3)vehicleLinearFactorV; - } - } + public static Vector3 VehicleLinearFactorV { get; private set; } public static float VehicleAngularFactor { get; private set; } - private static Vector3? vehicleAngularFactorV; - public static Vector3 VehicleAngularFactorV - { - get - { - if (!vehicleAngularFactorV.HasValue) - vehicleAngularFactorV = new Vector3(VehicleAngularFactor, VehicleAngularFactor, VehicleAngularFactor); - return (Vector3)vehicleAngularFactorV; - } - } + public static Vector3 VehicleAngularFactorV { get; private set; } public static float VehicleGroundGravityFudge { get; private set; } public static float VehicleDebuggingEnabled { get; private set; } @@ -469,12 +453,12 @@ public static class BSParam 1000.0f, (s,cf,p,v) => { VehicleMaxLinearVelocity = cf.GetFloat(p, v); }, (s) => { return (float)VehicleMaxLinearVelocity; }, - (s,p,l,v) => { VehicleMaxLinearVelocity = v; } ), + (s,p,l,v) => { VehicleMaxLinearVelocity = v; VehicleMaxLinearVelocitySq = v * v; } ), new ParameterDefn("VehicleMaxAngularVelocity", "Maximum rotational velocity magnitude that can be assigned to a vehicle", 12.0f, (s,cf,p,v) => { VehicleMaxAngularVelocity = cf.GetFloat(p, v); }, (s) => { return (float)VehicleMaxAngularVelocity; }, - (s,p,l,v) => { VehicleMaxAngularVelocity = v; } ), + (s,p,l,v) => { VehicleMaxAngularVelocity = v; VehicleMaxAngularVelocitySq = v * v; } ), new ParameterDefn("VehicleAngularDamping", "Factor to damp vehicle angular movement per second (0.0 - 1.0)", 0.0f, (s,cf,p,v) => { VehicleAngularDamping = cf.GetFloat(p, v); }, @@ -484,24 +468,24 @@ public static class BSParam 1.0f, (s,cf,p,v) => { VehicleLinearFactor = cf.GetFloat(p, v); }, (s) => { return VehicleLinearFactor; }, - (s,p,l,v) => { VehicleLinearFactor = v; } ), + (s,p,l,v) => { VehicleLinearFactor = v; VehicleLinearFactorV = new Vector3(v, v, v); } ), new ParameterDefn("VehicleAngularFactor", "Fraction of physical angular changes applied to vehicle (0.0 - 1.0)", 1.0f, (s,cf,p,v) => { VehicleAngularFactor = cf.GetFloat(p, v); }, (s) => { return VehicleAngularFactor; }, - (s,p,l,v) => { VehicleAngularFactor = v; } ), + (s,p,l,v) => { VehicleAngularFactor = v; VehicleAngularFactorV = new Vector3(v, v, v); } ), new ParameterDefn("VehicleFriction", "Friction of vehicle on the ground (0.0 - 1.0)", 0.0f, (s,cf,p,v) => { VehicleFriction = cf.GetFloat(p, v); }, (s) => { return VehicleFriction; }, (s,p,l,v) => { VehicleFriction = v; } ), new ParameterDefn("VehicleRestitution", "Bouncyness factor for vehicles (0.0 - 1.0)", - 0.2f, + 0.0f, (s,cf,p,v) => { VehicleRestitution = cf.GetFloat(p, v); }, (s) => { return VehicleRestitution; }, (s,p,l,v) => { VehicleRestitution = v; } ), new ParameterDefn("VehicleGroundGravityFudge", "Factor to multiple gravity if a ground vehicle is probably on the ground (0.0 - 1.0)", - 1.0f, + 0.2f, (s,cf,p,v) => { VehicleGroundGravityFudge = cf.GetFloat(p, v); }, (s) => { return VehicleGroundGravityFudge; }, (s,p,l,v) => { VehicleGroundGravityFudge = v; } ), -- cgit v1.1 From f6380a3ad3ee9479886415a117849eb5bd3f40f7 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 28 Jan 2013 09:02:01 -0800 Subject: BulletSim: fix the trimming of colliders so only the top 25 are returned. --- OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 4 ++-- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 86eb773..b23be91 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -708,8 +708,8 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters } List orderedPrims = new List(PhysObjects.Values); - orderedPrims.OrderByDescending(p => p.CollisionScore).Take(25); - topColliders = orderedPrims.ToDictionary(p => p.LocalID, p => p.CollisionScore); + orderedPrims.OrderByDescending(p => p.CollisionScore); + topColliders = orderedPrims.Take(25).ToDictionary(p => p.LocalID, p => p.CollisionScore); } return topColliders; diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 02a0b15..6d7f079 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -4096,8 +4096,8 @@ namespace OpenSim.Region.Physics.OdePlugin lock (_prims) { List orderedPrims = new List(_prims); - orderedPrims.OrderByDescending(p => p.CollisionScore).Take(25); - topColliders = orderedPrims.ToDictionary(p => p.LocalID, p => p.CollisionScore); + orderedPrims.OrderByDescending(p => p.CollisionScore); + topColliders = orderedPrims.Take(25).ToDictionary(p => p.LocalID, p => p.CollisionScore); foreach (OdePrim p in _prims) p.CollisionScore = 0; -- cgit v1.1 From e4c6a19940fe0bb4dfce7fa53de282bdd6fbfb08 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 28 Jan 2013 15:11:20 -0800 Subject: BulletSim: rename 'uint' to 'UInt32' to make clear the type that is passed to unmanaged code. --- .../Region/Physics/BulletSPlugin/BSApiTemplate.cs | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs index f25b447..abbd22c 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs @@ -87,7 +87,7 @@ public enum FixedShapeKey : ulong [StructLayout(LayoutKind.Sequential)] public struct ShapeData { - public uint ID; + public UInt32 ID; public BSPhysicsShapeType Type; public Vector3 Position; public Quaternion Rotation; @@ -111,7 +111,7 @@ public struct ShapeData [StructLayout(LayoutKind.Sequential)] public struct SweepHit { - public uint ID; + public UInt32 ID; public float Fraction; public Vector3 Normal; public Vector3 Point; @@ -119,15 +119,15 @@ public struct SweepHit [StructLayout(LayoutKind.Sequential)] public struct RaycastHit { - public uint ID; + public UInt32 ID; public float Fraction; public Vector3 Normal; } [StructLayout(LayoutKind.Sequential)] public struct CollisionDesc { - public uint aID; - public uint bID; + public UInt32 aID; + public UInt32 bID; public Vector3 point; public Vector3 normal; public float penetration; @@ -135,7 +135,7 @@ public struct CollisionDesc [StructLayout(LayoutKind.Sequential)] public struct EntityProperties { - public uint ID; + public UInt32 ID; public Vector3 Position; public Quaternion Rotation; public Vector3 Velocity; @@ -325,7 +325,7 @@ public abstract BulletWorld Initialize(Vector3 maxPosition, ConfigurationParamet public abstract int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep, out int updatedEntityCount, out int collidersCount); -public abstract bool UpdateParameter(BulletWorld world, uint localID, String parm, float value); +public abstract bool UpdateParameter(BulletWorld world, UInt32 localID, String parm, float value); public abstract void Shutdown(BulletWorld sim); @@ -366,24 +366,24 @@ public abstract void UpdateChildTransform(BulletShape pShape, int childIndex, Ve public abstract void RecalculateCompoundShapeLocalAabb(BulletShape cShape); -public abstract BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id); +public abstract BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, UInt32 id); public abstract bool DeleteCollisionShape(BulletWorld world, BulletShape shape); public abstract CollisionObjectTypes GetBodyType(BulletBody obj); -public abstract BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot); +public abstract BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, UInt32 id, Vector3 pos, Quaternion rot); -public abstract BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot); +public abstract BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, UInt32 id, Vector3 pos, Quaternion rot); -public abstract BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot); +public abstract BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, UInt32 id, Vector3 pos, Quaternion rot); public abstract void DestroyObject(BulletWorld sim, BulletBody obj); // ===================================================================================== -public abstract BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin); +public abstract BulletShape CreateGroundPlaneShape(UInt32 id, float height, float collisionMargin); -public abstract BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap, +public abstract BulletShape CreateTerrainShape(UInt32 id, Vector3 size, float minHeight, float maxHeight, float[] heightMap, float scaleFactor, float collisionMargin); // ===================================================================================== @@ -629,7 +629,7 @@ public abstract BulletConstraint GetConstraintRef(BulletBody obj, int index); public abstract int GetNumConstraintRefs(BulletBody obj); -public abstract bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask); +public abstract bool SetCollisionGroupMask(BulletBody body, UInt32 filter, UInt32 mask); // ===================================================================================== // btCollisionShape entries -- cgit v1.1 From e9aff0a91d6a4d02498ce45759389bb09b34fcbc Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 28 Jan 2013 15:11:50 -0800 Subject: BulletSim: do not zero an avatar's standing velocity if it is standing on a moving object. Rearrange pre/post action subscription code to put more in locks. Add meshmerizer params to BulletSimTestUtil scene creation (and fix line endings). Rebuilt version of DLLs and SOs with cleaned up code and no profiling for sure. --- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 13 +- .../Region/Physics/BulletSPlugin/BSPhysObject.cs | 33 ++-- .../BulletSPlugin/Tests/BulletSimTestsUtil.cs | 168 +++++++++++---------- 3 files changed, 118 insertions(+), 96 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 7603254..3884a5d 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -56,7 +56,6 @@ public sealed class BSCharacter : BSPhysObject private int _physicsActorType; private bool _isPhysical; private bool _flying; - private bool _wasWalking; // 'true' if the avatar was walking/moving last frame private bool _setAlwaysRun; private bool _throttleUpdates; private bool _floatOnWater; @@ -84,7 +83,6 @@ public sealed class BSCharacter : BSPhysObject _position = pos; _flying = isFlying; - _wasWalking = true; // causes first step to initialize standing _orientation = OMV.Quaternion.Identity; _velocity = OMV.Vector3.Zero; _buoyancy = ComputeBuoyancyFromFlying(isFlying); @@ -220,7 +218,13 @@ public sealed class BSCharacter : BSPhysObject { // The avatar shouldn't be moving _velocityMotor.Zero(); - ZeroMotion(true /* inTaintTime */); + + // If we are colliding with a stationary object, presume we're standing and don't move around + if (!ColliderIsMoving) + { + DetailLog("{0},BSCharacter.MoveMotor,collidingWithStationary,zeroingMotion", LocalID); + ZeroMotion(true /* inTaintTime */); + } // Standing has more friction on the ground if (_currentFriction != BSParam.AvatarStandingFriction) @@ -229,8 +233,6 @@ public sealed class BSCharacter : BSPhysObject PhysicsScene.PE.SetFriction(PhysBody, _currentFriction); } DetailLog("{0},BSCharacter.MoveMotor,taint,stopping,target={1}", LocalID, _velocityMotor.TargetValue); - - _wasWalking = false; } else { @@ -260,7 +262,6 @@ public sealed class BSCharacter : BSPhysObject DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", LocalID, stepVelocity, _velocity, Mass, moveForce); PhysicsScene.PE.ApplyCentralImpulse(PhysBody, moveForce); - _wasWalking = true; } }); } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 5e8143c..a113530 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -96,6 +96,7 @@ public abstract class BSPhysObject : PhysicsActor CollidingStep = 0; CollidingGroundStep = 0; CollisionAccumulation = 0; + ColliderIsMoving = false; CollisionScore = 0; } @@ -177,13 +178,14 @@ public abstract class BSPhysObject : PhysicsActor public abstract OMV.Vector3 RawPosition { get; set; } public abstract OMV.Vector3 ForcePosition { get; set; } - // Position is what the simulator thinks the positions of the prim is. + // 'Position' and 'Orientation' is what the simulator thinks the positions of the prim is. // Because Bullet needs the zero coordinate to be the center of mass of the linkset, // sometimes it is necessary to displace the position the physics engine thinks // the position is. PositionDisplacement must be added and removed from the // position as the simulator position is stored and fetched from the physics - // engine. + // engine. Similar to OrientationDisplacement. public virtual OMV.Vector3 PositionDisplacement { get; set; } + public virtual OMV.Quaternion OrientationDisplacement { get; set; } public abstract OMV.Quaternion RawOrientation { get; set; } public abstract OMV.Quaternion ForceOrientation { get; set; } @@ -240,6 +242,9 @@ public abstract class BSPhysObject : PhysicsActor protected long CollidingObjectStep { get; set; } // The collision flags we think are set in Bullet protected CollisionFlags CurrentCollisionFlags { get; set; } + // On a collision, check the collider and remember if the last collider was moving + // Used to modify the standing of avatars (avatars on stationary things stand still) + protected bool ColliderIsMoving; // Count of collisions for this object protected long CollisionAccumulation { get; set; } @@ -307,7 +312,10 @@ public abstract class BSPhysObject : PhysicsActor CollisionAccumulation++; - // if someone has subscribed for collision events.... + // For movement tests, remember if we are colliding with an object that is moving. + ColliderIsMoving = collidee != null ? collidee.RawVelocity != OMV.Vector3.Zero : false; + + // If someone has subscribed for collision events log the collision so it will be reported up if (SubscribedEvents()) { CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); DetailLog("{0},{1}.Collison.AddCollider,call,with={2},point={3},normal={4},depth={5}", @@ -393,12 +401,13 @@ public abstract class BSPhysObject : PhysicsActor public override bool SubscribedEvents() { return (SubscribedEventsMs > 0); } - // Because 'CollisionScore' is calls many times while sorting it should not be recomputed + // Because 'CollisionScore' is called many times while sorting, it should not be recomputed // each time called. So this is built to be light weight for each collision and to do // all the processing when the user asks for the info. public void ComputeCollisionScore() { - // Scale the collision count by the time since the last collision + // Scale the collision count by the time since the last collision. + // The "+1" prevents dividing by zero. long timeAgo = PhysicsScene.SimulationStep - CollidingStep + 1; CollisionScore = CollisionAccumulation / timeAgo; } @@ -423,13 +432,15 @@ public abstract class BSPhysObject : PhysicsActor UnRegisterPreStepAction(op, id); RegisteredPrestepActions[identifier] = actn; + + PhysicsScene.BeforeStep += actn; } - PhysicsScene.BeforeStep += actn; DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier); } // Unregister a pre step action. Safe to call if the action has not been registered. - protected void UnRegisterPreStepAction(string op, uint id) + // Returns 'true' if an action was actually removed + protected bool UnRegisterPreStepAction(string op, uint id) { string identifier = op + "-" + id.ToString(); bool removed = false; @@ -443,6 +454,7 @@ public abstract class BSPhysObject : PhysicsActor } } DetailLog("{0},BSPhysObject.UnRegisterPreStepAction,id={1},removed={2}", LocalID, identifier, removed); + return removed; } protected void UnRegisterAllPreStepActions() @@ -468,13 +480,15 @@ public abstract class BSPhysObject : PhysicsActor UnRegisterPostStepAction(op, id); RegisteredPoststepActions[identifier] = actn; + + PhysicsScene.AfterStep += actn; } - PhysicsScene.AfterStep += actn; DetailLog("{0},BSPhysObject.RegisterPostStepAction,id={1}", LocalID, identifier); } // Unregister a pre step action. Safe to call if the action has not been registered. - protected void UnRegisterPostStepAction(string op, uint id) + // Returns 'true' if an action was actually removed. + protected bool UnRegisterPostStepAction(string op, uint id) { string identifier = op + "-" + id.ToString(); bool removed = false; @@ -488,6 +502,7 @@ public abstract class BSPhysObject : PhysicsActor } } DetailLog("{0},BSPhysObject.UnRegisterPostStepAction,id={1},removed={2}", LocalID, identifier, removed); + return removed; } protected void UnRegisterAllPostStepActions() diff --git a/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs b/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs index 6c2247a..e7657f9 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs @@ -1,81 +1,87 @@ -/* - * 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 copyright - * 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 Nini.Config; - -using OpenSim.Framework; -using OpenSim.Region.Physics.BulletSPlugin; -using OpenSim.Region.Physics.Meshing; - -namespace OpenSim.Region.Physics.BulletSPlugin.Tests -{ -// Utility functions for building up and tearing down the sample physics environments -public static class BulletSimTestsUtil -{ - // 'engineName' is the Bullet engine to use. Either null (for unmanaged), "BulletUnmanaged" or "BulletXNA" - // 'params' is a set of keyValue pairs to set in the engine's configuration file (override defaults) - // May be 'null' if there are no overrides. - public static BSScene CreateBasicPhysicsEngine(string engineName, Dictionary paramOverrides) - { - if (engineName == null) - engineName = "BulletUnmanaged"; - - IConfigSource openSimINI = new IniConfigSource(); - IConfig startupConfig = openSimINI.AddConfig("StartUp"); - startupConfig.Set("meshing", "Meshmerizer"); - startupConfig.Set("physics", "BulletSim"); - - IConfig bulletSimConfig = openSimINI.AddConfig("BulletSim"); - bulletSimConfig.Set("BulletEngine", engineName); - if (paramOverrides != null) - { - foreach (KeyValuePair kvp in paramOverrides) - { - bulletSimConfig.Set(kvp.Key, kvp.Value); - } - } - // bulletSimConfig.Set("PhysicsLoggingEnabled","True"); - // bulletSimConfig.Set("PhysicsLoggingDoFlush","True"); - // bulletSimConfig.Set("VehicleLoggingEnabled","True"); - - BSPlugin bsPlugin = new BSPlugin(); - - BSScene bsScene = (BSScene)bsPlugin.GetScene("BSTestRegion"); - - Meshing.Meshmerizer mesher = new Meshmerizer(openSimINI); - bsScene.Initialise(mesher, openSimINI); - - return bsScene; - } - -} -} +/* + * 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 copyright + * 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 Nini.Config; + +using OpenSim.Framework; +using OpenSim.Region.Physics.BulletSPlugin; +using OpenSim.Region.Physics.Meshing; + +namespace OpenSim.Region.Physics.BulletSPlugin.Tests +{ +// Utility functions for building up and tearing down the sample physics environments +public static class BulletSimTestsUtil +{ + // 'engineName' is the Bullet engine to use. Either null (for unmanaged), "BulletUnmanaged" or "BulletXNA" + // 'params' is a set of keyValue pairs to set in the engine's configuration file (override defaults) + // May be 'null' if there are no overrides. + public static BSScene CreateBasicPhysicsEngine(Dictionary paramOverrides) + { + IConfigSource openSimINI = new IniConfigSource(); + IConfig startupConfig = openSimINI.AddConfig("StartUp"); + startupConfig.Set("physics", "BulletSim"); + startupConfig.Set("meshing", "Meshmerizer"); + startupConfig.Set("cacheSculptMaps", "false"); // meshmerizer shouldn't save maps + + IConfig bulletSimConfig = openSimINI.AddConfig("BulletSim"); + // If the caller cares, specify the bullet engine otherwise it will default to "BulletUnmanaged". + // bulletSimConfig.Set("BulletEngine", "BulletUnmanaged"); + // bulletSimConfig.Set("BulletEngine", "BulletXNA"); + bulletSimConfig.Set("MeshSculptedPrim", "false"); + bulletSimConfig.Set("ForceSimplePrimMeshing", "true"); + if (paramOverrides != null) + { + foreach (KeyValuePair kvp in paramOverrides) + { + bulletSimConfig.Set(kvp.Key, kvp.Value); + } + } + // bulletSimConfig.Set("PhysicsLoggingEnabled","True"); + // bulletSimConfig.Set("PhysicsLoggingDoFlush","True"); + // bulletSimConfig.Set("VehicleLoggingEnabled","True"); + + BSPlugin bsPlugin = new BSPlugin(); + + BSScene bsScene = (BSScene)bsPlugin.GetScene("BSTestRegion"); + + // Since the asset requestor is not initialized, any mesh or sculptie will be a cube. + // In the future, add a fake asset fetcher to get meshes and sculpts. + // bsScene.RequestAssetMethod = ???; + + Meshing.Meshmerizer mesher = new Meshmerizer(openSimINI); + bsScene.Initialise(mesher, openSimINI); + + return bsScene; + } + +} +} -- cgit v1.1 From 531d0429d1cc49a1959f6f7a0028ed3111dd6bd4 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 28 Jan 2013 17:08:34 -0800 Subject: BulletSim: first unit test: vehicle angular attraction --- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 12 +- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 32 ++-- OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 2 +- .../Physics/BulletSPlugin/Tests/BasicVehicles.cs | 181 ++++++++++++++------- .../BulletSPlugin/Tests/BulletSimTestsUtil.cs | 2 +- 5 files changed, 150 insertions(+), 79 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 94194b0..05a0dcc 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -125,9 +125,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin static readonly float PIOverTwo = ((float)Math.PI) / 2f; // For debugging, flags to turn on and off individual corrections. - private bool enableAngularVerticalAttraction; - private bool enableAngularDeflection; - private bool enableAngularBanking; + public bool enableAngularVerticalAttraction; + public bool enableAngularDeflection; + public bool enableAngularBanking; public BSDynamics(BSScene myScene, BSPrim myPrim) { @@ -165,7 +165,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin } #region Vehicle parameter setting - internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue) + public void ProcessFloatVehicleParam(Vehicle pParam, float pValue) { VDetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue); switch (pParam) @@ -677,13 +677,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin private const int m_knownChangedWaterLevel = 1 << 9; private const int m_knownChangedForwardVelocity = 1 <<10; - private void ForgetKnownVehicleProperties() + public void ForgetKnownVehicleProperties() { m_knownHas = 0; m_knownChanged = 0; } // Push all the changed values back into the physics engine - private void PushKnownChanged() + public void PushKnownChanged() { if (m_knownChanged != 0) { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 998836c..2b0a539 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -73,7 +73,7 @@ public sealed class BSPrim : BSPhysObject private bool _kinematic; private float _buoyancy; - private BSDynamics _vehicle; + public BSDynamics VehicleController { get; private set; } private BSVMotor _targetMotor; private OMV.Vector3 _PIDTarget; @@ -107,7 +107,7 @@ public sealed class BSPrim : BSPhysObject _friction = PhysicsScene.Params.defaultFriction; _restitution = PhysicsScene.Params.defaultRestitution; - _vehicle = new BSDynamics(PhysicsScene, this); // add vehicleness + VehicleController = new BSDynamics(PhysicsScene, this); // add vehicleness _mass = CalculateMass(); @@ -512,7 +512,7 @@ public sealed class BSPrim : BSPhysObject public override int VehicleType { get { - return (int)_vehicle.Type; // if we are a vehicle, return that type + return (int)VehicleController.Type; // if we are a vehicle, return that type } set { Vehicle type = (Vehicle)value; @@ -521,19 +521,19 @@ public sealed 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. - _vehicle.ProcessTypeChange(type); + VehicleController.ProcessTypeChange(type); ActivateIfPhysical(false); // If an active vehicle, register the vehicle code to be called before each step - if (_vehicle.Type == Vehicle.TYPE_NONE) + if (VehicleController.Type == Vehicle.TYPE_NONE) { UnRegisterPreStepAction("BSPrim.Vehicle", LocalID); - PhysicsScene.AfterStep -= _vehicle.PostStep; + PhysicsScene.AfterStep -= VehicleController.PostStep; } else { - RegisterPreStepAction("BSPrim.Vehicle", LocalID, _vehicle.Step); - PhysicsScene.AfterStep += _vehicle.PostStep; + RegisterPreStepAction("BSPrim.Vehicle", LocalID, VehicleController.Step); + PhysicsScene.AfterStep += VehicleController.PostStep; } }); } @@ -542,7 +542,7 @@ public sealed class BSPrim : BSPhysObject { PhysicsScene.TaintedObject("BSPrim.VehicleFloatParam", delegate() { - _vehicle.ProcessFloatVehicleParam((Vehicle)param, value); + VehicleController.ProcessFloatVehicleParam((Vehicle)param, value); ActivateIfPhysical(false); }); } @@ -550,7 +550,7 @@ public sealed class BSPrim : BSPhysObject { PhysicsScene.TaintedObject("BSPrim.VehicleVectorParam", delegate() { - _vehicle.ProcessVectorVehicleParam((Vehicle)param, value); + VehicleController.ProcessVectorVehicleParam((Vehicle)param, value); ActivateIfPhysical(false); }); } @@ -558,7 +558,7 @@ public sealed class BSPrim : BSPhysObject { PhysicsScene.TaintedObject("BSPrim.VehicleRotationParam", delegate() { - _vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation); + VehicleController.ProcessRotationVehicleParam((Vehicle)param, rotation); ActivateIfPhysical(false); }); } @@ -566,7 +566,7 @@ public sealed class BSPrim : BSPhysObject { PhysicsScene.TaintedObject("BSPrim.VehicleFlags", delegate() { - _vehicle.ProcessVehicleFlags(param, remove); + VehicleController.ProcessVehicleFlags(param, remove); }); } @@ -747,7 +747,7 @@ public sealed class BSPrim : BSPhysObject // isSolid: other objects bounce off of this object // isVolumeDetect: other objects pass through but can generate collisions // collisionEvents: whether this object returns collision events - private void UpdatePhysicalParameters() + public void UpdatePhysicalParameters() { // DetailLog("{0},BSPrim.UpdatePhysicalParameters,entry,body={1},shape={2}", LocalID, BSBody, BSShape); @@ -759,7 +759,7 @@ public sealed class BSPrim : BSPhysObject MakeDynamic(IsStatic); // Update vehicle specific parameters (after MakeDynamic() so can change physical parameters) - _vehicle.Refresh(); + VehicleController.Refresh(); // Arrange for collision events if the simulator wants them EnableCollisions(SubscribedEvents()); @@ -1601,7 +1601,7 @@ public sealed class BSPrim : BSPhysObject // Remove all the physical dependencies on the old body. // (Maybe someday make the changing of BSShape an event to be subscribed to by BSLinkset, ...) Linkset.RemoveBodyDependencies(this); - _vehicle.RemoveBodyDependencies(this); + VehicleController.RemoveBodyDependencies(this); }); // Make sure the properties are set on the new object @@ -1618,7 +1618,7 @@ public sealed class BSPrim : BSPhysObject { // A temporary kludge to suppress the rotational effects introduced on vehicles by Bullet // TODO: handle physics introduced by Bullet with computed vehicle physics. - if (_vehicle.IsActive) + if (VehicleController.IsActive) { entprop.RotationalVelocity = OMV.Vector3.Zero; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index b23be91..a4690ba 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -855,7 +855,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters { DetailLog("{0},BSScene.AssertInTaintTime,NOT IN TAINT TIME,Region={1},Where={2}", DetailLogZero, RegionName, whereFrom); m_log.ErrorFormat("{0} NOT IN TAINT TIME!! Region={1}, Where={2}", LogHeader, RegionName, whereFrom); - Util.PrintCallStack(DetailLog); + // Util.PrintCallStack(DetailLog); } return InTaintTime; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/Tests/BasicVehicles.cs b/OpenSim/Region/Physics/BulletSPlugin/Tests/BasicVehicles.cs index 41ef67b..5900103 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/Tests/BasicVehicles.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/Tests/BasicVehicles.cs @@ -1,56 +1,127 @@ -/* - * 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 copyright - * 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 NUnit.Framework; -using log4net; - -using OpenSim.Tests.Common; - -namespace OpenSim.Region.Physics.BulletSPlugin.Tests -{ -[TestFixture] -public class BasicVehicles : OpenSimTestCase -{ - // Documentation on attributes: http://www.nunit.org/index.php?p=attributes&r=2.6.1 - // Documentation on assertions: http://www.nunit.org/index.php?p=assertions&r=2.6.1 - - [TestFixtureSetUp] - public void Init() - { - } - - [TestFixtureTearDown] - public void TearDown() - { - } -} +/* + * 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 copyright + * 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 NUnit.Framework; +using log4net; + +using OpenSim.Framework; +using OpenSim.Region.Physics.BulletSPlugin; +using OpenSim.Region.Physics.Manager; +using OpenSim.Tests.Common; + +using OpenMetaverse; + +namespace OpenSim.Region.Physics.BulletSPlugin.Tests +{ +[TestFixture] +public class BasicVehicles : OpenSimTestCase +{ + // Documentation on attributes: http://www.nunit.org/index.php?p=attributes&r=2.6.1 + // Documentation on assertions: http://www.nunit.org/index.php?p=assertions&r=2.6.1 + + BSScene PhysicsScene { get; set; } + BSPrim TestVehicle { get; set; } + Vector3 TestVehicleInitPosition { get; set; } + float timeStep = 0.089f; + + [TestFixtureSetUp] + public void Init() + { + Dictionary engineParams = new Dictionary(); + PhysicsScene = BulletSimTestsUtil.CreateBasicPhysicsEngine(engineParams); + + PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateSphere(); + Vector3 pos = new Vector3(100.0f, 100.0f, 0f); + pos.Z = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos) + 2f; + TestVehicleInitPosition = pos; + Vector3 size = new Vector3(1f, 1f, 1f); + pbs.Scale = size; + Quaternion rot = Quaternion.Identity; + bool isPhys = false; + uint localID = 123; + + PhysicsScene.AddPrimShape("testPrim", pbs, pos, size, rot, isPhys, localID); + TestVehicle = (BSPrim)PhysicsScene.PhysObjects[localID]; + // The actual prim shape creation happens at taint time + PhysicsScene.ProcessTaints(); + + } + + [TestFixtureTearDown] + public void TearDown() + { + if (PhysicsScene != null) + { + // The Dispose() will also free any physical objects in the scene + PhysicsScene.Dispose(); + PhysicsScene = null; + } + } + + [TestCase(25, 0.25f, 0.25f, 0.25f)] + [TestCase(25, -0.25f, 0.25f, 0.25f)] + [TestCase(25, 0.25f, -0.25f, 0.25f)] + [TestCase(25, -0.25f, -0.25f, 0.25f)] + public void VerticalAttraction(int simSteps, float initRoll, float initPitch, float initYaw) + { + Quaternion initOrientation = Quaternion.CreateFromEulers(initRoll, initPitch, initYaw); + TestVehicle.Orientation = initOrientation; + + TestVehicle.Position = TestVehicleInitPosition; + + // The vehicle controller is not enabled directly (set a vehicle type). + // 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, 0.2f); + TestVehicle.VehicleController.ProcessFloatVehicleParam(Vehicle.VERTICAL_ATTRACTION_TIMESCALE, 2f); + TestVehicle.VehicleController.enableAngularVerticalAttraction = true; + + TestVehicle.IsPhysical = true; + PhysicsScene.ProcessTaints(); + + // Step the simulator a bunch of times and and vertical attraction should orient the vehicle up + for (int ii = 0; ii < simSteps; ii++) + { + TestVehicle.VehicleController.ForgetKnownVehicleProperties(); + TestVehicle.VehicleController.ComputeAngularVerticalAttraction(); + TestVehicle.VehicleController.PushKnownChanged(); + + PhysicsScene.Simulate(timeStep); + } + + // After these steps, the vehicle should be upright + Vector3 upPointer = Vector3.UnitZ * TestVehicle.Orientation; + Assert.That(upPointer.Z, Is.GreaterThan(0.99f)); + } +} } \ No newline at end of file diff --git a/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs b/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs index e7657f9..215e92f 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/Tests/BulletSimTestsUtil.cs @@ -47,7 +47,7 @@ public static class BulletSimTestsUtil public static BSScene CreateBasicPhysicsEngine(Dictionary paramOverrides) { IConfigSource openSimINI = new IniConfigSource(); - IConfig startupConfig = openSimINI.AddConfig("StartUp"); + IConfig startupConfig = openSimINI.AddConfig("Startup"); startupConfig.Set("physics", "BulletSim"); startupConfig.Set("meshing", "Meshmerizer"); startupConfig.Set("cacheSculptMaps", "false"); // meshmerizer shouldn't save maps -- cgit v1.1 From 47f09ed4c1d6a5d9763b6d1f5f86169e452281c8 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 28 Jan 2013 17:21:13 -0800 Subject: BulletSim: enable angular vertical attraction. Increase terrain collision margin to help vehicles from tunneling into same. --- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 4 ++-- OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 05a0dcc..05ab180 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -141,12 +141,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin // in changes by making enablement of debugging flags from INI file. public void SetupVehicleDebugging() { - enableAngularVerticalAttraction = false; + enableAngularVerticalAttraction = true; enableAngularDeflection = false; enableAngularBanking = false; if (BSParam.VehicleDebuggingEnabled != ConfigurationParameters.numericFalse) { - enableAngularVerticalAttraction = false; + enableAngularVerticalAttraction = true; enableAngularDeflection = false; enableAngularBanking = false; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index 4ece944..8c098b2 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs @@ -383,7 +383,7 @@ public static class BSParam (s) => { return TerrainRestitution; }, (s,p,l,v) => { TerrainRestitution = v; /* TODO: set on real terrain */ } ), new ParameterDefn("TerrainCollisionMargin", "Margin where collision checking starts" , - 0.04f, + 0.08f, (s,cf,p,v) => { TerrainCollisionMargin = cf.GetFloat(p, v); }, (s) => { return TerrainCollisionMargin; }, (s,p,l,v) => { TerrainCollisionMargin = v; /* TODO: set on real terrain */ } ), -- cgit v1.1