Exemple #1
0
    /// Initialize the proxy using the given shape. The shape
    /// must remain in scope while the proxy is in use.
    public void Set(b2Shape shape, int index)
    {
        switch (shape.GetType())
        {
        case b2Shape.Type.e_circle:
        {
            b2CircleShape circle = (b2CircleShape)shape;
            m_vertices = new [] { circle.m_p };
            m_count    = 1;
            m_radius   = circle.m_radius;
        }
        break;

        case b2Shape.Type.e_polygon:
        {
            b2PolygonShape polygon = (b2PolygonShape)shape;
            m_vertices = (b2Vec2[])polygon.m_vertices.Clone();
            m_count    = polygon.m_count;
            m_radius   = polygon.m_radius;
        }
        break;

        case b2Shape.Type.e_chain:
        {
            b2ChainShape chain = (b2ChainShape)shape;
            Debug.Assert(0 <= index && index < chain.m_count);

            m_buffer[0] = chain.m_vertices[index];
            if (index + 1 < chain.m_count)
            {
                m_buffer[1] = chain.m_vertices[index + 1];
            }
            else
            {
                m_buffer[1] = chain.m_vertices[0];
            }

            m_vertices = m_buffer;
            m_count    = 2;
            m_radius   = chain.m_radius;
        }
        break;

        case b2Shape.Type.e_edge:
        {
            b2EdgeShape edge = (b2EdgeShape)shape;
            m_vertices = new [] { edge.m_vertex1, edge.m_vertex2 };
            m_count    = 2;
            m_radius   = edge.m_radius;
        }
        break;

        default:
            Debug.Assert(false);
            break;
        }
    }
Exemple #2
0
 /**
  * Initialize the proxy using the given shape. The shape
  * must remain in scope while the proxy is in use.
  */
 public void Set(b2Shape shape)
 {
     /*switch(shape.GetType())
      * {
      *      case b2Shape.e_circleShape:
      *      {
      *              b2CircleShape circle = shape as b2CircleShape;
      *              m_vertices = new List<b2Vec2>();
      *              m_vertices[0] = circle.m_p;
      *              m_count = 1;
      *              m_radius = circle.m_radius;
      *      }
      *      break;
      *      case b2Shape.e_polygonShape:
      *      {
      *              b2PolygonShape polygon =  shape as b2PolygonShape;
      *              m_vertices = polygon.m_vertices;
      *              m_count = polygon.m_vertexCount;
      *              m_radius = polygon.m_radius;
      *      }
      *      break;
      *      default:
      *      b2Settings.b2Assert(false);
      * }*/
     if (shape.GetType() == b2Shape.e_circleShape)
     {
         b2CircleShape circle = shape as b2CircleShape;
         m_vertices = new List <b2Vec2>();
         m_vertices.Add(circle.m_p);
         m_count  = 1;
         m_radius = circle.m_radius;
     }
     else if (shape.GetType() == b2Shape.e_polygonShape)
     {
         b2PolygonShape polygon = shape as b2PolygonShape;
         m_vertices = polygon.m_vertices;
         m_count    = polygon.m_vertexCount;
         m_radius   = polygon.m_radius;
     }
     else
     {
         b2Settings.b2Assert(false);
     }
 }