I've box2d working fine, and I've got plotting lines working fine, now I need my circles (or any box2d shape) to know if a line has crossed them, any ideas on how best to do this? Are there any built in methods for this kind of collision detection? or am I going to have roll my own?
I haven't tried it yet, but hopefully I can figure it out from this
http://www.iforce2d.net/b2dtut/raycasting
Ok looking into the code, I want to convert this code
b2RayCastInput input;
input.p1 = p1;
input.p2 = p2;
input.maxFraction = 1;
//check every fixture of every body to find closest
float closestFraction = 1; //start with end of line as p2
b2Vec2 intersectionNormal(0,0);
for (b2Body* b = m_world->GetBodyList(); b; b = b->GetNext()) {
for (b2Fixture* f = b->GetFixtureList(); f; f = f->GetNext()) {
b2RayCastOutput output;
if ( ! f->RayCast( &output, input ) )
continue;
if ( output.fraction < closestFraction ) {
closestFraction = output.fraction;
intersectionNormal = output.normal;
}
}
}
b2Vec2 intersectionPoint = p1 + closestFraction * (p2 - p1);
There doesn't seem to be a GetBodyList or GetFeatureList for world? How can I iterate through the objects in the world and the features?