BulletSim: adjust friction and restitution based on material type.

0.7.5-pf-bulletsim
Robert Adams 2012-12-09 22:10:32 -08:00
parent af8d53657d
commit ce5083a504
2 changed files with 17 additions and 5 deletions

View File

@ -60,6 +60,9 @@ public abstract class BSPhysObject : PhysicsActor
Linkset = BSLinkset.Factory(PhysicsScene, this);
LastAssetBuildFailed = false;
// Default material type
Material = MaterialAttributes.Material.Wood;
CollisionCollection = new CollisionEventUpdate();
SubscribedEventsMs = 0;
CollidingStep = 0;
@ -109,6 +112,13 @@ public abstract class BSPhysObject : PhysicsActor
public abstract bool IsSolid { get; }
public abstract bool IsStatic { get; }
// Materialness
public MaterialAttributes.Material Material { get; private set; }
public override void SetMaterial(int material)
{
Material = (MaterialAttributes.Material)material;
}
// Stop all physical motion.
public abstract void ZeroMotion(bool inTaintTime);
public abstract void ZeroAngularMotion(bool inTaintTime);

View File

@ -683,8 +683,9 @@ public sealed class BSPrim : BSPhysObject
ZeroMotion(true);
// Set various physical properties so other object interact properly
BulletSimAPI.SetFriction2(PhysBody.ptr, PhysicsScene.Params.defaultFriction);
BulletSimAPI.SetRestitution2(PhysBody.ptr, PhysicsScene.Params.defaultRestitution);
MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false);
BulletSimAPI.SetFriction2(PhysBody.ptr, matAttrib.friction);
BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution);
// Mass is zero which disables a bunch of physics stuff in Bullet
UpdatePhysicalMassProperties(0f);
@ -711,9 +712,10 @@ public sealed class BSPrim : BSPhysObject
// Not a Bullet static object
CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT);
// Set various physical properties so internal dynamic properties will get computed correctly as they are set
BulletSimAPI.SetFriction2(PhysBody.ptr, PhysicsScene.Params.defaultFriction);
BulletSimAPI.SetRestitution2(PhysBody.ptr, PhysicsScene.Params.defaultRestitution);
// Set various physical properties so other object interact properly
MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true);
BulletSimAPI.SetFriction2(PhysBody.ptr, matAttrib.friction);
BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.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