Hi! i am using this code from the box2d testbed in my iPhone game:
[code]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));
m_debugDraw->DrawSegment(point1, callback.m_point, b2Color(0.8f, 0.8f, 0.8f));
b2Vec2 head = callback.m_point + 0.5f * callback.m_normal;
m_debugDraw->DrawSegment(callback.m_point, head, b2Color(0.9f, 0.9f, 0.4f));
}
else
{
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.
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 non-void it is when it points to coordinates (0,0) and there, i don't have anything at all... This is also random, it doesn't always happen...
Any ideas? Thanks
[code]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));
m_debugDraw->DrawSegment(point1, callback.m_point, b2Color(0.8f, 0.8f, 0.8f));
b2Vec2 head = callback.m_point + 0.5f * callback.m_normal;
m_debugDraw->DrawSegment(callback.m_point, head, b2Color(0.9f, 0.9f, 0.4f));
}
else
{
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.
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 non-void it is when it points to coordinates (0,0) and there, i don't have anything at all... This is also random, it doesn't always happen...
Any ideas? Thanks