BulletSim: remove double application of buoyancy. Centralize computation of buoyancy. Add motor angular debugging controls.

user_profiles
Robert Adams 2013-01-09 11:06:49 -08:00
parent b592ec265b
commit 98168edc29
4 changed files with 60 additions and 66 deletions

View File

@ -124,6 +124,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin
static readonly float PIOverFour = ((float)Math.PI) / 4f;
static readonly float PIOverTwo = ((float)Math.PI) / 2f;
// For debugging, flags to turn on and off individual corrections.
private bool enableAngularVerticalAttraction = true;
private bool enableAngularDeflection = true;
private bool enableAngularBanking = true;
public BSDynamics(BSScene myScene, BSPrim myPrim)
{
PhysicsScene = myScene;
@ -575,11 +580,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
PhysicsScene.PE.SetMassProps(Prim.PhysBody, m_vehicleMass, localInertia);
PhysicsScene.PE.UpdateInertiaTensor(Prim.PhysBody);
Vector3 grav = PhysicsScene.DefaultGravity * (1f - Prim.Buoyancy);
// Set the gravity for the vehicle depending on the buoyancy
// TODO: what should be done if prim and vehicle buoyancy differ?
Vector3 grav = Prim.ComputeGravity(m_VehicleBuoyancy);
PhysicsScene.PE.SetGravity(Prim.PhysBody, grav);
VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4}",
Prim.LocalID, m_vehicleMass, friction, localInertia, angularDamping);
VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4},grav={5}",
Prim.LocalID, m_vehicleMass, friction, localInertia, angularDamping, grav);
}
else
{
@ -858,12 +865,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin
linearMotorContribution *= VehicleOrientation;
// All the contributions after this are world relative (mostly Z modifications)
// ==================================================================
// Buoyancy: force to overcome gravity.
// m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g;
// So, if zero, don't change anything (let gravity happen). If one, negate the effect of gravity.
Vector3 buoyancyContribution = Prim.PhysicsScene.DefaultGravity * m_VehicleBuoyancy;
Vector3 terrainHeightContribution = ComputeLinearTerrainHeightCorrection(pTimestep);
Vector3 hoverContribution = ComputeLinearHover(pTimestep);
@ -873,12 +874,15 @@ namespace OpenSim.Region.Physics.BulletSPlugin
Vector3 limitMotorUpContribution = ComputeLinearMotorUp(pTimestep);
// ==================================================================
// Select between velocities and forces. Forces will happen over time and
// will take into account inertia, collisions, etc. Velocities are
// raw updates to the velocity of the vehicle.
Vector3 newVelocity = linearMotorContribution
+ terrainHeightContribution
+ hoverContribution
+ limitMotorUpContribution;
Vector3 newForce = buoyancyContribution;
Vector3 newForce = Vector3.Zero;
// If not changing some axis, reduce out velocity
if ((m_flags & (VehicleFlag.NO_X)) != 0)
@ -902,6 +906,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
// ==================================================================
// Stuff new linear velocity into the vehicle.
// Since the velocity is just being set, it is not scaled by pTimeStep. Bullet will do that for us.
// Also not scaled by mass since this is a super-physical setting of velocity.
VehicleVelocity = newVelocity;
// Other linear forces are applied as forces.
@ -911,13 +916,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin
VehicleAddForce(totalDownForce);
}
VDetailLog("{0}, MoveLinear,done,newVel={1},totDown={2},IsColliding={3}",
Prim.LocalID, newVelocity, totalDownForce, Prim.IsColliding);
VDetailLog("{0}, MoveLinear,done,linContrib={1},terrContrib={2},hoverContrib={3},limitContrib={4},buoyContrib={5}",
VDetailLog("{0}, MoveLinear,done,linContrib={1},terrContrib={2},hoverContrib={3},limitContrib={4},totDown={5},isColl={6},newVel={7}",
Prim.LocalID,
linearMotorContribution, terrainHeightContribution, hoverContribution,
limitMotorUpContribution, buoyancyContribution
);
linearMotorContribution, terrainHeightContribution, hoverContribution, limitMotorUpContribution,
totalDownForce, Prim.IsColliding, newVelocity );
} // end MoveLinear()
@ -1088,6 +1090,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin
// for preventing ground vehicles with large linear deflection, like bumper cars,
// from climbing their linear deflection into the sky.
// That is, NO_DEFLECTION_UP says angular motion should not add any pitch or roll movement
// TODO: This is here because this is where ODE put it but documentation says it
// is a linear effect. Where should this check go?
if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0)
{
angularMotorContribution.X = 0f;
@ -1179,7 +1183,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
Vector3 ret = Vector3.Zero;
// If vertical attaction timescale is reasonable
if (m_verticalAttractionTimescale < m_verticalAttractionCutoff)
if (enableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff)
{
// Take a vector pointing up and convert it from world to vehicle relative coords.
Vector3 verticalError = Vector3.UnitZ * VehicleOrientation;
@ -1230,7 +1234,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
// this creates an over-correction and then wabbling as the target is overshot.
// TODO: rethink how the different correction computations inter-relate.
if (m_angularDeflectionEfficiency != 0 && VehicleVelocity != Vector3.Zero)
if (enableAngularDeflection && m_angularDeflectionEfficiency != 0 && VehicleVelocity != Vector3.Zero)
{
// The direction the vehicle is moving
Vector3 movingDirection = VehicleVelocity;
@ -1303,7 +1307,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{
Vector3 ret = Vector3.Zero;
if (m_bankingEfficiency != 0 && m_verticalAttractionTimescale < m_verticalAttractionCutoff)
if (enableAngularBanking && m_bankingEfficiency != 0 && m_verticalAttractionTimescale < m_verticalAttractionCutoff)
{
// Rotate a UnitZ vector (pointing up) to how the vehicle is oriented.
// As the vehicle rolls to the right or left, the Y value will increase from

View File

@ -410,7 +410,7 @@ public sealed class BSPrim : BSPhysObject
}
else
{
OMV.Vector3 grav = ComputeGravity();
OMV.Vector3 grav = ComputeGravity(Buoyancy);
if (inWorld)
{
@ -445,12 +445,12 @@ public sealed class BSPrim : BSPhysObject
}
// Return what gravity should be set to this very moment
private OMV.Vector3 ComputeGravity()
public OMV.Vector3 ComputeGravity(float buoyancy)
{
OMV.Vector3 ret = PhysicsScene.DefaultGravity;
if (!IsStatic)
ret *= (1f - Buoyancy);
ret *= (1f - buoyancy);
return ret;
}
@ -1561,21 +1561,6 @@ public sealed class BSPrim : BSPhysObject
// The physics engine says that properties have updated. Update same and inform
// the world that things have changed.
// TODO: do we really need to check for changed? Maybe just copy values and call RequestPhysicsterseUpdate()
enum UpdatedProperties {
Position = 1 << 0,
Rotation = 1 << 1,
Velocity = 1 << 2,
Acceleration = 1 << 3,
RotationalVel = 1 << 4
}
const float ROTATION_TOLERANCE = 0.01f;
const float VELOCITY_TOLERANCE = 0.001f;
const float POSITION_TOLERANCE = 0.05f;
const float ACCELERATION_TOLERANCE = 0.01f;
const float ROTATIONAL_VELOCITY_TOLERANCE = 0.01f;
public override void UpdateProperties(EntityProperties entprop)
{
// Updates only for individual prims and for the root object of a linkset.
@ -1588,7 +1573,7 @@ public sealed class BSPrim : BSPhysObject
entprop.RotationalVelocity = OMV.Vector3.Zero;
}
// Assign directly to the local variables so the normal set action does not happen
// Assign directly to the local variables so the normal set actions do not happen
_position = entprop.Position;
_orientation = entprop.Rotation;
_velocity = entprop.Velocity;

View File

@ -486,6 +486,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
ProcessTaints();
// Some of the physical objects requre individual, pre-step calls
// (vehicles and avatar movement, in particular)
TriggerPreStepEvent(timeStep);
// the prestep actions might have added taints

View File

@ -1,12 +1,17 @@
CURRENT PRIORITIES
=================================================
Avatars walking up stairs (HALF DONE)
Vehicle movement on terrain smoothness
Nebadon vehicles turning funny in arena
limitMotorUp calibration (more down?)
Preferred orientation angular correction fix
Vehicle angular vertical attraction
Vehicle angular deflection
Preferred orientation angular correction fix
vehicle angular banking
Avatars walking up stairs (HALF DONE)
Radius of the capsule affects ability to climb edges.
Vehicle movement on terrain smoothness
Surfboard go wonky when turning
Angular motor direction is global coordinates rather than local coordinates?
Boats float low in the water
Boats float low in the water (DONE)
Avatar movement
flying into a wall doesn't stop avatar who keeps appearing to move through the obstacle (DONE)
walking up stairs is not calibrated correctly (stairs out of Kepler cabin)
@ -33,19 +38,15 @@ CRASHES
VEHICLES TODO LIST:
=================================================
Angular motor direction is global coordinates rather than local coordinates
Border crossing with linked vehicle causes crash
Vehicles (Move smoothly)
Add vehicle collisions so IsColliding is properly reported.
Needed for banking, limitMotorUp, movementLimiting, ...
VehicleAddForce is not scaled by the simulation step but it is only
applied for one step. Should it be scaled?
Some vehicles should not be able to turn if no speed or off ground.
Cannot edit/move a vehicle being ridden: it jumps back to the origional position.
Neb car jiggling left and right
Happens on terrain and any other mesh object. Flat cubes are much smoother.
This has been reduced but not eliminated.
Implement referenceFrame for all the motion routines.
For limitMotorUp, use raycast down to find if vehicle is in the air.
Angular motion around Z moves the vehicle in world Z and not vehicle Z in ODE.
Verify that angular motion specified around Z moves in the vehicle coordinates.
Verify llGetVel() is returning a smooth and good value for vehicle movement.
@ -54,14 +55,13 @@ Implement function efficiency for lineaar and angular motion.
After getting off a vehicle, the root prim is phantom (can be walked through)
Need to force a position update for the root prim after compound shape destruction
Linkset explosion after three "rides" on Nebadon lite vehicle (LinksetConstraint)
For limitMotorUp, use raycast down to find if vehicle is in the air.
Remove vehicle angular velocity zeroing in BSPrim.UpdateProperties().
A kludge that isn't fixing the real problem of Bullet adding extra motion.
Incorporate inter-relationship of angular corrections. For instance, angularDeflection
and angularMotorUp will compute same X or Y correction. When added together
creates over-correction and over-shoot and wabbling.
BULLETSIM TODO LIST:
GENERAL TODO LIST:
=================================================
Implement an avatar mesh shape. The Bullet capsule is way too limited.
Consider just hand creating a vertex/index array in a new BSShapeAvatar.
@ -121,11 +121,9 @@ LinksetCompound: when one of the children changes orientation (like tires
Verify/think through scripts in children of linksets. What do they reference
and return when getting position, velocity, ...
Confirm constraint linksets still work after making all the changes for compound linksets.
Use PostTaint callback to do rebuilds for constraint linksets to reduce rebuilding
Add 'changed' flag or similar to reduce the number of times a linkset is rebuilt.
For compound linksets, add ability to remove or reposition individual child shapes.
Disable activity of passive linkset children.
Since the linkset is a compound object, the old prims are left lying
around and need to be phantomized so they don't collide, ...
Speed up creation of large physical linksets
For instance, sitting in Neb's car (130 prims) takes several seconds to become physical.
REALLY bad for very large physical linksets (freezes the sim for many seconds).
@ -138,25 +136,21 @@ MORE
Use the HACD convex hull routine in Bullet rather than the C# version.
Do we need to do convex hulls all the time? Can complex meshes be left meshes?
There is some problem with meshes and collisions
Test avatar walking up stairs. How does compare with SL.
Radius of the capsule affects ability to climb edges.
Hulls are not as detailed as meshes. Hulled vehicles insides are different shape.
Debounce avatar contact so legs don't keep folding up when standing.
Implement LSL physics controls. Like STATUS_ROTATE_X.
Add border extensions to terrain to help region crossings and objects leaving region.
Use a different capsule shape for avatar when sitting
LL uses a pyrimidal shape scaled by the avatar's bounding box
http://wiki.secondlife.com/wiki/File:Avmeshforms.png
Performance test with lots of avatars. Can BulletSim support a thousand?
Optimize collisions in C++: only send up to the object subscribed to collisions.
Use collision subscription and remove the collsion(A,B) and collision(B,A)
Check whether SimMotionState needs large if statement (see TODO).
Implement 'top colliders' info.
Avatar jump
Performance measurement and changes to make quicker.
Implement detailed physics stats (GetStats()).
Measure performance improvement from hulls
Test not using ghost objects for volume detect implementation.
Performance of closures and delegates for taint processing
@ -164,9 +158,7 @@ Performance of closures and delegates for taint processing
Is any slowdown introduced by the existing implementation significant?
Is there are more efficient method of implementing pre and post step actions?
See http://www.codeproject.com/Articles/29922/Weak-Events-in-C
Physics Arena central pyramid: why is one side permiable?
In SL, perfect spheres don't seem to have rolling friction. Add special case.
Enforce physical parameter min/max:
Gravity: [-1, 28]
@ -197,22 +189,19 @@ Generalize Dynamics and PID with standardized motors.
Generalize Linkset and vehicles into PropertyManagers
Methods for Refresh, RemoveBodyDependencies, RestoreBodyDependencies
Potentially add events for shape destruction, etc.
Complete implemention of preStepActions
Replace vehicle step call with prestep event.
Is there a need for postStepActions? postStepTaints?
Better mechanism for resetting linkset set and vehicle parameters when body rebuilt.
BSPrim.CreateGeomAndObject is kludgy with the callbacks, etc.
Implement linkset by setting position of children when root updated. (LinksetManual)
Linkset implementation using manual prim movement.
LinkablePrim class? Would that simplify/centralize the linkset logic?
BSScene.UpdateParameterSet() is broken. How to set params on objects?
Remove HeightmapInfo from terrain specification
Since C++ code does not need terrain height, this structure et al are not needed.
Add floating motor for BS_FLOATS_ON_WATER so prim and avatar will
bob at the water level. BSPrim.PositionSanityCheck().
bob at the water level. BSPrim.PositionSanityCheck()
Should taints check for existance or activeness of target?
When destroying linksets/etc, taints can be generated for objects that are
actually gone when the taint happens. Crashes don't happen because the taint closure
keeps the object from being freed, but that is just an accident.
Possibly have and 'active' flag that is checked by the taint processor?
Possibly have an 'active' flag that is checked by the taint processor?
Parameters for physics logging should be moved from BSScene to BSParam (at least boolean ones)
Can some of the physical wrapper classes (BulletBody, BulletWorld, BulletShape) be 'sealed'?
There are TOO MANY interfaces from BulletSim core to Bullet itself
@ -282,3 +271,18 @@ Redo BulletSimAPI to allow native C# implementation of Bullet option (DONE)
Meshes rendering as bounding boxes (DONE)
(Resolution: Added test for mesh/sculpties in native shapes so it didn't think it was a box)
llMoveToTarget (Resolution: added simple motor to update the position.)
Angular motor direction is global coordinates rather than local coordinates (DONE)
Add vehicle collisions so IsColliding is properly reported. (DONE)
Needed for banking, limitMotorUp, movementLimiting, ...
(Resolution: added CollisionFlags.BS_VEHICLE_COLLISION and code to use it)
VehicleAddForce is not scaled by the simulation step but it is only
applied for one step. Should it be scaled? (DONE)
(Resolution: use force for timed things, Impulse for immediate, non-timed things)
Complete implemention of preStepActions (DONE)
Replace vehicle step call with prestep event.
Is there a need for postStepActions? postStepTaints?
Disable activity of passive linkset children. (DONE)
Since the linkset is a compound object, the old prims are left lying
around and need to be phantomized so they don't collide, ...
Remove HeightmapInfo from terrain specification (DONE)
Since C++ code does not need terrain height, this structure et al are not needed.