Ejemplo n.º 1
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            m_debugDraw.DrawString(5, m_textLine, "Press 1-5 to drop stuff, m to change the mode");
            m_textLine += 15;
            m_debugDraw.DrawString(5, m_textLine, "Mode = {0}", m_mode);
            m_textLine += 15;

            float  L      = 11.0f;
            b2Vec2 point1 = new b2Vec2(0.0f, 10.0f);
            b2Vec2 d      = new b2Vec2(L * (float)Math.Cos(m_angle), L * (float)Math.Sin(m_angle));
            b2Vec2 point2 = point1 + d;

            if (m_mode == Mode.e_closest)
            {
                RayCastClosestCallback callback = new RayCastClosestCallback();
                m_world.RayCast(callback, point1, point2);

                if (callback.m_hit)
                {
                    m_debugDraw.DrawPoint(callback.m_point, 5.0f, new b2Color(0.4f, 0.9f, 0.4f));
                    m_debugDraw.DrawSegment(point1, callback.m_point, new b2Color(0.8f, 0.8f, 0.8f));
                    b2Vec2 head = callback.m_point + 0.5f * callback.m_normal;
                    m_debugDraw.DrawSegment(callback.m_point, head, new b2Color(0.9f, 0.9f, 0.4f));
                }
                else
                {
                    m_debugDraw.DrawSegment(point1, point2, new b2Color(0.8f, 0.8f, 0.8f));
                }
            }
            else if (m_mode == Mode.e_any)
            {
                RayCastAnyCallback callback = new RayCastAnyCallback();
                m_world.RayCast(callback, point1, point2);

                if (callback.m_hit)
                {
                    m_debugDraw.DrawPoint(callback.m_point, 5.0f, new b2Color(0.4f, 0.9f, 0.4f));
                    m_debugDraw.DrawSegment(point1, callback.m_point, new b2Color(0.8f, 0.8f, 0.8f));
                    b2Vec2 head = callback.m_point + 0.5f * callback.m_normal;
                    m_debugDraw.DrawSegment(callback.m_point, head, new b2Color(0.9f, 0.9f, 0.4f));
                }
                else
                {
                    m_debugDraw.DrawSegment(point1, point2, new b2Color(0.8f, 0.8f, 0.8f));
                }
            }
            else if (m_mode == Mode.e_multiple)
            {
                RayCastMultipleCallback callback = new RayCastMultipleCallback();
                m_world.RayCast(callback, point1, point2);
                m_debugDraw.DrawSegment(point1, point2, new b2Color(0.8f, 0.8f, 0.8f));

                for (int i = 0; i < callback.m_count; ++i)
                {
                    b2Vec2 p = callback.m_points[i];
                    b2Vec2 n = callback.m_normals[i];
                    m_debugDraw.DrawPoint(p, 5.0f, new b2Color(0.4f, 0.9f, 0.4f));
                    m_debugDraw.DrawSegment(point1, p, new b2Color(0.8f, 0.8f, 0.8f));
                    b2Vec2 head = p + 0.5f * n;
                    m_debugDraw.DrawSegment(p, head, new b2Color(0.9f, 0.9f, 0.4f));
                }
            }
        }
Ejemplo n.º 2
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            m_debugDraw.DrawString(5, m_textLine, "Press 1-5 to drop stuff, m to change the mode");
            m_textLine += 15;
            m_debugDraw.DrawString(5, m_textLine, "Mode = {0}", m_mode);
            m_textLine += 15;

            float L = 11.0f;
            b2Vec2 point1 = new b2Vec2(0.0f, 10.0f);
            b2Vec2 d = new b2Vec2(L * (float)Math.Cos(m_angle), L * (float)Math.Sin(m_angle));
            b2Vec2 point2 = point1 + d;

            if (m_mode == Mode.e_closest)
            {
                RayCastClosestCallback callback = new RayCastClosestCallback();
                m_world.RayCast(callback, point1, point2);

                if (callback.m_hit)
                {
                    m_debugDraw.DrawPoint(callback.m_point, 5.0f, new b2Color(0.4f, 0.9f, 0.4f));
                    m_debugDraw.DrawSegment(point1, callback.m_point, new b2Color(0.8f, 0.8f, 0.8f));
                    b2Vec2 head = callback.m_point + 0.5f * callback.m_normal;
                    m_debugDraw.DrawSegment(callback.m_point, head, new b2Color(0.9f, 0.9f, 0.4f));
                }
                else
                {
                    m_debugDraw.DrawSegment(point1, point2, new b2Color(0.8f, 0.8f, 0.8f));
                }
            }
            else if (m_mode == Mode.e_any)
            {
                RayCastAnyCallback callback = new RayCastAnyCallback();
                m_world.RayCast(callback, point1, point2);

                if (callback.m_hit)
                {
                    m_debugDraw.DrawPoint(callback.m_point, 5.0f, new b2Color(0.4f, 0.9f, 0.4f));
                    m_debugDraw.DrawSegment(point1, callback.m_point, new b2Color(0.8f, 0.8f, 0.8f));
                    b2Vec2 head = callback.m_point + 0.5f * callback.m_normal;
                    m_debugDraw.DrawSegment(callback.m_point, head, new b2Color(0.9f, 0.9f, 0.4f));
                }
                else
                {
                    m_debugDraw.DrawSegment(point1, point2, new b2Color(0.8f, 0.8f, 0.8f));
                }
            }
            else if (m_mode == Mode.e_multiple)
            {
                RayCastMultipleCallback callback = new RayCastMultipleCallback();
                m_world.RayCast(callback, point1, point2);
                m_debugDraw.DrawSegment(point1, point2, new b2Color(0.8f, 0.8f, 0.8f));

                for (int i = 0; i < callback.m_count; ++i)
                {
                    b2Vec2 p = callback.m_points[i];
                    b2Vec2 n = callback.m_normals[i];
                    m_debugDraw.DrawPoint(p, 5.0f, new b2Color(0.4f, 0.9f, 0.4f));
                    m_debugDraw.DrawSegment(point1, p, new b2Color(0.8f, 0.8f, 0.8f));
                    b2Vec2 head = p + 0.5f * n;
                    m_debugDraw.DrawSegment(p, head, new b2Color(0.9f, 0.9f, 0.4f));
                }
            }
        }