Esempio n. 1
0
        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));
                }
            }
        }
Esempio n. 2
0
        public override void Step(TestSettings settings)
        {
            bool advanceRay = settings.pause == false || settings.singleStep;

            base.Step(settings);
            m_debugDraw.DrawString("Press 1-5 to drop stuff, m to change the mode");

            switch (m_mode)
            {
            case Mode.e_closest:
                m_debugDraw.DrawString("Ray-cast mode: closest - find closest fixture along the ray");
                break;

            case Mode.e_any:
                m_debugDraw.DrawString("Ray-cast mode: any - check for obstruction");
                break;

            case Mode.e_multiple:
                m_debugDraw.DrawString("Ray-cast mode: multiple - gather multiple fixtures");
                break;
            }

            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)
            {
                RayCastClosestCallback callback = new RayCastClosestCallback();
                m_world.RayCast(callback, point1, point2);

                if (callback.m_hit)
                {
                    m_debugDraw.DrawPoint(callback.m_point, 5.0f, Color.FromArgb(100, 225, 100));
                    m_debugDraw.DrawSegment(point1, callback.m_point, Color.FromArgb(200, 200, 200));
                    Vec2 head = callback.m_point + 0.5f * callback.m_normal;
                    m_debugDraw.DrawSegment(callback.m_point, head, Color.FromArgb(225, 225, 100));
                }
                else
                {
                    m_debugDraw.DrawSegment(point1, point2, Color.FromArgb(200, 200, 200));
                }
            }
            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, Color.FromArgb(100, 225, 100));
                    m_debugDraw.DrawSegment(point1, callback.m_point, Color.FromArgb(200, 200, 200));
                    Vec2 head = callback.m_point + 0.5f * callback.m_normal;
                    m_debugDraw.DrawSegment(callback.m_point, head, Color.FromArgb(225, 225, 100));
                }
                else
                {
                    m_debugDraw.DrawSegment(point1, point2, Color.FromArgb(200, 200, 200));
                }
            }
            else if (m_mode == Mode.e_multiple)
            {
                RayCastMultipleCallback callback = new RayCastMultipleCallback();
                m_world.RayCast(callback, point1, point2);
                m_debugDraw.DrawSegment(point1, point2, Color.FromArgb(200, 200, 200));

                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, Color.FromArgb(100, 225, 100));
                    m_debugDraw.DrawSegment(point1, p, Color.FromArgb(200, 200, 200));
                    Vec2 head = p + 0.5f * n;
                    m_debugDraw.DrawSegment(p, head, Color.FromArgb(225, 225, 100));
                }
            }

            if (advanceRay)
            {
                m_angle += 0.25f * (float)Math.PI / 180.0f;
            }

        #if ZERO
            // This case was failing.
            {
                Vec2[] vertices = new Vec2[4];
                //vertices[0].Set(-22.875f, -3.0f);
                //vertices[1].Set(22.875f, -3.0f);
                //vertices[2].Set(22.875f, 3.0f);
                //vertices[3].Set(-22.875f, 3.0f);

                PolygonShape shape = new PolygonShape();
                //shape.Set(vertices, 4);
                shape.SetAsBox(22.875f, 3.0f);

                RayCastInput input;
                input.p1.Set(10.2725f, 1.71372f);
                input.p2.Set(10.2353f, 2.21807f);
                //input.maxFraction = 0.567623f;
                input.maxFraction = 0.56762173f;

                Transform xf;
                xf.SetIdentity();
                xf.position.Set(23.0f, 5.0f);

                RayCastOutput output;
                bool          hit;
                hit = shape.RayCast(out output, input, xf);
                hit = false;

                Color color(1.0f, 1.0f, 1.0f);

                Vec2[] vs = new Vec2[4];
                for (int i = 0; i < 4; ++i)
                {
                    vs[i] = Utilities.Mul(xf, shape.m_vertices[i]);
                }

                m_debugDraw.DrawPolygon(vs, 4, color);
                m_debugDraw.DrawSegment(input.p1, input.p2, color);
            }
        #endif
        }
