to ease the creation of a common interface for other physics apis as well, can i do the stuff usually done in callback by calling the function before NewtonUpdate() for each body?
I've not tried out. If there are any disadvantages, i'll choose another way.
Here's an axample user interaction callback, which contains all function calls that i think i need for any purpose.
Would all of those work as ecpected? Are there any substep issues?
- Code: Select all
static void PhysicsApplyHandForce (const NewtonBody* body, dFloat timestep, int threadIndex)
{
dFloat mass;
dFloat Ixx;
dFloat Iyy;
dFloat Izz;
dVector com;
dVector veloc;
dMatrix matrix;
//if (chainForceCallBack) chainForceCallBack (body, timestep, threadIndex);
NewtonBodyGetVelocity (body, &veloc[0]);
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
dVector force (pickedForce.Scale (mass * MOUSE_PICK_STIFFNESS));
dVector dampForce (veloc.Scale (mass * MOUSE_PICK_DAMP));
force -= dampForce;
NewtonBodyGetMatrix(body, &matrix[0][0]);
NewtonBodyGetCentreOfMass (body, &com[0]);
if (0) // com impulse
{
dVector linVel (pickedForce.Scale(1 / timestep));
NewtonBodySetVelocity (body, &linVel.m_x);
}
else
{
NewtonBodyAddForce (body, &force.m_x);
}
// orientation...
dQuaternion q;
NewtonBodyGetRotation (body, &q.m_q0);//
dVector curAngVel; NewtonBodyGetOmega (body, &curAngVel.m_x);
dVector targetAngVel = AngVelFromAToB (q, gHandOrn).Scale (1 / timestep * 0.1);
if (0) // ang impulse
{
NewtonBodySetOmega (body, &targetAngVel.m_x);
}
else
{
dVector torque = ConvertAngVelToTorque (targetAngVel, curAngVel, matrix,
timestep, mass, Ixx, Iyy, Izz);
NewtonBodyAddTorque (body, &torque[0]);
}
NewtonBodySetFreezeState (body, 0);
}