Jump to content

[SOLVED] body class collision function


photo

Recommended Posts

image.thumb.png.94eca6eb2a11016606deb07b6f9f5388.png

1. Is the return value of getNumContacts () different from the size of the unregistered_collisions vector?

If the unregistered_collisions vector is a stacked body set each time it crashes, what exactly does getNumContacts () mean? Sorry. I do not understand the document well.

 

2. If another node does not have a body and shape, but have a surface collision, it will not overlap, but  the callback function not be called. is that right or No?

 

 

I am sorry about the English writing. I used Google Translator.

 

Link to comment

Hi dongju.jeong,

As the notice to the getNumContacts() function says: "a contact can be handled by any of the bodies that participate in it. To which body it will be assigned is completely random. If the contact is assigned to and handled by another body, the number of contacts for the current body is not incremented".

So, getNumContacts() will give you the number of contacts handled by this particular body, other contacts, in which this body participates too, but which are handled by another body will be unregistered, to capture such contacts we use the setContactCallback() method and add them to the  unregistered_collisions vector. Thus, we process all contacts, in which a body participated in this frame: registered by this body (using getNumContacts() and getContactObject()) and registered by other bodies (using the the unregistered_collisions vector).

As for the second question: if a body hits an object without a body or shape assigned, but having surface collision enabled the callback will be called (provided that collision mask of a shape assigned to the body matches the collision mask of the surface).

It's ok, don't worry, we understand you!

Thank you!

 

Link to comment

If the surface is collided and the callback function is called, What is assigned to the callback function's parameter(body,num)? 

Is the parameter assigned null because the collided object has no body and shape?

Link to comment

The callback will be called for the body, colliding with a surface of such object (having no physical body and shape), so the body parameter won't be null.

In such a case you'll be able to get, for example, the name of the object , whose surface was hit:

void on_contact(BodyPtr body, int num)
{
	Log::message("\n CALLBACK CALLED! Hit object name: %s \n", body->getContactObject(num)->getName());
}

Thank you!

  • Like 1
Link to comment

thank you,  I tryed to debug callback using Breakpoint.

 

However, physics and rendering seem to progress internally during break. Is there a way to stop the process completely while it is hanging on the breakpoint?
 

Link to comment

The point is, that physics callbacks are not executed immediately, they're placed in a queue to be processed later, before the next flush() or next update() of the world script. Moreover, they are executed in parallel with the main and physics threads. So, you can't monitor all collisions visually while debugging with breakpoints inside a contact callback.

Thank you!

Link to comment

Hi,

 

However, Even if I hold a breakpoint inside the update () and pause for a while, when I continue again, the ball that has falling is already  reaches the ground and is rolling.

I have debugged in the update () section of the attached photo code(on Top This post) 

Link to comment

Physics callbacks are executed in parallel with the main and physics threads. Moreover physics has its own FPS which does not depend on rendering frame rate (thus, physics calculations are not processed each rendering frame). So, guess you cannot monitor all collisions visually while debugging with breakpoints.

Thank you!

Link to comment
  • silent changed the title to [SOLVED] body class collision function
×
×
  • Create New...