Jump to content

How to attain "other" body's contact surface (or contact id) in contact callback?


Recommended Posts

I have MyClass that owns a BodyRigid, with contact callback set up. Inside the callback function, I would like to get the relevant surface for both bodies involved in the contact.

void MyClass::OnContact( Unigine::Ptr<Unigine::Body> ourBody, int contactID )
{
	int ourSurface=-1, body0Surface=-1, body1Surface=-1;
	ourSurface=ourBody->getContactSurface(contactID);
	if(ourBody->getContactBody0(contactID).get()) 
	{
		if(contactID<=ourBody->getContactBody0(contactID)->getNumContacts())
		{
			body0Surface=ourBody->getContactBody0(contactID)->getContactSurface(contactID);
		}
		else
		{
			Unigine::Log::warning("contact ID for body 0 is out of bounds: %d!\n",contactID);
			return;
		}
	}
	else
	{
		// no body, this is ok, might be terrain
	}

	if(ourBody->getContactBody1(contactID).get())
	{
		if(contactID<=ourBody->getContactBody1(contactID)->getNumContacts())
		{
			body1Surface=ourBody->getContactBody1(contactID)->getContactSurface(contactID);
		}
		else
		{
			Unigine::Log::warning("contact ID for body 1 is out of bounds: %d!\n", contactID);
			return;
		}
	}
	else
	{
		// might be terrain
	}
	Unigine::Log::message("our surface: %d, body0 surface: %d, body1 surface: %d\n", ourSurface, body0Surface, body1Surface);
}

What I find with the above is that contactID cannot be used for both bodies -- it is only relevant on ourBody (usually body0). How can I get the contact ID for the other body? How can I get the surface number of the other body?

Link to comment

I'm afraid we've decided to take a different approach to solving our collision problem -- the extra info needed during a contact event will be stored in / retrieved from the Node instead of the surface. Thus, we do not need to get the surface of both contacting bodies any longer. This is still a point of confusion and something I would like to understand, but it is no longer required for our purposes. You can consider it a low priority.

 

Since it is low priority, I unfortunately cannot devote time to setting up a test scene, but the fundamental problem should hopefully be fairly simple to reproduce. When Body A collides with Body B, and both bodies have multiple surfaces, how to determine the surfaces involved for each body?

 

Within contact callback attached to Body A, it seems possible to retrieve surface for Body A, but not for Body B. How can we retrieve contact surface for Body B (without also attaching contact callback to B ) ?

Link to comment
×
×
  • Create New...