Forces not applying when colliding migrating from 200 to 300

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Forces not applying when colliding migrating from 200 to 300

Postby wivlaro » Mon Jul 22, 2013 3:30 pm

I have a strange problem. In switching my code from Newton 200 to 300, I have changed my NewtonCreateBody calls to NewtonCreateDynamicBody, and updated the other small API changes. The problem is that when my player body is colliding, the ForceAndTorqueCallback stops being called.

Any ideas? Is there any documentation for 300 at all? I can't find anything myself.

I have set up my player body like this:

Code: Select all
    float lx = 1.92 * 2;
    float ly = 1.48 * 2;
    float lz = 0.408 * 2;
   NewtonCollision* box = NewtonCreateBox(world, lx, ly, lz, 0, nullptr);
   body = NewtonCreateDynamicBody(world, box, matrix.m);

   NewtonBodySetUserData(body, this);
    dFloat angularDamping[]{0.05,0.05,0.05};
    NewtonBodySetAngularDamping(body, angularDamping);
    NewtonBodySetLinearDamping(body, 0.275f);

   float mass = 5;
   float   Ixx = mass * (ly*ly + lz*lz) / 12,
         Iyy = mass * (lx*lx + lz*lz) / 12,
         Izz = mass * (lx*lx + ly*ly) / 12;
   NewtonBodySetMassMatrix(body, mass, Ixx, Iyy, Izz);

    NewtonBodySetForceAndTorqueCallback(body, Craft::applyForce);
    NewtonBodySetTransformCallback(body, Craft::onNewTransform);


In my applyForce callback, I am basically only modifying the body using NewtonBodySetForce and NewtonBodySetTorque.

Thanks for any ideas
wivlaro
 
Posts: 10
Joined: Sun Jul 21, 2013 5:16 am

Re: Forces not applying when colliding migrating from 200 to

Postby Julio Jerez » Mon Jul 22, 2013 4:30 pm

That is not possible, force and torque callback is call for all dynamics bodies even when they are at rest.
The function is called form this loop

Code: Select all
void dgBroadPhase::ApplyForceAndtorque (dgBroadphaseSyncDescriptor* const descriptor, dgInt32 threadID)
{
   dgFloat32 timestep = descriptor->m_timestep;

   dgBodyMasterList::dgListNode* node = NULL;
   {
      dgThreadHiveScopeLock lock (m_world, descriptor->m_lock);
      node = descriptor->m_forceAndTorqueBodyNode;
      if (node) {
         descriptor->m_forceAndTorqueBodyNode = node->GetNext();
      }
   }

   for ( ; node; ) {
      dgBody* const body = node->GetInfo().GetBody();

      if (body->IsRTTIType(dgBody::m_dynamicBodyRTTI)) {
         dgDynamicBody* const dymamicBody = (dgDynamicBody*) body;

// this is the call to force and toruqe callback and it alway happen for all dynamcis bodies
         dymamicBody->ApplyExtenalForces (timestep, threadID);
         if (!dymamicBody->IsInEquilibrium ()) {
            dymamicBody->m_sleeping = false;
            dymamicBody->m_equilibrium = false;



when yo usay player, is that play a dynamics actor?
Julio
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Forces not applying when colliding migrating from 200 to

Postby wivlaro » Tue Jul 23, 2013 1:14 pm

Yes, sorry player is a DynamicBody. My mistake, the callback is being called, but the forces I set do not do anything. It seems as soon as the bodies are intersecting.
wivlaro
 
Posts: 10
Joined: Sun Jul 21, 2013 5:16 am

Re: Forces not applying when colliding migrating from 200 to

Postby Julio Jerez » Tue Jul 23, 2013 1:19 pm

if ttow bodeis are collidning an da force is no strong enough to move then, the teh force will have noeffect.

can you make a video, so that I can see what is going on?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Forces not applying when colliding migrating from 200 to

Postby wivlaro » Tue Jul 23, 2013 1:34 pm



The thruster graphics should make it quite clear to see when I'm applying forces. So only just at the point where the bodies stop intersecting does the force get applied again. Also, probably most importantly, I've lost the collision responses. :oops:

The building's dynamic body is just made with NewtonCreateDynamicBody and I do nothing else to it. The collision box for the building is shared between many buildings.
wivlaro
 
Posts: 10
Joined: Sun Jul 21, 2013 5:16 am

Re: Forces not applying when colliding migrating from 200 to

Postby wivlaro » Tue Jul 23, 2013 1:43 pm

Aha! I have just been trying changing a few random Newton things - removing this line has "fixed" it:
Code: Select all
NewtonSetSolverModel(world, 0);
:)
wivlaro
 
Posts: 10
Joined: Sun Jul 21, 2013 5:16 am

Re: Forces not applying when colliding migrating from 200 to

Postby Julio Jerez » Tue Jul 23, 2013 2:39 pm

Oh you were using Netwon Solver mode 0?
that the exact solver for realistic simulation acurate, and I have not updated,

you should use solver more 1, it is teh fastest and is very acurate for games.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Forces not applying when colliding migrating from 200 to

Postby JoeJ » Tue Jul 23, 2013 2:57 pm

body = NewtonCreateDynamicBody(world, box, matrix.m);

Can you check if the last column of that matrix is correct (0,0,0,1) for all bodies?
If it is not, newton does not assert, but things go very wrong.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron