Esempio n. 1
0
 def __init__(self, body, vertices, offset, auto_order_vertices=False):
     """Create a polygon
     
         body : `Body`
             The body to attach the poly to
         vertices : [(x,y)] or [`Vec2d`]
             Define a convex hull of the polygon with a counterclockwise
             winding.
         offset : (x,y) or `Vec2d`
             The offset from the body's center of gravity in body local 
             coordinates. 
         auto_order_vertices : bool 
             Set to True to automatically order the vertices. Currently 
             not supported.
     """
     if auto_order_vertices: 
         raise Exception(NotImplemented)
     self._body = body
     self.offset = offset
     #self.verts = (Vec2d * len(vertices))(*vertices)
     self.verts = (Vec2d * len(vertices))
     self.verts = self.verts(Vec2d(0, 0))
     for (i, vertex) in enumerate(vertices):
         self.verts[i].x = vertex[0]
         self.verts[i].y = vertex[1]
         
     self._shape = cp.cpPolyShapeNew(body._body, len(vertices), self.verts, offset)
     self._shapecontents = self._shape.contents
Esempio n. 2
0
    def __init__(self, body, vertices, offset):
        """body is the body to attach the poly to, verts is an array of
        cpVect's defining a convex hull with a counterclockwise winding, offset
        is the offset from the body's center of gravity in body local
        coordinates."""
        self._body = body
        verts = (vec2d * len(vertices))(*vertices)
#		for (i, vertex) in enumerate(vertices):
#			verts[i].x = vertex.x
#			verts[i].y = vertex.y
        print cp.cpMomentForPoly(body.mass, len(vertices), verts, offset)
        self._shape = cp.cpPolyShapeNew(body._body, len(vertices), verts, offset)
Esempio n. 3
0
 def __init__(self, body, vertices, offset):
     """body is the body to attach the poly to, verts is an array of
     cpVect's defining a convex hull with a counterclockwise winding, offset
     is the offset from the body's center of gravity in body local
     coordinates."""
     self._body = body
     verts = (vec2d * len(vertices))(*vertices)
     #		for (i, vertex) in enumerate(vertices):
     #			verts[i].x = vertex.x
     #			verts[i].y = vertex.y
     print cp.cpMomentForPoly(body.mass, len(vertices), verts, offset)
     self._shape = cp.cpPolyShapeNew(body._body, len(vertices), verts,
                                     offset)
Esempio n. 4
0
 def __init__(self, body, vertices, offset, auto_order_vertices=False):
     """body is the body to attach the poly to, verts is an array of
     cpVect's defining a convex hull with a counterclockwise winding, offset
     is the offset from the body's center of gravity in body local
     coordinates. Set auto_order_vertices to automatically order the
     vertices"""
     if auto_order_vertices: 
         raise Exception(NotImplemented)
     self._body = body
     #self.verts = (Vec2d * len(vertices))(*vertices)
     self.verts = (Vec2d * len(vertices))
     self.verts = self.verts(Vec2d(0, 0))
     for (i, vertex) in enumerate(vertices):
         self.verts[i].x = vertex[0]
         self.verts[i].y = vertex[1]
         
     self._shape = cp.cpPolyShapeNew(body._body, len(vertices), self.verts, offset)
     self._shapecontents = self._shape.contents