Forces do not work correctly with Newton3

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Forces do not work correctly with Newton3

Postby Lax » Sat Feb 24, 2018 9:09 am

Hi,

I'm using Newton quite for a while in my engine. In the past I used Newton2.x. I have the following destruction scenario:

I have some fragment bodies, that are connected together with hinge joints, forming the whole body (Container). As long as the force does not exceed the max. allowed breakforce the framents are tied together.
Now I'm throwing other objects at the container. Now with Newton2.x the container will break to peaces.
Since I'm using Newton3, the container will no more break.
I'm having custom force and torque callbacks, in which I add force etc. (NewtonBodySetForceAndTorqueCallback). Something is wrong with the forces. Has something significantly changed in Newton3? Do I miss a command? The forces I get for testing if its high enough to resolve the joints is never high enough and depending when I calculate the force, the acting force is even 0.

When I manually break the joints, the fragments have no gravity anymore, which is also strange, since each fragment has its own force and torque callback.

So there are several things strange.

Code:
Code: Select all
void PhysicsActiveDestructableComponent::SplitPart::splitPartMoveCallback(OgreNewt::Body* body, Ogre::Real timeStep, int threadIndex)
{
this->splitPartBody->setCustomForceAndTorqueCallback<PhysicsActiveDestructableComponent::SplitPart>(&PhysicsActiveDestructableComponent::SplitPart::splitPartMoveCallback, this);

void PhysicsActiveDestructableComponent::SplitPart::splitPartMoveCallback(OgreNewt::Body* body, Ogre::Real timeStep, int threadIndex)
   {
      Ogre::Real breakForceLength = body->getForce().squaredLength();
      Ogre::Real breakTorqueLength = body->getOmega().squaredLength();

      PhysicsActiveDestructableComponent::SplitPart* part = OgreNewt::any_cast<PhysicsActiveDestructableComponent::SplitPart*>(body->getUserData());
      // go through all joint handlers for a split part and if the acting force or torgue is stronger as the configured value,
      for (auto& jointCompPtr : part->getJointComponents())
      {
         // check if the force acting on the body is higher as the specified force to break the joint
         if (breakForceLength >= part->getBreakForce() /** part->getBreakForce()*/ || breakTorqueLength >= part->getBreakTorque() /** part->getBreakTorque()*/)
         {
            Ogre::LogManager::getSingletonPtr()->logMessage(Ogre::LML_CRITICAL, "[PhysicsActiveDestructableComponent::SplitPart] Force high enough!!!!");
            // If at least one part is broken, hide the placeholder scene node and show all parts
            if (false == this->physicsActiveDestructableComponent->firstTimeBroken && true == this->physicsActiveDestructableComponent->motionless->getBool())
            {
               this->physicsActiveDestructableComponent->gameObjectPtr->getSceneNode()->setVisible(false);
               for (auto& it = this->physicsActiveDestructableComponent->parts.cbegin(); it != this->physicsActiveDestructableComponent->parts.cend(); it++)
               {
                  it->second->sceneNode->setVisible(true);
               }
               this->physicsActiveDestructableComponent->firstTimeBroken = true;
            }

            // can be called by x-configured threads, therefore lock here the remove operation
            mutex.lock();

            if (jointCompPtr->getJoint())
            {
               part->setMotionLess(false);
               this->physicsActiveDestructableComponent->motionless->setValue(false);

               this->physicsActiveDestructableComponent->delayedDeleteJointComponentList.emplace(jointCompPtr);
            }
            // Also check all its predecessors and remove the joints if necessary
            auto& predecessorJointComponent = NOWA::makeStrongPtr(GameObjectController::getInstance()->getJointComponent(jointCompPtr->getPredecessorId()));
            if (predecessorJointComponent && predecessorJointComponent->getJoint())
            {
               this->physicsActiveDestructableComponent->delayedDeleteJointComponentList.emplace(predecessorJointComponent);
            }

            mutex.unlock();
         }
      }

      // will not work here, because force is 0 above, why???
      Ogre::Real mass;
      Ogre::Vector3 inertia;
      // calculate gravity
      body->getMassMatrix(mass, inertia);
      Ogre::Vector3 force = this->physicsActiveDestructableComponent->getGravity();
      force *= mass;
      // add the force that pushed towards earth
      body->setForce(force);
   }
}


Regards
Lax
Last edited by Lax on Tue Mar 06, 2018 5:52 am, edited 1 time in total.
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: Forces do not work correctly with Newton3

Postby Julio Jerez » Sat Feb 24, 2018 11:29 am

few things,
1- can you make a picture.
2-do you have the later committ, there was lot of work on the joint, but now all the basic joint are functional
so what yo describe should work.
3- after you sync in the problem is there can you post an executable some where, that I can download tha like to the newton DLL and newton Joint, so that I can debug the problem?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Forces do not work correctly with Newton3

Postby JoeJ » Sat Feb 24, 2018 11:50 am

Julio Jerez wrote:there was lot of work on the joint

Didn't you change something about max friction?
Previously it took mass into account, now this is left to the user?
(Not sure if that's related at all)
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: Forces do not work correctly with Newton3

Postby Julio Jerez » Sat Feb 24, 2018 11:58 am

oh yes the friction was change for some joints now is set as a force of a torque base of the teh row is,
use mass make unit less but is was a mistake, that some the use can control better.

but you say you are using hinges, I do no remember teh hinge has a break force, why joint are you using the one in the engine, teh dCustomHinge or one you make yourself.

BTW I just update the projects, if you sync before just do it again, or the binary will not run if you make a repro demo.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Forces do not work correctly with Newton3

Postby Lax » Tue Mar 06, 2018 5:51 am

but you say you are using hinges, I do no remember teh hinge has a break force, why joint are you using the one in the engine, teh dCustomHinge or one you make yourself.

Newton does not do that, its my own implementation. I just check, if the length of the force or torque is higher than the break force in the hinge joint. If this is the case, I destroy the joint.

In the forceAndTorqueCallback, I posted, with Newton2.x the force and torque has been calculated correctly for this body based on how hard the body has been hit by another body and how hard it has been rotated. I think this is no more the case, or I do not understand, how the scenario in the video below could work correctly. But I think, when one body does hit e.g. the wall, for each part the force and maybe torque should increase.
See the video with Newton2.x:
https://youtu.be/_FUqXxA_zZI
This scenario does not work anymore, as no matter how hard I throw the object and how high its mass is, the tower or the wall will never be destructed.

Note: The destructable objects had been fragmented to parts prior.
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: Forces do not work correctly with Newton3

Postby Julio Jerez » Tue Mar 06, 2018 9:41 am

it should work if you use the dCustomHinge

all the functionality in the old joint system is part of the new system. and there reason some stuff in teh old system does not work as before is that as improvement is made, stuff that take lot of work to maintain in the old system is simply disabled, because keeping redundant system is too hard.

try linking the dCustomJoint. then using that functionality is a matter of a funtion call, from anywhere
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Forces do not work correctly with Newton3

Postby Julio Jerez » Tue Mar 06, 2018 4:35 pm

Lax wrote:
but you say you are using hinges, I do no remember teh hinge has a break force, why joint are you using the one in the engine, teh dCustomHinge or one you make yourself.

Newton does not do that, its my own implementation. I just check, if the length of the force or torque is higher than the break force in the hinge joint. If this is the case, I destroy the joint.

ok, with the late commit it should the way you want now.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Forces do not work correctly with Newton3

Postby Lax » Thu Mar 08, 2018 8:06 am

Hi Julio,

ok, thanks! I will try it out soon.

Regards
Lax
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: Forces do not work correctly with Newton3

Postby JernejL » Fri Mar 09, 2018 3:37 am

Lax wrote:In the forceAndTorqueCallback, I posted, with Newton2.x the force and torque has been calculated correctly for this body based on how hard the body has been hit by another body and how hard it has been rotated.


Newton force torque callback should not be destroying joints (or bodies), this is also mentioned on the wiki documentation:

http://newtondynamics.com/wiki/index.ph ... stroyJoint
http://newtondynamics.com/wiki/index.ph ... estroyBody

Destroying bodies and joints from within forcetorque callback is undefined behavior, in my case i was having crashes because i was removing bodies due to this in newton 3, while newton 2 somehow was able to process it, it's possible that removing a joint from within forcetorque callback simply does nothing in newton3?

Just process your forcetorque callback and set a flag to destroy joints in post processing.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Forces do not work correctly with Newton3

Postby Julio Jerez » Fri Mar 09, 2018 9:31 am

JernejL wrote:Destroying bodies and joints from within forcetorque callback is undefined behavior,
...
Just process your forcetorque callback and set a flag to destroy joints in post processing.


thsi was allowed in 2.xx but as the engine is becoming more complex this simple made the logic to difficult for not reason, therefore is was remove.

stuff liek listeners and the factorization of joints connection for solving then fats make that logic to hard to manage.
The list is stilll there by the code logic does no work anymore.

I was done the same same way you say, you can put the on a list r vector and delete everything there after each time step.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Forces do not work correctly with Newton3

Postby Lax » Fri Mar 09, 2018 10:15 am

Hi,

Just process your forcetorque callback and set a flag to destroy joints in post processing.

yeah, thats what I did anyway. I just tagged the to be destroyed joints and pushed them to a list, which is updated in a normal update loop and not in the callback. Since the force and torque callback can be called from different threads, I also used a mutex.

Regards
Lax
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 2 guests

cron