i've started looking though the forums looking at what some people have requested and added 1 function i also wanted added which is very useful for basic objects that require just a set force added to them each time, instead of the need of creating a procedure to be called outside of newtion... anyways i will share the update (it would be nice if there is a section on the forum to post such things... anyways
in files
newton.h
- Code: Select all
NEWTON_API void NewtonBodySetConstForce (const NewtonBody* body, dFloat x, dFloat y, dFloat z); //Colin Stewart - 16.02.2011
Newton.cpp
- Code: Select all
//Colin Stewart - 16.02.2011
void NewtonBodySetConstForce(const NewtonBody* bodyPtr, dFloat x, dFloat y, dFloat z)
{
dgBody *body;
body = (dgBody *)bodyPtr;
body->SetConstForce(dgVector(x,y,z,0));
}
dgBody.h
- Code: Select all
//Colin Stewart - 16.02.2011
inline void dgBody::SetConstForce(const dgVector& force)
{
m_constantForce = force;
}
add to the class declaration also:
both
- Code: Select all
void SetConstForce(const dgVector& force); //Colin Stewart - 16.02.2011
and
- Code: Select all
dgVector m_constantForce; //added 16.02.2011 - Colin Stewart
also find the inline procedure dgBody::ApplyExtenalForces (dgFloat32 timestep, dgInt32 threadIndex)
change it to >
- Code: Select all
inline void dgBody::ApplyExtenalForces (dgFloat32 timestep, dgInt32 threadIndex)
{
m_accel = dgVector (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));
m_alpha = dgVector (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));
//Colin Stewart - 16.02.2011
if ((m_constantForce.m_x != 0) || (m_constantForce.m_y != 0) || (m_constantForce.m_z != 0)) {
//add any repeating internal forces here....
this->AddForce(m_constantForce);
}
if (m_applyExtForces) {
m_applyExtForces(*this, timestep, threadIndex);
}
}
now in your include header for newton you add (in my case i wrote include for delphi so u will need to add this in c (easy enough)
- Code: Select all
procedure NewtonBodySetConstForce(const body: PNewtonBody; x,y,z: Float); cdecl; external NewtonDLL;
ok so basically rather then create a function that is called by newton on ForceAndTorque callback, you no longer need to do this for simple objects you just call once on creation of the newton body
- Code: Select all
NewtonBodySetConstForce(Result.ptrBody, 0, -10 * Result.fMass, 0);
this would be the equivelent of adding a callback which the callback would keep adding gravity * mass, note you can still set a regular callback also for more advanced forces/torque, this can be set as a constant downforce e.g. gravity
@ Julio, if you would consider adding this to next release? i can send you the actual updated files if neccasary, i think it is quite useful, i already use it, and i see it has been requested before
-Colin