How to avoid Force and Torque callback

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

How to avoid Force and Torque callback

Postby JoeJ » Sat Jan 15, 2011 8:39 am

Hi,

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);
}
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: How to avoid Force and Torque callback

Postby Julio Jerez » Sat Jan 15, 2011 9:07 am

No.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How to avoid Force and Torque callback

Postby JernejL » Sat Jan 15, 2011 12:49 pm

You can accumulate forces elsewhere as you desire but still have to apply them during the callback.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron