Hi! i am using this code from the box2d testbed:
float32 L = 32000.0f;
b2Vec2 point1(1000.0f,1000.0f);
b2Vec2 d(L * cosf(m_angle), L * sinf(m_angle));
b2Vec2 point2 = point1 + d;
RayCastCallback callback;
myWorld->RayCast(&callback, point1, point2);
if (callback.m_fixture)
{
m_debugDraw->DrawPoint(callback.m_point, 5.0f, b2Color(0.4f, 0.9f, 0.4f));
drawLine(ccp(point1.x/PTM_RATIO,point1.y/PTM_RATIO),ccp(callback.m_point.x/PTM_RATIO,callback.m_point.y/PTM_RATIO));
m_debugDraw->DrawSegment(point1, callback.m_point, b2Color(0.8f, 0.8f, 0.8f));
b2Vec2 head = callback.m_point + 0.5f * callback.m_normal;
drawLine(ccp(callback.m_point.x/PTM_RATIO,callback.m_point.y/PTM_RATIO),ccp(head.x/PTM_RATIO,head.y/PTM_RATIO));
m_debugDraw->DrawSegment(callback.m_point, head, b2Color(0.9f, 0.9f, 0.4f));
}
else
{
drawLine(ccp(point1.x/PTM_RATIO,point1.y/PTM_RATIO),ccp(point2.x/PTM_RATIO,point2.y/PTM_RATIO));
m_debugDraw->DrawSegment(point1, point2, b2Color(1.0f, 1.0f, 1.0f));
}
m_angle += 1.25f * b2_pi / 180.0f;
This code works perfectly in the visual c++ version.
Now using this in my game has some problems which i don't understand.
First of all you may notice i added some drawLine(ccp(point1.x/PTM_RATIO,point1.y/PTM_RATIO),ccp(point2.x/PTM_RATIO,point2.y/PTM_RATIO));
beacuse the debugdraw is not working for this. I have it enabled and it works for the bodies,etc. So i am using opengl drawline to debug it for the time being.
Second and the most important it is not working right. Apparently the raycast never touches anything... It is never getting inside the
if (callback.m_fixture){} line...
If i add a breakpoint when the raycast is indeed touching something the callback.m_fixture is always null.
The weirdest part is there is ONE momment it does return nonvoid it is when it points to coordinates (0,0) and there i don't have anything at all...
Any ideas? Thanks