Hey sorry this is a basic question, but I'm trying to get the body intersected with from a raycast, I used the sample on the testbed but I can't work out how to get it.
Here's what I'm doing:
the call back function here with m_body added:
Code:
class RayCastAnyCallback : public b2RayCastCallback
{
public:
RayCastAnyCallback()
{
m_hit = false;
}
float32 ReportFixture( b2Fixture* fixture, const b2Vec2& point,
const b2Vec2& normal, float32 fraction)
{
b2Body* body = fixture->GetBody();
void* userData = body->GetUserData();
if (userData)
{
int32 index = *(int32*)userData;
if (index == 0)
{
// filter
return -1.0f;
}
}
m_hit = true;
m_point = point;
m_normal = normal;
m_body = body;
return 0.0f;
}
bool m_hit;
b2Vec2 m_point;
b2Vec2 m_normal;
b2Body* m_body //this is what I've added
};
and here is how I've implemented:
Code:
RayCastAnyCallback callback;
world->RayCast(&callback, point1, point2);
if (callback.m_hit)
{
NSLog(@"hit %@ ",callback.m_body);
}
I'm doing this for an iphone app but I'm not savvy with c++ maybe that's the problem.
Thanks, Dave.