BulletSim: add extended physics LSL constants for axis specification.

Add specific error warnings for mis-matched parameter types in extended
   physics functions.
varregion
Robert Adams 2013-09-04 07:56:59 -07:00
parent cf2cdc191d
commit 5827b6e1aa
3 changed files with 74 additions and 37 deletions

View File

@ -415,9 +415,21 @@ public class ExtendedPhysics : INonSharedRegionModule
[ScriptConstant] [ScriptConstant]
public const int PHYS_AXIS_ALL = -1; public const int PHYS_AXIS_ALL = -1;
[ScriptConstant] [ScriptConstant]
public const int PHYS_AXIS_ALL_LINEAR = -2; public const int PHYS_AXIS_LINEAR_ALL = -2;
[ScriptConstant] [ScriptConstant]
public const int PHYS_AXIS_ALL_ANGULAR = -3; public const int PHYS_AXIS_ANGULAR_ALL = -3;
[ScriptConstant]
public const int PHYS_AXIS_LINEAR_X = 0;
[ScriptConstant]
public const int PHYS_AXIS_LINEAR_Y = 1;
[ScriptConstant]
public const int PHYS_AXIS_LINEAR_Z = 2;
[ScriptConstant]
public const int PHYS_AXIS_ANGULAR_X = 3;
[ScriptConstant]
public const int PHYS_AXIS_ANGULAR_Y = 4;
[ScriptConstant]
public const int PHYS_AXIS_ANGULAR_Z = 5;
// physChangeLinkParams(integer linkNum, [ PHYS_PARAM_*, value, PHYS_PARAM_*, value, ...]) // physChangeLinkParams(integer linkNum, [ PHYS_PARAM_*, value, PHYS_PARAM_*, value, ...])
[ScriptInvocation] [ScriptInvocation]

View File

