Does anyone have a little more in depth explanation on how to implement the contact listener in C++. I mean I have seen some tutorials in flash and read the documentation for box2d but nothing really goes to in depth on how to implement it with c++. I have tried a few things in my project and maybe someone can explain it to me a little more. Here is the basics of what I have no logic put into the functions just yet which is what I hope you guys can help me with:
As you can tell I am still using the older box2d but, what needs to go inside those functions? I know in flash after you put all the logic inside those functions you just implement it like so:
That's C++ but its the basic premise of what they did in the flash tut.
Now pretty much all they did with the code inside the Add and Remove was set the alpha of the box to 50% if it was colliding. So how would I be able to tell if a specific object is colliding rather than every object in the world? Is there a better way to check collision for one object or am I going to have to use the contact listener in order to achieve this? If so then how exactly would I achieve this because it seems like the world just checks to see if an object is colliding with another object and if it is run the Add function code in the contact listener. How do I ask a specify object if it is colliding with another specific object?
IE if the character is colliding with the item then add the item to the inventory.
If anyone is curious I am using Dark GDK to code in.
Code:
void MyContactListener::Add(b2ContactPoint *point)
{
if(point->shape1->GetBody()->GetUserData() && point->shape2->GetBody()->GetUserData())
{
}
}
/// Called when a contact point persists. This includes the geometry
/// and the forces.
void MyContactListener::Persist( b2ContactPoint* point)
{
}
/// Called when a contact point is removed. This includes the last
/// computed geometry and forces.
void MyContactListener::Remove( b2ContactPoint* point)
{
}
/// Called after a contact point is solved.
void MyContactListener::Result( b2ContactResult* point)
{
if(point->shape1->GetBody()->GetUserData() && point->shape2->GetBody()->GetUserData())
{
}
}
{
if(point->shape1->GetBody()->GetUserData() && point->shape2->GetBody()->GetUserData())
{
}
}
/// Called when a contact point persists. This includes the geometry
/// and the forces.
void MyContactListener::Persist( b2ContactPoint* point)
{
}
/// Called when a contact point is removed. This includes the last
/// computed geometry and forces.
void MyContactListener::Remove( b2ContactPoint* point)
{
}
/// Called after a contact point is solved.
void MyContactListener::Result( b2ContactResult* point)
{
if(point->shape1->GetBody()->GetUserData() && point->shape2->GetBody()->GetUserData())
{
}
}
As you can tell I am still using the older box2d but, what needs to go inside those functions? I know in flash after you put all the logic inside those functions you just implement it like so:
Code:
ContanctListener* m_contactListener=new ContanctListener();
m_world.SetContactListener(m_contactListener);
m_world.SetContactListener(m_contactListener);
That's C++ but its the basic premise of what they did in the flash tut.
Now pretty much all they did with the code inside the Add and Remove was set the alpha of the box to 50% if it was colliding. So how would I be able to tell if a specific object is colliding rather than every object in the world? Is there a better way to check collision for one object or am I going to have to use the contact listener in order to achieve this? If so then how exactly would I achieve this because it seems like the world just checks to see if an object is colliding with another object and if it is run the Add function code in the contact listener. How do I ask a specify object if it is colliding with another specific object?
IE if the character is colliding with the item then add the item to the inventory.
If anyone is curious I am using Dark GDK to code in.