Bullet engine details collision Event Callback Function

Source: Internet
Author: User

A very common application in bullet is to call the callback function provided by the developer when two objects collide.

For example, if a sphere hits another sphere to make a sound

The following is an example of three types of objects in a scenario: ball (dynamic), floor (static), and wall (static)

The sound of the ball hitting the wall is different from that of the floor.

Therefore, you need to set these three objects to different categories and use the userpointer of collisionobj to complete

Int objclass [3] = {0, 1, 2 };
Boxbody-> setuserpointer (& objclass [0]);

Ground-> setuserpointer (& objclass [1]);

Wall-> setuserpointer (& objclass [2]);

Then, call the following callback function in update or render:

The main idea is to get the current narrowphase collision pair from btpersistentmanifold.

However, check the contact point. If the contact point is greater than 0, check the collision object category.

Perform different actions based on the category.

Example video http://www.youtube.com/watch? V = xxecljjr05w

Sound not recorded, wait for the last two days to update

View plaincopy to clipboardprint?
-(Void) collide_callback {
Int type_obj1, type_obj2;
Int nummanifolds = sdynamicsworld-> getdispatcher ()-> getnummanifolds ();
For (INT I = 0; I <nummanifolds; I ++)
{
Btpersistentmanifold * contactmanifold = sdynamicsworld-> getdispatcher ()-> getmanifoldbyindexinternal (I );
Int numcontacts = contactmanifold-> getnumcontacts ();
If (numcontacts> 0)
{
Btcollisionobject * Oba = static_cast <btcollisionobject *> (contactmanifold-> getbody0 ());
Btcollisionobject * OBB = static_cast <btcollisionobject *> (contactmanifold-> getbody1 ());
Type_obj1 = * (int *) Oba-> getuserpointer ();
Type_obj2 = * (int *) OBB-> getuserpointer ();
If (type_obj1 = 0) & (type_obj2 = 1 ))
{
[G_resmanager playsound: @ "test. caf"];
}
If (type_obj1 = 0) & (type_obj2 = 2 ))
{
[G_resmanager playsound: @ "test2.caf"];
}
}
}

}

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/superwiles/archive/2010/03/28/5425842.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.