Exemple #1
0
        internal static Contact Create(Fixture fixtureA, int indexA, Fixture fixtureB, int indexB)
        {
            if (s_initialized == false)
            {
                InitializeRegisters();
                s_initialized = true;
            }

            ShapeType type1 = fixtureA.GetShapeType();
            ShapeType type2 = fixtureB.GetShapeType();

            Utilities.Assert(0 <= type1 && type1 < ShapeType.Count);
            Utilities.Assert(0 <= type2 && type2 < ShapeType.Count);

            ContactCreateFcn createFcn = s_registers[(int)type1, (int)type2].createFcn;

            if (createFcn != null)
            {
                if (s_registers[(int)type1, (int)type2].primary)
                {
                    return(createFcn(fixtureA, indexA, fixtureB, indexB));
                }
                else
                {
                    return(createFcn(fixtureB, indexB, fixtureA, indexA));
                }
            }
            else
            {
                return(null);
            }
        }
Exemple #2
0
		public void DrawFixture(Fixture fixture)
		{
			Color color = Color.FromArgb(245, 245, 150);
			Transform xf = fixture.GetBody().GetTransform();

			switch (fixture.GetShapeType())
			{
			case ShapeType.Circle:
				{
					CircleShape circle = (CircleShape)fixture.GetShape();

					Vec2 center = Utilities.Mul(xf, circle.m_p);
					float radius = circle.m_radius;

					m_debugDraw.DrawCircle(center, radius, color);
				}
				break;

			case ShapeType.Polygon:
				{
					PolygonShape poly = (PolygonShape)fixture.GetShape();
					int vertexCount = poly.m_count;
					Utilities.Assert(vertexCount <= Settings._maxPolygonVertices);
					Vec2[] vertices = new Vec2[Settings._maxPolygonVertices];

					for (int i = 0; i < vertexCount; ++i)
					{
						vertices[i] = Utilities.Mul(xf, poly.m_vertices[i]);
					}

					m_debugDraw.DrawPolygon(vertices, vertexCount, color);
				}
				break;
				
			default:
				break;
			}
		}
Exemple #3
0
		internal static Contact Create(Fixture fixtureA, int indexA, Fixture fixtureB, int indexB){
			if (s_initialized == false)
			{
			    InitializeRegisters();
			    s_initialized = true;
			}

			ShapeType type1 = fixtureA.GetShapeType();
			ShapeType type2 = fixtureB.GetShapeType();

			Utilities.Assert(0 <= type1 && type1 < ShapeType.Count);
			Utilities.Assert(0 <= type2 && type2 < ShapeType.Count);
	
			ContactCreateFcn createFcn = s_registers[(int)type1, (int)type2].createFcn;
			if (createFcn != null)
			{
			    if (s_registers[(int)type1, (int)type2].primary)
			    {
			        return createFcn(fixtureA, indexA, fixtureB, indexB);
			    }
			    else
			    {
			        return createFcn(fixtureB, indexB, fixtureA, indexA);
			    }
			}
			else
			{
			    return null;
			}
		}
Exemple #4
0
		private void DrawShape(Fixture fixture, Transform xf, Color color){
			switch (fixture.GetShapeType())
			{
			case ShapeType.Circle:
			    {
			        CircleShape circle = (CircleShape)fixture.GetShape();

			        Vec2 center = Utilities.Mul(xf, circle.m_p);
			        float radius = circle.m_radius;
			        Vec2 axis = Utilities.Mul(xf.q, new Vec2(1.0f, 0.0f));

			        m_debugDraw.DrawSolidCircle(center, radius, axis, color);
			    }
			    break;

			case ShapeType.Edge:
			    {
			        EdgeShape edge = (EdgeShape)fixture.GetShape();
			        Vec2 v1 = Utilities.Mul(xf, edge.m_vertex1);
			        Vec2 v2 = Utilities.Mul(xf, edge.m_vertex2);
			        m_debugDraw.DrawSegment(v1, v2, color);
			    }
			    break;

			case ShapeType.Chain:
			    {
			        ChainShape chain = (ChainShape)fixture.GetShape();
			        int count = chain.m_count;
			        List<Vec2> vertices = chain.m_vertices;

			        Vec2 v1 = Utilities.Mul(xf, vertices[0]);
			        for (int i = 1; i < count; ++i)
			        {
			            Vec2 v2 = Utilities.Mul(xf, vertices[i]);
			            m_debugDraw.DrawSegment(v1, v2, color);
			            m_debugDraw.DrawCircle(v1, 0.05f, color);
			            v1 = v2;
			        }
			    }
			    break;

			case ShapeType.Polygon:
			    {
			        PolygonShape poly = (PolygonShape)fixture.GetShape();
			        int vertexCount = poly.m_count;
			        Utilities.Assert(vertexCount <= Settings._maxPolygonVertices);
			        Vec2[] vertices = new Vec2[Settings._maxPolygonVertices];

			        for (int i = 0; i < vertexCount; ++i)
			        {
			            vertices[i] = Utilities.Mul(xf, poly.m_vertices[i]);
			        }

			        m_debugDraw.DrawSolidPolygon(vertices, vertexCount, color);
			    }
			    break;
            
			default:
			    break;
			}
		}
Exemple #5
0
        private void DrawShape(Fixture fixture, Transform xf, Color color)
        {
            switch (fixture.GetShapeType())
            {
            case ShapeType.Circle:
            {
                CircleShape circle = (CircleShape)fixture.GetShape();

                Vec2  center = Utilities.Mul(xf, circle.m_p);
                float radius = circle.m_radius;
                Vec2  axis   = Utilities.Mul(xf.q, new Vec2(1.0f, 0.0f));

                m_debugDraw.DrawSolidCircle(center, radius, axis, color);
            }
            break;

            case ShapeType.Edge:
            {
                EdgeShape edge = (EdgeShape)fixture.GetShape();
                Vec2      v1   = Utilities.Mul(xf, edge.m_vertex1);
                Vec2      v2   = Utilities.Mul(xf, edge.m_vertex2);
                m_debugDraw.DrawSegment(v1, v2, color);
            }
            break;

            case ShapeType.Chain:
            {
                ChainShape  chain    = (ChainShape)fixture.GetShape();
                int         count    = chain.m_count;
                List <Vec2> vertices = chain.m_vertices;

                Vec2 v1 = Utilities.Mul(xf, vertices[0]);
                for (int i = 1; i < count; ++i)
                {
                    Vec2 v2 = Utilities.Mul(xf, vertices[i]);
                    m_debugDraw.DrawSegment(v1, v2, color);
                    m_debugDraw.DrawCircle(v1, 0.05f, color);
                    v1 = v2;
                }
            }
            break;

            case ShapeType.Polygon:
            {
                PolygonShape poly        = (PolygonShape)fixture.GetShape();
                int          vertexCount = poly.m_count;
                Utilities.Assert(vertexCount <= Settings._maxPolygonVertices);
                Vec2[] vertices = new Vec2[Settings._maxPolygonVertices];

                for (int i = 0; i < vertexCount; ++i)
                {
                    vertices[i] = Utilities.Mul(xf, poly.m_vertices[i]);
                }

                m_debugDraw.DrawSolidPolygon(vertices, vertexCount, color);
            }
            break;

            default:
                break;
            }
        }