@ -63,7 +63,7 @@ public sealed class BSConstraintSpring : BSConstraint6Dof
public bool SetStiffness(int pIndex, float pStiffness) public bool SetStiffness(int pIndex, float pStiffness)
{ {
PhysicsScene.DetailLog("{0},BSConstraintSpring.SetStiffness,obj1ID={1},obj2ID={2},indx={3},enable={4}", PhysicsScene.DetailLog("{0},BSConstraintSpring.SetStiffness,obj1ID={1},obj2ID={2},indx={3},stiff={4}",
m_body1.ID, m_body1.ID, m_body2.ID, pIndex, pStiffness); m_body1.ID, m_body1.ID, m_body2.ID, pIndex, pStiffness);
PhysicsScene.PE.SpringSetStiffness(m_constraint, pIndex, pStiffness); PhysicsScene.PE.SpringSetStiffness(m_constraint, pIndex, pStiffness);
return true; return true;
@ -71,7 +71,7 @@ public sealed class BSConstraintSpring : BSConstraint6Dof
public bool SetDamping(int pIndex, float pDamping) public bool SetDamping(int pIndex, float pDamping)
{ {
PhysicsScene.DetailLog("{0},BSConstraintSpring.SetDamping,obj1ID={1},obj2ID={2},indx={3},enable={4}", PhysicsScene.DetailLog("{0},BSConstraintSpring.SetDamping,obj1ID={1},obj2ID={2},indx={3},damp={4}",
m_body1.ID, m_body1.ID, m_body2.ID, pIndex, pDamping); m_body1.ID, m_body1.ID, m_body2.ID, pIndex, pDamping);
PhysicsScene.PE.SpringSetDamping(m_constraint, pIndex, pDamping); PhysicsScene.PE.SpringSetDamping(m_constraint, pIndex, pDamping);
return true; return true;
@ -79,7 +79,7 @@ public sealed class BSConstraintSpring : BSConstraint6Dof
public bool SetEquilibriumPoint(int pIndex, float pEqPoint) public bool SetEquilibriumPoint(int pIndex, float pEqPoint)
{ {
PhysicsScene.DetailLog("{0},BSConstraintSpring.SetEquilibriumPoint,obj1ID={1},obj2ID={2},indx={3},enable={4}", PhysicsScene.DetailLog("{0},BSConstraintSpring.SetEquilibriumPoint,obj1ID={1},obj2ID={2},indx={3},eqPoint={4}",
m_body1.ID, m_body1.ID, m_body2.ID, pIndex, pEqPoint); m_body1.ID, m_body1.ID, m_body2.ID, pIndex, pEqPoint);
PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, pIndex, pEqPoint); PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, pIndex, pEqPoint);
return true; return true;

View File

@ -605,30 +605,32 @@ public sealed class BSLinksetConstraints : BSLinkset
// pParams = [ BSPhysObject root, BSPhysObject child, int op, object opParams, int op, object opParams, ... ] // pParams = [ BSPhysObject root, BSPhysObject child, int op, object opParams, int op, object opParams, ... ]
case ExtendedPhysics.PhysFunctChangeLinkParams: case ExtendedPhysics.PhysFunctChangeLinkParams:
// There should be two parameters: the childActor and a list of parameters to set // There should be two parameters: the childActor and a list of parameters to set
try if (pParams.Length > 2)
{ {
if (pParams.Length > 2) BSPrimLinkable child = pParams[1] as BSPrimLinkable;
BSLinkInfo baseLinkInfo = null;
if (TryGetLinkInfo(child, out baseLinkInfo))
{ {
BSPrimLinkable child = pParams[1] as BSPrimLinkable; BSLinkInfoConstraint linkInfo = baseLinkInfo as BSLinkInfoConstraint;
BSLinkInfo baseLinkInfo = null; if (linkInfo != null)
if (TryGetLinkInfo(child, out baseLinkInfo))
{ {
BSLinkInfoConstraint linkInfo = baseLinkInfo as BSLinkInfoConstraint; int valueInt;
if (linkInfo != null) float valueFloat;
{ bool valueBool;
int valueInt; OMV.Vector3 valueVector;
float valueFloat; OMV.Quaternion valueQuaternion;
bool valueBool; int axisLow, axisHigh;
OMV.Vector3 valueVector;
OMV.Quaternion valueQuaternion;
int axisLow, axisHigh;
int opIndex = 2; int opIndex = 2;
while (opIndex < pParams.Length) while (opIndex < pParams.Length)
{
int thisOp = 0;
string errMsg = "";
try
{ {
int thisOp = (int)pParams[opIndex]; thisOp = (int)pParams[opIndex];
DetailLog("{0},BSLinksetConstraint.ChangeLinkParams2,op={1},val={2}", DetailLog("{0},BSLinksetConstraint.ChangeLinkParams2,op={1},val={2}",
linkInfo.member.LocalID, thisOp, pParams[opIndex+1]); linkInfo.member.LocalID, thisOp, pParams[opIndex + 1]);
switch (thisOp) switch (thisOp)
{ {
case ExtendedPhysics.PHYS_PARAM_LINK_TYPE: case ExtendedPhysics.PHYS_PARAM_LINK_TYPE:
@ -646,89 +648,106 @@ public sealed class BSLinksetConstraints : BSLinkset
opIndex += 2; opIndex += 2;
break; break;
case ExtendedPhysics.PHYS_PARAM_FRAMEINA_LOC: case ExtendedPhysics.PHYS_PARAM_FRAMEINA_LOC:
errMsg = "PHYS_PARAM_FRAMEINA_LOC takes one parameter of type vector";
valueVector = (OMV.Vector3)pParams[opIndex + 1]; valueVector = (OMV.Vector3)pParams[opIndex + 1];
linkInfo.frameInAloc = valueVector; linkInfo.frameInAloc = valueVector;
opIndex += 2; opIndex += 2;
break; break;
case ExtendedPhysics.PHYS_PARAM_FRAMEINA_ROT: case ExtendedPhysics.PHYS_PARAM_FRAMEINA_ROT:
errMsg = "PHYS_PARAM_FRAMEINA_ROT takes one parameter of type rotation";
valueQuaternion = (OMV.Quaternion)pParams[opIndex + 1]; valueQuaternion = (OMV.Quaternion)pParams[opIndex + 1];
linkInfo.frameInArot = valueQuaternion; linkInfo.frameInArot = valueQuaternion;
opIndex += 2; opIndex += 2;
break; break;
case ExtendedPhysics.PHYS_PARAM_FRAMEINB_LOC: case ExtendedPhysics.PHYS_PARAM_FRAMEINB_LOC:
errMsg = "PHYS_PARAM_FRAMEINB_LOC takes one parameter of type vector";
valueVector = (OMV.Vector3)pParams[opIndex + 1]; valueVector = (OMV.Vector3)pParams[opIndex + 1];
linkInfo.frameInBloc = valueVector; linkInfo.frameInBloc = valueVector;
opIndex += 2; opIndex += 2;
break; break;
case ExtendedPhysics.PHYS_PARAM_FRAMEINB_ROT: case ExtendedPhysics.PHYS_PARAM_FRAMEINB_ROT:
errMsg = "PHYS_PARAM_FRAMEINB_ROT takes one parameter of type rotation";
valueQuaternion = (OMV.Quaternion)pParams[opIndex + 1]; valueQuaternion = (OMV.Quaternion)pParams[opIndex + 1];
linkInfo.frameInBrot = valueQuaternion; linkInfo.frameInBrot = valueQuaternion;
opIndex += 2; opIndex += 2;
break; break;
case ExtendedPhysics.PHYS_PARAM_LINEAR_LIMIT_LOW: case ExtendedPhysics.PHYS_PARAM_LINEAR_LIMIT_LOW:
errMsg = "PHYS_PARAM_LINEAR_LIMIT_LOW takes one parameter of type vector";
valueVector = (OMV.Vector3)pParams[opIndex + 1]; valueVector = (OMV.Vector3)pParams[opIndex + 1];
linkInfo.linearLimitLow = valueVector; linkInfo.linearLimitLow = valueVector;
opIndex += 2; opIndex += 2;
break; break;
case ExtendedPhysics.PHYS_PARAM_LINEAR_LIMIT_HIGH: case ExtendedPhysics.PHYS_PARAM_LINEAR_LIMIT_HIGH:
errMsg = "PHYS_PARAM_LINEAR_LIMIT_HIGH takes one parameter of type vector";
valueVector = (OMV.Vector3)pParams[opIndex + 1]; valueVector = (OMV.Vector3)pParams[opIndex + 1];
linkInfo.linearLimitHigh = valueVector; linkInfo.linearLimitHigh = valueVector;
opIndex += 2; opIndex += 2;
break; break;
case ExtendedPhysics.PHYS_PARAM_ANGULAR_LIMIT_LOW: case ExtendedPhysics.PHYS_PARAM_ANGULAR_LIMIT_LOW:
errMsg = "PHYS_PARAM_ANGULAR_LIMIT_LOW takes one parameter of type vector";
valueVector = (OMV.Vector3)pParams[opIndex + 1]; valueVector = (OMV.Vector3)pParams[opIndex + 1];
linkInfo.angularLimitLow = valueVector; linkInfo.angularLimitLow = valueVector;
opIndex += 2; opIndex += 2;
break; break;
case ExtendedPhysics.PHYS_PARAM_ANGULAR_LIMIT_HIGH: case ExtendedPhysics.PHYS_PARAM_ANGULAR_LIMIT_HIGH:
errMsg = "PHYS_PARAM_ANGULAR_LIMIT_HIGH takes one parameter of type vector";
valueVector = (OMV.Vector3)pParams[opIndex + 1]; valueVector = (OMV.Vector3)pParams[opIndex + 1];
linkInfo.angularLimitHigh = valueVector; linkInfo.angularLimitHigh = valueVector;
opIndex += 2; opIndex += 2;
break; break;
case ExtendedPhysics.PHYS_PARAM_USE_FRAME_OFFSET: case ExtendedPhysics.PHYS_PARAM_USE_FRAME_OFFSET:
valueBool = (bool)pParams[opIndex + 1]; errMsg = "PHYS_PARAM_USE_FRAME_OFFSET takes one parameter of type integer (bool)";
valueBool = ((int)pParams[opIndex + 1]) != 0;
linkInfo.useFrameOffset = valueBool; linkInfo.useFrameOffset = valueBool;
opIndex += 2; opIndex += 2;
break; break;
case ExtendedPhysics.PHYS_PARAM_ENABLE_TRANSMOTOR: case ExtendedPhysics.PHYS_PARAM_ENABLE_TRANSMOTOR:
valueBool = (bool)pParams[opIndex + 1]; errMsg = "PHYS_PARAM_ENABLE_TRANSMOTOR takes one parameter of type integer (bool)";
valueBool = ((int)pParams[opIndex + 1]) != 0;
linkInfo.enableTransMotor = valueBool; linkInfo.enableTransMotor = valueBool;
opIndex += 2; opIndex += 2;
break; break;
case ExtendedPhysics.PHYS_PARAM_TRANSMOTOR_MAXVEL: case ExtendedPhysics.PHYS_PARAM_TRANSMOTOR_MAXVEL:
errMsg = "PHYS_PARAM_TRANSMOTOR_MAXVEL takes one parameter of type float";
valueFloat = (float)pParams[opIndex + 1]; valueFloat = (float)pParams[opIndex + 1];
linkInfo.transMotorMaxVel = valueFloat; linkInfo.transMotorMaxVel = valueFloat;
opIndex += 2; opIndex += 2;
break; break;
case ExtendedPhysics.PHYS_PARAM_TRANSMOTOR_MAXFORCE: case ExtendedPhysics.PHYS_PARAM_TRANSMOTOR_MAXFORCE:
errMsg = "PHYS_PARAM_TRANSMOTOR_MAXFORCE takes one parameter of type float";
valueFloat = (float)pParams[opIndex + 1]; valueFloat = (float)pParams[opIndex + 1];
linkInfo.transMotorMaxForce = valueFloat; linkInfo.transMotorMaxForce = valueFloat;
opIndex += 2; opIndex += 2;
break; break;
case ExtendedPhysics.PHYS_PARAM_CFM: case ExtendedPhysics.PHYS_PARAM_CFM:
errMsg = "PHYS_PARAM_CFM takes one parameter of type float";
valueFloat = (float)pParams[opIndex + 1]; valueFloat = (float)pParams[opIndex + 1];
linkInfo.cfm = valueFloat; linkInfo.cfm = valueFloat;
opIndex += 2; opIndex += 2;
break; break;
case ExtendedPhysics.PHYS_PARAM_ERP: case ExtendedPhysics.PHYS_PARAM_ERP:
errMsg = "PHYS_PARAM_ERP takes one parameter of type float";
valueFloat = (float)pParams[opIndex + 1]; valueFloat = (float)pParams[opIndex + 1];
linkInfo.erp = valueFloat; linkInfo.erp = valueFloat;
opIndex += 2; opIndex += 2;
break; break;
case ExtendedPhysics.PHYS_PARAM_SOLVER_ITERATIONS: case ExtendedPhysics.PHYS_PARAM_SOLVER_ITERATIONS:
errMsg = "PHYS_PARAM_SOLVER_ITERATIONS takes one parameter of type float";
valueFloat = (float)pParams[opIndex + 1]; valueFloat = (float)pParams[opIndex + 1];
linkInfo.solverIterations = valueFloat; linkInfo.solverIterations = valueFloat;
opIndex += 2; opIndex += 2;
break; break;
case ExtendedPhysics.PHYS_PARAM_SPRING_AXIS_ENABLE: case ExtendedPhysics.PHYS_PARAM_SPRING_AXIS_ENABLE:
errMsg = "PHYS_PARAM_SPRING_AXIS_ENABLE takes two parameters of types integer and integer (bool)";
valueInt = (int)pParams[opIndex + 1]; valueInt = (int)pParams[opIndex + 1];
valueBool = ((int)pParams[opIndex + 2] != 0); valueBool = ((int)pParams[opIndex + 2]) != 0;
GetAxisRange(valueInt, out axisLow, out axisHigh); GetAxisRange(valueInt, out axisLow, out axisHigh);
for (int ii = axisLow; ii <= axisHigh; ii++) for (int ii = axisLow; ii <= axisHigh; ii++)
linkInfo.springAxisEnable[ii] = valueBool; linkInfo.springAxisEnable[ii] = valueBool;
opIndex += 3; opIndex += 3;
break; break;
case ExtendedPhysics.PHYS_PARAM_SPRING_DAMPING: case ExtendedPhysics.PHYS_PARAM_SPRING_DAMPING:
errMsg = "PHYS_PARAM_SPRING_DAMPING takes two parameters of types integer and float";
valueInt = (int)pParams[opIndex + 1]; valueInt = (int)pParams[opIndex + 1];
valueFloat = (float)pParams[opIndex + 2]; valueFloat = (float)pParams[opIndex + 2];
GetAxisRange(valueInt, out axisLow, out axisHigh); GetAxisRange(valueInt, out axisLow, out axisHigh);
@ -737,6 +756,7 @@ public sealed class BSLinksetConstraints : BSLinkset
opIndex += 3; opIndex += 3;
break; break;
case ExtendedPhysics.PHYS_PARAM_SPRING_STIFFNESS: case ExtendedPhysics.PHYS_PARAM_SPRING_STIFFNESS:
errMsg = "PHYS_PARAM_SPRING_STIFFNESS takes two parameters of types integer and float";
valueInt = (int)pParams[opIndex + 1]; valueInt = (int)pParams[opIndex + 1];
valueFloat = (float)pParams[opIndex + 2]; valueFloat = (float)pParams[opIndex + 2];
GetAxisRange(valueInt, out axisLow, out axisHigh); GetAxisRange(valueInt, out axisLow, out axisHigh);
@ -745,7 +765,8 @@ public sealed class BSLinksetConstraints : BSLinkset
opIndex += 3; opIndex += 3;
break; break;
case ExtendedPhysics.PHYS_PARAM_USE_LINEAR_FRAMEA: case ExtendedPhysics.PHYS_PARAM_USE_LINEAR_FRAMEA:
valueBool = (bool)pParams[opIndex + 1]; errMsg = "PHYS_PARAM_USE_LINEAR_FRAMEA takes one parameter of type integer (bool)";
valueBool = ((int)pParams[opIndex + 1]) != 0;
linkInfo.useLinearReferenceFrameA = valueBool; linkInfo.useLinearReferenceFrameA = valueBool;
opIndex += 2; opIndex += 2;
break; break;
@ -753,18 +774,22 @@ public sealed class BSLinksetConstraints : BSLinkset
break; break;
} }
} }
catch (InvalidCastException e)
{
m_physicsScene.Logger.WarnFormat("{0} value of wrong type in physSetLinksetParams: {1}, err={2}",
LogHeader, errMsg, e);
}
catch (Exception e)
{
m_physicsScene.Logger.WarnFormat("{0} bad parameters in physSetLinksetParams: {1}", LogHeader, e);
}
} }
// Something changed so a rebuild is in order
Refresh(child);
} }
// Something changed so a rebuild is in order
Refresh(child);
} }
} }
catch (Exception e) break;
{
// There are many ways to mess up the parameters. If not just right don't fail without some error.
m_physicsScene.Logger.WarnFormat("{0} bad parameters in physSetLinksetParams: {1}", LogHeader, e);
}
break;
default: default:
ret = base.Extension(pFunct, pParams); ret = base.Extension(pFunct, pParams);
break; break;
@ -779,11 +804,11 @@ public sealed class BSLinksetConstraints : BSLinkset
{ {
switch (rangeSpec) switch (rangeSpec)
{ {
case ExtendedPhysics.PHYS_AXIS_ALL_LINEAR: case ExtendedPhysics.PHYS_AXIS_LINEAR_ALL:
low = 0; low = 0;
high = 2; high = 2;
break; break;
case ExtendedPhysics.PHYS_AXIS_ALL_ANGULAR: case ExtendedPhysics.PHYS_AXIS_ANGULAR_ALL:
low = 3; low = 3;
high = 5; high = 5;
break; break;