BulletSim: Adapt BulletSim to the newer physical properties. Viewer
dialog setting of friction, restitution, ... working.user_profiles
parent
b545e13184
commit
913965256f
|
@ -79,7 +79,7 @@ public abstract class BSPhysObject : PhysicsActor
|
||||||
TypeName = typeName;
|
TypeName = typeName;
|
||||||
|
|
||||||
// Initialize variables kept in base.
|
// Initialize variables kept in base.
|
||||||
GravityModifier = 1.0f;
|
GravModifier = 1.0f;
|
||||||
Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity);
|
Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity);
|
||||||
|
|
||||||
// We don't have any physical representation yet.
|
// We don't have any physical representation yet.
|
||||||
|
@ -170,6 +170,8 @@ public abstract class BSPhysObject : PhysicsActor
|
||||||
public override void SetMaterial(int material)
|
public override void SetMaterial(int material)
|
||||||
{
|
{
|
||||||
Material = (MaterialAttributes.Material)material;
|
Material = (MaterialAttributes.Material)material;
|
||||||
|
|
||||||
|
// Setting the material sets the material attributes also.
|
||||||
MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false);
|
MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false);
|
||||||
Friction = matAttrib.friction;
|
Friction = matAttrib.friction;
|
||||||
Restitution = matAttrib.restitution;
|
Restitution = matAttrib.restitution;
|
||||||
|
|
|
@ -423,8 +423,6 @@ public sealed class BSPrim : BSPhysObject
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
OMV.Vector3 grav = ComputeGravity(Buoyancy);
|
|
||||||
|
|
||||||
if (inWorld)
|
if (inWorld)
|
||||||
{
|
{
|
||||||
// Changing interesting properties doesn't change proxy and collision cache
|
// 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.
|
// 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);
|
Inertia = PhysicsScene.PE.CalculateLocalInertia(PhysShape, physMass);
|
||||||
PhysicsScene.PE.SetMassProps(PhysBody, physMass, Inertia);
|
PhysicsScene.PE.SetMassProps(PhysBody, physMass, Inertia);
|
||||||
PhysicsScene.PE.UpdateInertiaTensor(PhysBody);
|
PhysicsScene.PE.UpdateInertiaTensor(PhysBody);
|
||||||
|
|
||||||
// center of mass is at the zero of the object
|
DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}",
|
||||||
// DEBUG DEBUG PhysicsScene.PE.SetCenterOfMassByPosRot(PhysBody, ForcePosition, ForceOrientation);
|
LocalID, physMass, Inertia, Gravity, inWorld);
|
||||||
DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}", LocalID, physMass, Inertia, grav, inWorld);
|
|
||||||
|
|
||||||
if (inWorld)
|
if (inWorld)
|
||||||
{
|
{
|
||||||
|
@ -455,10 +453,13 @@ public sealed class BSPrim : BSPhysObject
|
||||||
// Return what gravity should be set to this very moment
|
// Return what gravity should be set to this very moment
|
||||||
public OMV.Vector3 ComputeGravity(float buoyancy)
|
public OMV.Vector3 ComputeGravity(float buoyancy)
|
||||||
{
|
{
|
||||||
OMV.Vector3 ret = PhysicsScene.DefaultGravity * GravityModifier;
|
OMV.Vector3 ret = PhysicsScene.DefaultGravity;
|
||||||
|
|
||||||
if (!IsStatic)
|
if (!IsStatic)
|
||||||
|
{
|
||||||
ret *= (1f - buoyancy);
|
ret *= (1f - buoyancy);
|
||||||
|
ret *= GravModifier;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -587,8 +588,7 @@ public sealed class BSPrim : BSPhysObject
|
||||||
base.SetMaterial(material);
|
base.SetMaterial(material);
|
||||||
PhysicsScene.TaintedObject("BSPrim.SetMaterial", delegate()
|
PhysicsScene.TaintedObject("BSPrim.SetMaterial", delegate()
|
||||||
{
|
{
|
||||||
if (PhysBody.HasPhysicalBody)
|
UpdatePhysicalParameters();
|
||||||
UpdatePhysicalParameters();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public override float Friction
|
public override float Friction
|
||||||
|
@ -601,8 +601,7 @@ public sealed class BSPrim : BSPhysObject
|
||||||
base.Friction = value;
|
base.Friction = value;
|
||||||
PhysicsScene.TaintedObject("BSPrim.setFriction", delegate()
|
PhysicsScene.TaintedObject("BSPrim.setFriction", delegate()
|
||||||
{
|
{
|
||||||
if (PhysBody.HasPhysicalBody)
|
UpdatePhysicalParameters();
|
||||||
UpdatePhysicalParameters();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -617,8 +616,7 @@ public sealed class BSPrim : BSPhysObject
|
||||||
base.Restitution = value;
|
base.Restitution = value;
|
||||||
PhysicsScene.TaintedObject("BSPrim.setRestitution", delegate()
|
PhysicsScene.TaintedObject("BSPrim.setRestitution", delegate()
|
||||||
{
|
{
|
||||||
if (PhysBody.HasPhysicalBody)
|
UpdatePhysicalParameters();
|
||||||
UpdatePhysicalParameters();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -633,24 +631,22 @@ public sealed class BSPrim : BSPhysObject
|
||||||
base.Density = value;
|
base.Density = value;
|
||||||
PhysicsScene.TaintedObject("BSPrim.setDensity", delegate()
|
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
|
set
|
||||||
{
|
{
|
||||||
if (base.GravityModifier != value)
|
if (base.GravModifier != value)
|
||||||
{
|
{
|
||||||
base.GravityModifier = value;
|
base.GravModifier = value;
|
||||||
PhysicsScene.TaintedObject("BSPrim.setGravityModifier", delegate()
|
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
|
// collisionEvents: whether this object returns collision events
|
||||||
public void UpdatePhysicalParameters()
|
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.
|
// 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).
|
// 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);
|
CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT);
|
||||||
|
|
||||||
// Set various physical properties so other object interact properly
|
// Set various physical properties so other object interact properly
|
||||||
MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true);
|
|
||||||
PhysicsScene.PE.SetFriction(PhysBody, Friction);
|
PhysicsScene.PE.SetFriction(PhysBody, Friction);
|
||||||
PhysicsScene.PE.SetRestitution(PhysBody, Restitution);
|
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
|
// per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382
|
||||||
// Since this can be called multiple times, only zero forces when becoming physical
|
// 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)
|
if (PhysBody.HasPhysicalBody)
|
||||||
{
|
{
|
||||||
PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody);
|
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
|
else
|
||||||
{
|
{
|
||||||
m_log.ErrorFormat("{0} Attempt to add physical object without body. id={1}", LogHeader, LocalID);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue