Trigger volumes

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Trigger volumes

Postby rabbit » Tue Oct 27, 2009 8:37 am

A friend recently showed me some callbacks offered in nxogre (physx wrapper).

He was able to trigger events from an onenter and an onexit callback.

Is it possible to do the same with newton? if possible how, if not, may i request the functionality in the next build?
rabbit
 
Posts: 18
Joined: Fri Mar 27, 2009 7:01 am

Re: Trigger volumes

Postby JernejL » Tue Oct 27, 2009 9:24 am

Newton supports this thru NewtonCollisionSetAsTriggerVolume function, but i don't know how it is intended to be used (proper documentation on wiki for this new function hasn't been written yet), there is likely a demo in sdk.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Trigger volumes

Postby agi_shi » Tue Oct 27, 2009 3:27 pm

Delfi wrote:Newton supports this thru NewtonCollisionSetAsTriggerVolume function, but i don't know how it is intended to be used (proper documentation on wiki for this new function hasn't been written yet), there is likely a demo in sdk.

This only disregards the contacts in order for higher efficiency, it's not actually required for a trigger.

What you want to do is create a material contact callback that stores objects in a dictionary between object and time since contact. On every contact, check if the object is already stored -if not, then you have an onEnter() event. If it was already stored, then simply subtract the delta time from the time since contact. In some other per-frame method, add the delta time to the time since contact. If the time since contact is now greater than some constant (perhaps twice the physics step size), the object has left the trigger and you have an onExit() event and remove the object from the dictionary.
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: Trigger volumes

Postby Julio Jerez » Tue Oct 27, 2009 4:53 pm

agi_shi wrote:This only disregards the contacts in order for higher efficiency, it's not actually required for a trigger.

What you want to do is create a material contact callback that stores objects in a dictionary between object and time since contact. On every contact, check if the object is already stored -if not, then you have an onEnter() event. If it was already stored, then simply subtract the delta time from the time since contact. In some other per-frame method, add the delta time to the time since contact. If the time since contact is now greater than some constant (perhaps twice the physics step size), the object has left the trigger and you have an onExit() event and remove the object from the dictionary.


This is very good idea, I will add few ideas to agi_shi sugestion,
first I will clarify that since triggers are meant to be big volumnes, the option set as trigger play an importnat role when triggers are Big and have many bodies on fligh.
Secund the only reason I an refining your idea is because if does no consider if a body go to rest inside a trigger.
Plus I beleive your idea is correct but can be implemented much simpler without tracking time or contacts.

-Make a Material and call it trigger or whatever.
-asign a dictinonary or a Map to the Trigger body.
-add a Force and Torque callback to prosses the Trigger Bodies.
-in this funtion back tree things can happens
-1 body can enter the trigger,
-2 body can be in teh trigger,
-3 body can be out of eth trigger

basically the callback should looks like this

Code: Select all
void TriggerForceAndTorqueCallback (const NewtonBody* body)
{
   // find OnEnter Event, these are the bodes that enter in the Dictionary for the First Time
   for (NewtonJoint* joint = NewtonBodyGetFirstContactJoint (body); joint; joint = NewtonBodyGetNextContactJoint (body, joint)) {
      const NewtonBody* otherBody;

      // get the othe Body from the joint
      otherBody = (NewtonJointGetBody0 (joint) != body) ? NewtonJointGetBody0 (joint) : NewtonJointGetBody1 (joint) ;

      // See if this Body is in the Dictionary (an STL map will do)
      if (!Map.find (otherBody)) {
         Map.Insert (otherBody);
         // issue the OnEmnetdEvenet Here
         OneEnter (otherBody);
      } else {
         // optinally you can issue a while in trigget here
      }
   }


   // Now you chech for bodies hwo left the Trigger, These are bodies how are in the Map but tha tdo not has trigerJoints
   for (node = Map.GetFist(); node; node = nextNodt)
      node = NextNode;
      NewtonJoint* joint;
      // the Body is in the Trigger is it still have a contact Joint
      for (joint = NewtonBodyGetFirstContactJoint (body); joint; joint = NewtonBodyGetNextContactJoint (body, joint)) {
         if ((node->GetBody() == NewtonJointGetBody0 (joint)) || (node->GetBody() == NewtonJointGetBody1 (joint))) {
            break;
         }
         if (joint) {
            // the body left the trigger region, remove from the map and issue and OnExit event
            Map.Remove (node);
            OneEnter (node->GetBody());
         }
      }
     }

}


As you can see some features are no really feature at all,
It is just diffrent flavors of the same thing but some people add all the stuff to make it looks as if it was bigger.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Trigger volumes

Postby agi_shi » Wed Oct 28, 2009 3:33 pm

Wow that is *very* interesting, I did not know you can get the contacting bodies during the force and torque callback.
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: Trigger volumes

Postby Julio Jerez » Wed Oct 28, 2009 5:28 pm

As of newton 2.0 there are iterator for getting joints, the contacts joints, Materials, and Bodies from any place even form outside a newton update.
so you not longer need to do everything in callbacks,
although doing stuff in the apropriate callback is the most efficient way of doing must things in general,

That Newton Engine is full of suprices isn't it, even dark masters can get fool by it some time.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron