View previous topic :: View next topic |
Author |
Message |
mike
Joined: 28 Dec 2008 Posts: 34
|
Posted: Sun Mar 22, 2009 8:33 pm Post subject: Collision help |
|
|
I can't quite figure out how to tell what object hit what.
For blaze 1.0 all I used was poly2poly to tell if the object hit another object.
What would I have to use for blaze 2.0? Do I have to do something with the contact class? |
|
Back to top |
|
|
zzzzrrr
Joined: 17 Feb 2007 Posts: 139 Location: Washington, DC
|
Posted: Mon Mar 23, 2009 12:55 pm Post subject: Re: Collision help |
|
|
mike wrote: | I can't quite figure out how to tell what object hit what. |
Take a look at the ContactListener in the testbed; it's a very good example of how to use collision callbacks.
In fact, if you select 'draw contacts' in the demo and then then run the pyramid test, you should see some interesting results. |
|
Back to top |
|
|
mike
Joined: 28 Dec 2008 Posts: 34
|
Posted: Tue Mar 24, 2009 8:13 pm Post subject: |
|
|
Im still confused on what I have to actually look for.
I checked out the contactlistener.d and i looked at test.d. I cant figure out how you added the contactpoint.
Like I don't understand add(bzContactPoint point).
Im just really confused on this. |
|
Back to top |
|
|
zzzzrrr
Joined: 17 Feb 2007 Posts: 139 Location: Washington, DC
|
Posted: Tue Mar 24, 2009 8:44 pm Post subject: Contact Listener |
|
|
When a collision event occurs in Blaze, it registers a callback if you've created a contact listener in your application. For example, you should create a class like this in your program:
Code: |
class MyContactListener : bzContactListener
{
void add(bzContactPoint point)
{
// handle add point
}
void persist(bzContactPoint point)
{
// handle persist point
}
void remove(bzContactPoint point)
{
// handle remove point
}
void Result(bzContactResult point)
{
// handle results
}
};
|
See the abstract class bzContactListener in bzWorldCallbacks.d for more details.... Also look in bzContact.d for bzContactPoint.
You can create a new instance your contact listener by doing this:
Code: |
// Create your listener
auto listener = new MyContactListener;
// Register your contact listener with world
world.contactListener = listener;
|
Whenever a collision occurs, it will "call back" to 'listener', and you can handle the results accordingly.
Hope this helps.... You can also check out the Box2D wiki for good info. |
|
Back to top |
|
|
mike
Joined: 28 Dec 2008 Posts: 34
|
Posted: Wed Mar 25, 2009 2:45 pm Post subject: |
|
|
Wow that is really simple. I kept thinking it was more complex than just that.
Thanks for the help again. |
|
Back to top |
|
|
|