BulletSim: Adapt BulletSim to the newer physical properties. Viewer

dialog setting of friction, restitution, ... working.
user_profiles
Robert Adams 2013-02-07 17:05:40 -08:00
parent b545e13184
commit 913965256f
2 changed files with 28 additions and 30 deletions

View File

@ -79,7 +79,7 @@ public abstract class BSPhysObject : PhysicsActor
TypeName = typeName;
// Initialize variables kept in base.
GravityModifier = 1.0f;
GravModifier = 1.0f;
Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity);
// We don't have any physical representation yet.
@ -170,6 +170,8 @@ public abstract class BSPhysObject : PhysicsActor
public override void SetMaterial(int material)
{
Material = (MaterialAttributes.Material)material;
// Setting the material sets the material attributes also.
MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false);
Friction = matAttrib.friction;
Restitution = matAttrib.restitution;

View File

@ -423,8 +423,6 @@ public sealed class BSPrim : BSPhysObject
}
else
{
OMV.Vector3 grav = ComputeGravity(Buoyancy);
if (inWorld)
{
// Changing interesting properties doesn't change proxy and collision cache
@ -434,15 +432,15 @@ public sealed class BSPrim : BSPhysObject
}
// The computation of mass props requires gravity to be set on the object.
PhysicsScene.PE.SetGravity(PhysBody, grav);
Gravity = ComputeGravity(Buoyancy);
PhysicsScene.PE.SetGravity(PhysBody, Gravity);
Inertia = PhysicsScene.PE.CalculateLocalInertia(PhysShape, physMass);
PhysicsScene.PE.SetMassProps(PhysBody, physMass, Inertia);
PhysicsScene.PE.UpdateInertiaTensor(PhysBody);
// center of mass is at the zero of the object
// DEBUG DEBUG PhysicsScene.PE.SetCenterOfMassByPosRot(PhysBody, ForcePosition, ForceOrientation);
DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}", LocalID, physMass, Inertia, grav, inWorld);
DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}",
LocalID, physMass, Inertia, Gravity, inWorld);
if (inWorld)
{
@ -455,10 +453,13 @@ public sealed class BSPrim : BSPhysObject
// Return what gravity should be set to this very moment
public OMV.Vector3 ComputeGravity(float buoyancy)
{
OMV.Vector3 ret = PhysicsScene.DefaultGravity * GravityModifier;
OMV.Vector3 ret = PhysicsScene.DefaultGravity;
if (!IsStatic)
{
ret *= (1f - buoyancy);
ret *= GravModifier;
}
return ret;
}
@ -587,8 +588,7 @@ public sealed class BSPrim : BSPhysObject
base.SetMaterial(material);
PhysicsScene.TaintedObject("BSPrim.SetMaterial", delegate()
{
if (PhysBody.HasPhysicalBody)
UpdatePhysicalParameters();
UpdatePhysicalParameters();
});
}
public override float Friction
@ -601,8 +601,7 @@ public sealed class BSPrim : BSPhysObject
base.Friction = value;
PhysicsScene.TaintedObject("BSPrim.setFriction", delegate()
{
if (PhysBody.HasPhysicalBody)
UpdatePhysicalParameters();
UpdatePhysicalParameters();
});
}
}
@ -617,8 +616,7 @@ public sealed class BSPrim : BSPhysObject
base.Restitution = value;
PhysicsScene.TaintedObject("BSPrim.setRestitution", delegate()
{
if (PhysBody.HasPhysicalBody)
UpdatePhysicalParameters();
UpdatePhysicalParameters();
});
}
}
@ -633,24 +631,22 @@ public sealed class BSPrim : BSPhysObject
base.Density = value;
PhysicsScene.TaintedObject("BSPrim.setDensity", delegate()
{
if (PhysBody.HasPhysicalBody)
UpdatePhysicalParameters();
UpdatePhysicalParameters();
});
}
}
}
public override float GravityModifier
public override float GravModifier
{
get { return base.GravityModifier; }
get { return base.GravModifier; }
set
{
if (base.GravityModifier != value)
if (base.GravModifier != value)
{
base.GravityModifier = value;
base.GravModifier = value;
PhysicsScene.TaintedObject("BSPrim.setGravityModifier", delegate()
{
if (PhysBody.HasPhysicalBody)
UpdatePhysicalParameters();
UpdatePhysicalParameters();
});
}
}
@ -820,7 +816,12 @@ public sealed class BSPrim : BSPhysObject
// collisionEvents: whether this object returns collision events
public void UpdatePhysicalParameters()
{
// DetailLog("{0},BSPrim.UpdatePhysicalParameters,entry,body={1},shape={2}", LocalID, BSBody, BSShape);
if (!PhysBody.HasPhysicalBody)
{
// This would only happen if updates are called for during initialization when the body is not set up yet.
DetailLog("{0},BSPrim.UpdatePhysicalParameters,taint,calledWithNoPhysBody", LocalID);
return;
}
// Mangling all the physical properties requires the object not be in the physical world.
// This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found).
@ -898,9 +899,9 @@ public sealed class BSPrim : BSPhysObject
CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT);
// Set various physical properties so other object interact properly
MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true);
PhysicsScene.PE.SetFriction(PhysBody, Friction);
PhysicsScene.PE.SetRestitution(PhysBody, Restitution);
// DetailLog("{0},BSPrim.MakeDynamic,frict={1},rest={2}", LocalID, Friction, Restitution);
// per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382
// Since this can be called multiple times, only zero forces when becoming physical
@ -999,16 +1000,11 @@ public sealed class BSPrim : BSPhysObject
if (PhysBody.HasPhysicalBody)
{
PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody);
// Must set gravity after it has been added to the world because, for unknown reasons,
// adding the object resets the object's gravity to world gravity
OMV.Vector3 grav = ComputeGravity(Buoyancy);
PhysicsScene.PE.SetGravity(PhysBody, grav);
}
else
{
m_log.ErrorFormat("{0} Attempt to add physical object without body. id={1}", LogHeader, LocalID);
DetailLog("{0},BSPrim.UpdatePhysicalParameters,addObjectWithoutBody,cType={1}", LocalID, PhysBody.collisionType);
DetailLog("{0},BSPrim.AddObjectToPhysicalWorld,addObjectWithoutBody,cType={1}", LocalID, PhysBody.collisionType);
}
}