Esempio n. 3
0
		public override void Step(TestSettings settings)
		{
			bool advanceRay = settings.pause == false || settings.singleStep;

			base.Step(settings);
			m_debugDraw.DrawString("Press 1-5 to drop stuff, m to change the mode");
			
			switch (m_mode)
			{
				case Mode.e_closest:
					m_debugDraw.DrawString("Ray-cast mode: closest - find closest fixture along the ray");
					break;

				case Mode.e_any:
					m_debugDraw.DrawString("Ray-cast mode: any - check for obstruction");
					break;

				case Mode.e_multiple:
					m_debugDraw.DrawString("Ray-cast mode: multiple - gather multiple fixtures");
					break;
			}

			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)
			{
				RayCastClosestCallback callback = new RayCastClosestCallback();
				m_world.RayCast(callback, point1, point2);

				if (callback.m_hit)
				{
					m_debugDraw.DrawPoint(callback.m_point, 5.0f, Color.FromArgb(100, 225, 100));
					m_debugDraw.DrawSegment(point1, callback.m_point, Color.FromArgb(200, 200, 200));
					Vec2 head = callback.m_point + 0.5f * callback.m_normal;
					m_debugDraw.DrawSegment(callback.m_point, head, Color.FromArgb(225, 225, 100));
				}
				else
				{
					m_debugDraw.DrawSegment(point1, point2, Color.FromArgb(200, 200, 200));
				}
			}
			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, Color.FromArgb(100, 225, 100));
					m_debugDraw.DrawSegment(point1, callback.m_point, Color.FromArgb(200, 200, 200));
					Vec2 head = callback.m_point + 0.5f * callback.m_normal;
					m_debugDraw.DrawSegment(callback.m_point, head, Color.FromArgb(225, 225, 100));
				}
				else
				{
					m_debugDraw.DrawSegment(point1, point2, Color.FromArgb(200, 200, 200));
				}
			}
			else if (m_mode == Mode.e_multiple)
			{
				RayCastMultipleCallback callback = new RayCastMultipleCallback();
				m_world.RayCast(callback, point1, point2);
				m_debugDraw.DrawSegment(point1, point2, Color.FromArgb(200, 200, 200));

				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, Color.FromArgb(100, 225, 100));
					m_debugDraw.DrawSegment(point1, p, Color.FromArgb(200, 200, 200));
					Vec2 head = p + 0.5f * n;
					m_debugDraw.DrawSegment(p, head, Color.FromArgb(225, 225, 100));
				}
			}

			if (advanceRay)
			{
				m_angle += 0.25f * (float)Math.PI / 180.0f;
			}

	#if ZERO
			// This case was failing.
			{
				Vec2[] vertices = new Vec2[4];
				//vertices[0].Set(-22.875f, -3.0f);
				//vertices[1].Set(22.875f, -3.0f);
				//vertices[2].Set(22.875f, 3.0f);
				//vertices[3].Set(-22.875f, 3.0f);

				PolygonShape shape = new PolygonShape();
				//shape.Set(vertices, 4);
				shape.SetAsBox(22.875f, 3.0f);

				RayCastInput input;
				input.p1.Set(10.2725f,1.71372f);
				input.p2.Set(10.2353f,2.21807f);
				//input.maxFraction = 0.567623f;
				input.maxFraction = 0.56762173f;

				Transform xf;
				xf.SetIdentity();
				xf.position.Set(23.0f, 5.0f);

				RayCastOutput output;
				bool hit;
				hit = shape.RayCast(out output, input, xf);
				hit = false;

				Color color(1.0f, 1.0f, 1.0f);
				Vec2[] vs = new Vec2[4];
				for (int i = 0; i < 4; ++i)
				{
					vs[i] = Utilities.Mul(xf, shape.m_vertices[i]);
				}

				m_debugDraw.DrawPolygon(vs, 4, color);
				m_debugDraw.DrawSegment(input.p1, input.p2, color);
			}
	#endif
		}