From 5685b33071c683c41643fcb78d6f8a28d98db468 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 26 Nov 2012 10:47:34 -0800 Subject: [PATCH 1/2] BulletSim: increase vehicle stability by suppressing Bullet's update to angular velocity. --- .../Physics/BulletSPlugin/BSDynamics.cs | 21 +++++--- .../Region/Physics/BulletSPlugin/BSPrim.cs | 52 +++---------------- .../Region/Physics/BulletSPlugin/BSScene.cs | 12 ++--- .../Physics/BulletSPlugin/BulletSimAPI.cs | 2 +- 4 files changed, 27 insertions(+), 60 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 95a41347be..6ff8a48a27 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -805,6 +805,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin // m_angularFrictionTimescale // body angular velocity decay rate // m_lastAngularVelocity // what was last applied to body + /* if (m_angularMotorDirection.LengthSquared() > 0.0001) { Vector3 origVel = m_angularMotorVelocity; @@ -823,6 +824,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin { m_angularMotorVelocity = Vector3.Zero; } + */ Vector3 angularMotorContribution = m_angularMotor.Step(pTimestep); @@ -842,15 +844,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin // verticalError.X and .Y are the World error amounts. They are 0 when there is no // error (Vehicle Body is 'vertical'), and .Z will be 1. As the body leans to its // side |.X| will increase to 1 and .Z fall to 0. As body inverts |.X| will fall - // and .Z will go // negative. Similar for tilt and |.Y|. .X and .Y must be + // and .Z will go negative. Similar for tilt and |.Y|. .X and .Y must be // modulated to prevent a stable inverted body. // Error is 0 (no error) to +/- 2 (max error) - if (verticalError.Z < 0.0f) - { - verticalError.X = 2.0f - verticalError.X; - verticalError.Y = 2.0f - verticalError.Y; - } + verticalError.X = Math.Max(-2f, Math.Min(verticalError.X, 2f)); + verticalError.Y = Math.Max(-2f, Math.Min(verticalError.Y, 2f)); + // scale it by VAservo (timestep and timescale) verticalError = verticalError * VAservo; @@ -1013,10 +1013,15 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Also remove any motion that is on the object so added motion is only from vehicle. Vector3 applyAngularForce = ((m_lastAngularVelocity * pTimestep) - Prim.ForceRotationalVelocity); + // Unscale the force by the angular factor so it overwhelmes the Bullet additions. Prim.ForceRotationalVelocity = applyAngularForce; - VDetailLog("{0},MoveAngular,done,newRotVel={1},lastAngular={2}", - Prim.LocalID, applyAngularForce, m_lastAngularVelocity); + VDetailLog("{0},MoveAngular,done,angMotor={1},vertAttr={2},bank={3},deflect={4},newAngForce={5},lastAngular={6}", + Prim.LocalID, + angularMotorContribution, verticalAttractionContribution, + bankingContribution, deflectionContribution, + applyAngularForce, m_lastAngularVelocity + ); } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index caa6c4696f..c62c79a11f 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -1380,54 +1380,16 @@ public sealed class BSPrim : BSPhysObject public override void UpdateProperties(EntityProperties entprop) { - /* - UpdatedProperties changed = 0; - // assign to the local variables so the normal set action does not happen - // if (_position != entprop.Position) - if (!_position.ApproxEquals(entprop.Position, POSITION_TOLERANCE)) - { - _position = entprop.Position; - changed |= UpdatedProperties.Position; - } - // if (_orientation != entprop.Rotation) - if (!_orientation.ApproxEquals(entprop.Rotation, ROTATION_TOLERANCE)) - { - _orientation = entprop.Rotation; - changed |= UpdatedProperties.Rotation; - } - // if (_velocity != entprop.Velocity) - if (!_velocity.ApproxEquals(entprop.Velocity, VELOCITY_TOLERANCE)) - { - _velocity = entprop.Velocity; - changed |= UpdatedProperties.Velocity; - } - // if (_acceleration != entprop.Acceleration) - if (!_acceleration.ApproxEquals(entprop.Acceleration, ACCELERATION_TOLERANCE)) - { - _acceleration = entprop.Acceleration; - changed |= UpdatedProperties.Acceleration; - } - // if (_rotationalVelocity != entprop.RotationalVelocity) - if (!_rotationalVelocity.ApproxEquals(entprop.RotationalVelocity, ROTATIONAL_VELOCITY_TOLERANCE)) - { - _rotationalVelocity = entprop.RotationalVelocity; - changed |= UpdatedProperties.RotationalVel; - } - if (changed != 0) - { - // Only update the position of single objects and linkset roots - if (Linkset.IsRoot(this)) - { - base.RequestPhysicsterseUpdate(); - } - } - */ - - // Don't check for damping here -- it's done in BulletSim and SceneObjectPart. - // Updates only for individual prims and for the root object of a linkset. if (Linkset.IsRoot(this)) { + // 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) + { + entprop.RotationalVelocity = OMV.Vector3.Zero; + } + // Assign directly to the local variables so the normal set action does not happen _position = entprop.Position; _orientation = entprop.Rotation; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 805e670c1b..09b1423586 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -515,9 +515,9 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters collidersCount = 0; } - // Don't have to use the pointers passed back since we know it is the same pinned memory we passed in + // Don't have to use the pointers passed back since we know it is the same pinned memory we passed in. - // Get a value for 'now' so all the collision and update routines don't have to get their own + // Get a value for 'now' so all the collision and update routines don't have to get their own. SimulationNowTime = Util.EnvironmentTickCount(); // If there were collisions, process them by sending the event to the prim. @@ -563,6 +563,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters ObjectsWithCollisions.Remove(po); ObjectsWithNoMoreCollisions.Clear(); } + // Done with collisions. // If any of the objects had updated properties, tell the object it has been changed by the physics engine if (updatedEntityCount > 0) @@ -586,9 +587,8 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters // The physics engine returns the number of milliseconds it simulated this call. // These are summed and normalized to one second and divided by 1000 to give the reported physics FPS. - // We multiply by 55 to give a recognizable running rate (55 or less). - return numSubSteps * m_fixedTimeStep * 1000 * 55; - // return timeStep * 1000 * 55; + // Multiply by 55 to give a nominal frame rate of 55. + return (float)numSubSteps * m_fixedTimeStep * 1000f * 55f; } // Something has collided @@ -1172,7 +1172,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters (s) => { return s.m_params[0].avatarFriction; }, (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].avatarFriction, p, l, v); } ), new ParameterDefn("AvatarStandingFriction", "Avatar friction when standing. Changed on avatar recreation.", - 0.99f, + 10.0f, (s,cf,p,v) => { s.m_params[0].avatarStandingFriction = cf.GetFloat(p, v); }, (s) => { return s.m_params[0].avatarStandingFriction; }, (s,p,l,v) => { s.m_params[0].avatarStandingFriction = v; } ), diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs index 12baee9ff5..1e003e6e8c 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs @@ -357,7 +357,7 @@ public enum CollisionFlags : uint CF_CHARACTER_OBJECT = 1 << 4, CF_DISABLE_VISUALIZE_OBJECT = 1 << 5, CF_DISABLE_SPU_COLLISION_PROCESS = 1 << 6, - // Following used by BulletSim to control collisions + // Following used by BulletSim to control collisions and updates BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10, BS_FLOATS_ON_WATER = 1 << 11, BS_NONE = 0, From 16e4019eca0bec8802e9bd7d2e7bd228025b701a Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Mon, 26 Nov 2012 22:25:36 +0000 Subject: [PATCH 2/2] Fix database service unit test failures by temporarily reverting BasicDataServiceTest extending OpenSimTestCase. Mono 2.4.3 doesn't like this when running nunit, with nunit throwing AssetTests`2 : System.MemberAccessException : Cannot create an instance of OpenSim.Data.Tests.AssetTests`2[TConn,TAssetData] because Type.ContainsGenericParameters is true. and similar. Mono 2.10.8.1 does not have this issue. So will wait until min version of mono bumps before restoring. --- OpenSim/Data/Tests/BasicDataServiceTest.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/OpenSim/Data/Tests/BasicDataServiceTest.cs b/OpenSim/Data/Tests/BasicDataServiceTest.cs index d8019ba9b4..69b79bf6e0 100644 --- a/OpenSim/Data/Tests/BasicDataServiceTest.cs +++ b/OpenSim/Data/Tests/BasicDataServiceTest.cs @@ -44,9 +44,15 @@ namespace OpenSim.Data.Tests /// This is a base class for testing any Data service for any DBMS. /// Requires NUnit 2.5 or better (to support the generics). /// + /// + /// FIXME: Should extend OpenSimTestCase but compile on mono 2.4.3 currently fails with + /// AssetTests`2 : System.MemberAccessException : Cannot create an instance of OpenSim.Data.Tests.AssetTests`2[TConn,TAssetData] because Type.ContainsGenericParameters is true. + /// and similar on EstateTests, InventoryTests and RegionTests. + /// Runs fine with mono 2.10.8.1, so easiest thing is to wait until min Mono version uplifts. + /// /// /// - public class BasicDataServiceTest : OpenSimTestCase + public class BasicDataServiceTest where TConn : DbConnection, new() where TService : class, new() {