Trigger Volumes

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Trigger Volumes

Postby carli2 » Wed Oct 24, 2012 11:15 am

But why does newton provide these two functions? NewtonCollisionIsTriggerVolume and NewtonCollisionSetAsTriggerVolume
carli2
 
Posts: 157
Joined: Thu Nov 10, 2011 1:53 pm

Re: Trigger Volumes

Postby Julio Jerez » Wed Oct 24, 2012 11:59 am

because the are legacy from core 200. The kinematic body is a more powerfull concept

latee when the I add teh option DoNoGenerate contact to a collsion shape, then a full truuger will be a kenematc body in wich teh shape has that option set.
this will make lighwight. if teh option is set then it will generate contacts.

a dynamics body can also have a compond shape in which some subshapes has the do not generate contact option set to on. thoso will act as trigger that are part of the shape and you get the callback.

This is a more more peweful and flexible system, and it does no required special code pathway in the collision system.

Please try using kinematic body for trigger, you will see it is better.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Trigger Volumes

Postby carli2 » Wed Oct 24, 2012 3:28 pm

In the moment I use the following code:

In the ConvexCast prefilter I kick the triggers out to get a view of the solid world:
Code: Select all
function myprefilter(body: PNewtonBody; collision: PNewtonCollision; userData: Pointer): cardinal; cdecl;
begin
 result:=integer((TWorldObject(userData).newton<>body) and (NewtonCollisionIsTriggerVolume(NewtonBodyGetCollision(body))=0));
end;


A collision in my game is marked as trigger and then newton is informed about the state:
Code: Select all
if trigger then NewtonCollisionSetAsTriggerVolume(col, 1);


How should I use your system now? How do I have to change the prefilter code to detect a triggered body?
I think I have to move the trigger code from collision creation to the object creation.

Is there some entry in the wiki that explains the difference bezween dynamic and kinematik?
carli2
 
Posts: 157
Joined: Thu Nov 10, 2011 1:53 pm

Re: Trigger Volumes

Postby Julio Jerez » Wed Oct 24, 2012 4:32 pm

You create a kinematic body
Code: Select all
Int mytriggercode = some special value
NewtonWorld* const world = scene->GetNewton();
NewtonCollision* const collision = CreateConvexCollision (world, &aligment[0][0], size, _BOX_PRIMITIVE, mytriggercode);
NewtonCollision* triggerBody = NewtonCreateKinematicBody(world, collision, &matrix[0][0]);
      NewtonBodySetUserData(m_tornadoBody, this);
      NewtonBodySetTransformCallback(m_tornadoBody, DemoEntity::TransformCallback);

In a convex cast you can check for the collision id of the collision shape of the hit body, if the ID match mytriggercode, then it is a trigger.

for body to body you iterate over the contact joint of the triggerBody, each joint will be a boy in teh trigger shape.
or you can do the same in a callback.

Sync to svn, I just place 25 players, in te hscene, the players are kenamti bodies, and they are all collected in the callback of the calling player.
you cn amove aroiudn and you see hwo i collide, by you can also make no colladibel by rejectin that contact.
you can do anything you want, and it is cost effective.

if you still has problem I will make a trigger demo.

The triggers are all there, it is just that they are no called triggers, because they are much more versitile than just triggers.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Trigger Volumes

Postby carli2 » Fri Oct 26, 2012 9:49 am

Yes, that works, thanks :)

(I abused the UserID of the collision to reflect the trigger flag and create kinematic bodies for triggers. the RPG works now)
carli2
 
Posts: 157
Joined: Thu Nov 10, 2011 1:53 pm

Re: Trigger Volumes

Postby Julio Jerez » Fri Oct 26, 2012 10:43 am

carli2 wrote:(I abused the UserID of the collision to reflect the trigger flag and create kinematic bodies for triggers. the RPG works now)


That's is not abused, tha is the porpuse of that field is for the client application to do what si want to do with it.
one perfect ligitimal use if to make materials.
That oen fo teh big diffrentce with core 200, copre 200 shape were shared and teh coudl no have diffrent ID unless they where duplicated.
now two identical boxes, for example, can have different IDs and still share the data internally.

what Game is that you are working?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Trigger Volumes

Postby carli2 » Sun Oct 28, 2012 3:59 pm

http://goldenwipf.de

It's a kind of universal game engine, so the engine may run untrusted code (from a server in a network game) and the physics are completely accessible via the scripting API.
It's a very big and interesting project, we will release in December.
carli2
 
Posts: 157
Joined: Thu Nov 10, 2011 1:53 pm

Re: Trigger Volumes

Postby pHySiQuE » Wed Jan 23, 2013 6:20 am

Has anything been done that would cause NewtonCollisionClosestPoint() to stop working as an intersection test? It's supposed to return 0 if the bodies intersect, right?
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Trigger Volumes

Postby Julio Jerez » Wed Jan 23, 2013 8:24 am

I did not understand that question.
But I just re enable the closest point demo which use that function , and it seems to work
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Trigger Volumes

Postby pHySiQuE » Wed Jan 23, 2013 11:42 am

I am using the function NewtonCollisionClosestPoint() as an intersection test. If the function returns 0, the collisions are intersecting. If the function returns 1, they are not intersecting, and a closest point is returned.

This code demonstrates the behavior has changed, and returns 1 when collisions are intersecting. (It should return 0.) This means I can't use it as an intersection test:
Code: Select all
NewtonWorld* newtonworld = NewtonCreate();
NewtonCollision* newtoncollision = NewtonCreateBox(newtonworld,10,10,10,0,NULL);
dFloat mat0[16] = {1.0,0.0,0.0,0.0, 0.0,1.0,0.0,0.0, 0.0,0.0,1.0,0.0, 0.1,0.0,0.0,1.0};
dFloat mat1[16] = {1.0,0.0,0.0,0.0, 0.0,1.0,0.0,0.0, 0.0,0.0,1.0,0.0, 0.0,0.0,0.0,1.0};
dFloat contactA[3];
dFloat contactB[3];
dFloat normalAB[3];
if (NewtonCollisionClosestPoint(newtonworld, newtoncollision, mat0, newtoncollision, mat1, contactA, contactB, normalAB, 0)==1)
{
   printf("1");
}
else
{
   printf("0");
}
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Trigger Volumes

Postby Julio Jerez » Wed Jan 23, 2013 12:25 pm

This si the code closet of closet point funtion
Code: Select all
bool dgCollisionConvex::CalculateClosestPoints (dgCollisionParamProxy& proxy) const
{
   _ASSERTE (this == proxy.m_referenceCollision->m_childShape);
   dgMinkHull minkHull (proxy);
   minkHull.CalculateClosestPoints ();

   dgContactPoint* const contactOut = proxy.m_contacts;
   dgCollisionInstance* const collConicConvexInstance = proxy.m_referenceCollision;
   dgVector p (ConvexConicSupporVertex(minkHull.m_p, minkHull.m_normal));

   const dgVector& scale = collConicConvexInstance->m_scale;
   const dgVector& invScale = collConicConvexInstance->m_invScale;
   const dgMatrix& matrix = collConicConvexInstance->GetGlobalMatrix();
   dgVector normal (matrix.RotateVector(invScale.CompProduct4(minkHull.m_normal)));
   normal = normal.Scale(dgRsqrt(normal % normal));

   contactOut[0].m_normal = normal;
   contactOut[0].m_point = matrix.TransformVector(scale.CompProduct4(p));

   contactOut[1].m_normal = normal.Scale (-1.0f);
   contactOut[1].m_point = matrix.TransformVector(scale.CompProduct4(minkHull.m_q));
   return true;
}

as you can see it does not return false ever. that funtion is called by thsi funtions

Code: Select all
dgInt32 dgWorld::ClosestPoint (dgCollisionParamProxy& proxy) const   
{
   dgCollisionInstance* const collision1 = proxy.m_referenceCollision;
   dgCollisionInstance* const collision2 = proxy.m_floatingCollision;
   if (!(collision1->GetConvexVertexCount() && collision2->GetConvexVertexCount())) {
      return 0;
   }

...
}

as you can see it can return 0 or false, by this is for the cases of shapes that can not be casted. stuff like heighfield, NULL collsion scene collsion
this is different that preivisue version wherer closest point returned 0, in new core 300 it always returns the closest point even if the shape are penetrations.

This is more useful beacsue it also give you teh same funtionality, to can detect penetration usin closet point by doingt this

Code: Select all
      bool penetration = false;
      if (NewtonCollisionClosestPoint(world, collisionA, &matrixA[0][0], m_castingVisualEntity->m_castingShape, &matrixB[0][0], &m_castingVisualEntity->m_contact0[0], &m_castingVisualEntity->m_contact1[0], &m_castingVisualEntity->m_normal[0], 0))
         penetration = (((m_castingVisualEntity->m_contact1 - m_castingVisualEntity->m_contact0) % m_castingVisualEntity->m_normal) >= 0) ? true : false;
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Trigger Volumes

Postby Julio Jerez » Wed Jan 23, 2013 12:29 pm

thsi is your same example modified

Code: Select all
NewtonCollision* newtoncollision = NewtonCreateBox(newtonworld,10,10,10,0,NULL);
dFloat mat0[16] = {1.0,0.0,0.0,0.0, 0.0,1.0,0.0,0.0, 0.0,0.0,1.0,0.0, 0.1,0.0,0.0,1.0};
dFloat mat1[16] = {1.0,0.0,0.0,0.0, 0.0,1.0,0.0,0.0, 0.0,0.0,1.0,0.0, 0.0,0.0,0.0,1.0};
dFloat contactA[3];
dFloat contactB[3];
dFloat normalAB[3];
if (NewtonCollisionClosestPoint(newtonworld, newtoncollision, mat0, newtoncollision, mat1, contactA, contactB, normalAB, 0)==1)
{
   // shape has close point
   // cheack for penetration
      dFloat diff[3];
     diff[0] = contactB[0] - contactA[0];
     diff[1] = contactB[1] - contactA[1];
     diff[2] = contactB[2] - contactA[2];
      bool penetration = dotproduct (diff, noprmalAB) < 0 ? true : false;
}
else
{
  // shape do no have closest pooint
   printf("0");
}
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Trigger Volumes

Postby pHySiQuE » Wed Jan 23, 2013 12:57 pm

I had to flip the sign of the diff vector, but yeah it works. Thanks!
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron