BulletSim: Fix llApplyImpulse so it works after the first impulse. The problem was Bullet deactivating the object between the pushes (when, as far as the physics engine is concerned, it isn't moving).

0.7.5-pf-bulletsim
Robert Adams 2012-12-21 23:03:27 -08:00
parent 3d659fe97d
commit 37fb691ba5
2 changed files with 29 additions and 4 deletions

View File

@ -304,17 +304,21 @@ public abstract class BSPhysObject : PhysicsActor
string identifier = op + "-" + id.ToString(); string identifier = op + "-" + id.ToString();
RegisteredActions[identifier] = actn; RegisteredActions[identifier] = actn;
PhysicsScene.BeforeStep += actn; PhysicsScene.BeforeStep += actn;
DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier);
} }
// Unregister a pre step action. Safe to call if the action has not been registered. // Unregister a pre step action. Safe to call if the action has not been registered.
protected void UnRegisterPreStepAction(string op, uint id) protected void UnRegisterPreStepAction(string op, uint id)
{ {
string identifier = op + "-" + id.ToString(); string identifier = op + "-" + id.ToString();
bool removed = false;
if (RegisteredActions.ContainsKey(identifier)) if (RegisteredActions.ContainsKey(identifier))
{ {
PhysicsScene.BeforeStep -= RegisteredActions[identifier]; PhysicsScene.BeforeStep -= RegisteredActions[identifier];
RegisteredActions.Remove(identifier); RegisteredActions.Remove(identifier);
removed = true;
} }
DetailLog("{0},BSPhysObject.UnRegisterPreStepAction,id={1},removed={2}", LocalID, identifier, removed);
} }
protected void UnRegisterAllPreStepActions() protected void UnRegisterAllPreStepActions()
@ -324,6 +328,7 @@ public abstract class BSPhysObject : PhysicsActor
PhysicsScene.BeforeStep -= kvp.Value; PhysicsScene.BeforeStep -= kvp.Value;
} }
RegisteredActions.Clear(); RegisteredActions.Clear();
DetailLog("{0},BSPhysObject.UnRegisterAllPreStepActions,", LocalID);
} }

View File

@ -442,8 +442,12 @@ public sealed class BSPrim : BSPhysObject
RegisterPreStepAction("BSPrim.setForce", LocalID, RegisterPreStepAction("BSPrim.setForce", LocalID,
delegate(float timeStep) delegate(float timeStep)
{ {
DetailLog("{0},BSPrim.setForce,preStep,force={1}", LocalID, _force);
if (PhysBody.HasPhysicalBody) if (PhysBody.HasPhysicalBody)
{
BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, _force); BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, _force);
ActivateIfPhysical(false);
}
} }
); );
} }
@ -554,7 +558,10 @@ public sealed class BSPrim : BSPhysObject
_velocity = value; _velocity = value;
if (PhysBody.HasPhysicalBody) if (PhysBody.HasPhysicalBody)
{
BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity);
ActivateIfPhysical(false);
}
} }
} }
public override OMV.Vector3 Torque { public override OMV.Vector3 Torque {
@ -845,7 +852,7 @@ public sealed class BSPrim : BSPhysObject
// Called in taint-time!! // Called in taint-time!!
private void ActivateIfPhysical(bool forceIt) private void ActivateIfPhysical(bool forceIt)
{ {
if (IsPhysical) if (IsPhysical && PhysBody.HasPhysicalBody)
BulletSimAPI.Activate2(PhysBody.ptr, forceIt); BulletSimAPI.Activate2(PhysBody.ptr, forceIt);
} }
@ -919,8 +926,7 @@ public sealed class BSPrim : BSPhysObject
PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate() PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate()
{ {
DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity);
if (PhysBody.HasPhysicalBody) ForceRotationalVelocity = _rotationalVelocity;
BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity);
}); });
} }
} }
@ -930,7 +936,11 @@ public sealed class BSPrim : BSPhysObject
} }
set { set {
_rotationalVelocity = value; _rotationalVelocity = value;
BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); if (PhysBody.HasPhysicalBody)
{
BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity);
ActivateIfPhysical(false);
}
} }
} }
public override bool Kinematic { public override bool Kinematic {
@ -959,6 +969,7 @@ public sealed class BSPrim : BSPhysObject
{ {
float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); float grav = PhysicsScene.Params.gravity * (1f - _buoyancy);
BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav));
ActivateIfPhysical(false);
} }
} }
} }
@ -1011,7 +1022,10 @@ public sealed class BSPrim : BSPhysObject
// Bullet adds this central force to the total force for this tick // Bullet adds this central force to the total force for this tick
DetailLog("{0},BSPrim.addForce,taint,force={1}", LocalID, addForce); DetailLog("{0},BSPrim.addForce,taint,force={1}", LocalID, addForce);
if (PhysBody.HasPhysicalBody) if (PhysBody.HasPhysicalBody)
{
BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, addForce); BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, addForce);
ActivateIfPhysical(false);
}
}); });
} }
else else
@ -1032,7 +1046,10 @@ public sealed class BSPrim : BSPhysObject
PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddAngularForce", delegate() PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddAngularForce", delegate()
{ {
if (PhysBody.HasPhysicalBody) if (PhysBody.HasPhysicalBody)
{
BulletSimAPI.ApplyTorque2(PhysBody.ptr, angForce); BulletSimAPI.ApplyTorque2(PhysBody.ptr, angForce);
ActivateIfPhysical(false);
}
}); });
} }
else else
@ -1052,7 +1069,10 @@ public sealed class BSPrim : BSPhysObject
PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyTorqueImpulse", delegate() PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyTorqueImpulse", delegate()
{ {
if (PhysBody.HasPhysicalBody) if (PhysBody.HasPhysicalBody)
{
BulletSimAPI.ApplyTorqueImpulse2(PhysBody.ptr, applyImpulse); BulletSimAPI.ApplyTorqueImpulse2(PhysBody.ptr, applyImpulse);
ActivateIfPhysical(false);
}
}); });
} }