public override void Step() { bool advanceRay = TestSettings.pause == false || TestSettings.singleStep; base.Step(); float L = 11.0f; Vec2 point1 = new Vec2(0.0f, 10.0f); Vec2 d = new Vec2(L * (float)Math.Cos(m_angle), L * (float)Math.Sin(m_angle)); Vec2 point2 = point1 + d; if (m_mode == Mode.e_closest) { _callback = new RayCastClosestCallback(); m_world.RayCast(_callback, point1, point2); } else if (m_mode == Mode.e_any) { _callback = new RayCastAnyCallback(); m_world.RayCast(_callback, point1, point2); } else if (m_mode == Mode.e_multiple) { _callback = new RayCastMultipleCallback(); m_world.RayCast(_callback, point1, point2); } if (advanceRay) { m_angle += (float)(0.25 * Math.PI / 180.0); } }
public void RayCast(RayCastCallback callback, Vec2 point1, Vec2 point2) { NativeMethods.b2world_raycast(_worldPtr, callback.Listener, point1, point2); }
public override void Draw() { base.Draw(); m_debugDraw.DrawString(5, m_textLine, "Press 1-5 to place stuff, m to change the mode"); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "Mode = "+m_mode.ToString()); m_textLine += 15; if (_callback == null) return; float L = 11.0f; Vec2 point1 = new Vec2(0.0f, 10.0f); Vec2 d = new Vec2(L * (float)Math.Cos(m_angle), L * (float)Math.Sin(m_angle)); Vec2 point2 = point1 + d; if (_callback is RayCastClosestCallback) { RayCastClosestCallback callback = (RayCastClosestCallback)_callback; m_world.RayCast(_callback, point1, point2); if (callback.m_hit) { m_debugDraw.DrawPoint(callback.m_point, 5.0f, new ColorF(0.4f, 0.9f, 0.4f)); m_debugDraw.DrawSegment(point1, callback.m_point, new ColorF(0.8f, 0.8f, 0.8f)); Vec2 head = callback.m_point + 0.5f * callback.m_normal; m_debugDraw.DrawSegment(callback.m_point, head, new ColorF(0.9f, 0.9f, 0.4f)); } else { m_debugDraw.DrawSegment(point1, point2, new ColorF(0.8f, 0.8f, 0.8f)); } } else if (_callback is RayCastAnyCallback) { RayCastAnyCallback callback = (RayCastAnyCallback)_callback; _callback = new RayCastAnyCallback(); if (callback.m_hit) { m_debugDraw.DrawPoint(callback.m_point, 5.0f, new ColorF(0.4f, 0.9f, 0.4f)); m_debugDraw.DrawSegment(point1, callback.m_point, new ColorF(0.8f, 0.8f, 0.8f)); Vec2 head = callback.m_point + 0.5f * callback.m_normal; m_debugDraw.DrawSegment(callback.m_point, head, new ColorF(0.9f, 0.9f, 0.4f)); } else { m_debugDraw.DrawSegment(point1, point2, new ColorF(0.8f, 0.8f, 0.8f)); } } else if (_callback is RayCastMultipleCallback) { RayCastMultipleCallback callback = (RayCastMultipleCallback)_callback; m_debugDraw.DrawSegment(point1, point2, new ColorF(0.8f, 0.8f, 0.8f)); for (int i = 0; i < callback.m_count; ++i) { Vec2 p = callback.m_points[i]; Vec2 n = callback.m_normals[i]; m_debugDraw.DrawPoint(p, 5.0f, new ColorF(0.4f, 0.9f, 0.4f)); m_debugDraw.DrawSegment(point1, p, new ColorF(0.8f, 0.8f, 0.8f)); Vec2 head = p + 0.5f * n; m_debugDraw.DrawSegment(p, head, new ColorF(0.9f, 0.9f, 0.4f)); } } }