Sign in to follow this  
photo

PhysicalTrigger functions question

Recommended Posts

In Entercallback function, Is there a way to get contactpoint directly? ( using a way trigger->getContactPoint(int contact) , body->getContactPoint(int num) or another )

Can I get the contact number of the current contact right away?

 

and Does the Entercallback function run only once when contacted moment, and getNumContacts() continue to have the same return value while the contact continues?

Edited by dongju.jeong

Share this post


Link to post

Could you please specify what do you mean by "get contactpoint directly"? I'm not sure if get you right.

Quote

Can I get the contact number of the current contact right away?

As for getting a contact number, how do you plan to use this number? The point is that a contact can be handled by any of the bodies that participate in it. If the contact is assigned to and handled by another body (it's random), the number of contacts for the current body is not incremented. So, if you've got two bodies having a contact, they will not have "copies" of this particular contact with the same number, in fact, only one of the bodies will have it, the one that handles it.

Quote

Does the Entercallback function run only once when contacted moment, and getNumContacts() continue to have the same return value while the contact continues?

Yes.

Thanks!

  • Like 1

Share this post


Link to post

 

Spoiler

//callback function (physical trigger)
void Haptic::trigger_enter(BodyPtr body)
{
	ObjButton* bt = getComponent<ObjButton>(body->getObject()->getNode());
	if (bt)
		EnterButtonBodys.push_back(bt);

      // +I want to get the current contact number or the contact point in here.
      
      
}

 

 

Share this post


Link to post

Hi Dongju,

You can get contact points for the entering body like this:

//callback function (physical trigger)
void Haptic::trigger_enter(BodyPtr body)
{
	ObjButton* bt = getComponent<ObjButton>(body->getObject()->getNode());
	if (bt)
		EnterButtonBodys.push_back(bt);

      // --------------------------------------------------------
			Vector<int> contact_numbers;

			int num_body_shapes = body->getNumShapes();
			int num_contacts = trigger->getNumContacts();

			// checking which of the shapes collided with the trigger 
			// belong to the currently entering body (a body can have several shapes)
			// and remembering contact numbers
			for (int i = 0; i < num_contacts; i++)
				for (int j = 0; j < num_body_shapes; j++) 
				{
					if (trigger->getContactShape(i) == body->getShape(j)) 
					{
						contact_numbers.append(i);
						break;
					}
				}
			
  			// printing all contact points detected for the body
			for (int ci = 0; ci < contact_numbers.size(); ci++) 
			{
				vec3 p = trigger->getContactPoint(ci);
				Log::message("\nBody contact point [%d]: (%f, %f, %f)", ci, p.x, p.y, p.z);
			}
      // --------------------------------------------------------
}

Hope this helps!

Thanks!

  • Like 1

Share this post


Link to post
Sign in to follow this