class CP::Shape::Poly
- CP::Shape::Poly
- CP::Shape
- Reference
- Object
Overview
A convex polygon shape
Slowest, but most flexible collision shape.
Included Modules
Direct Known Subclasses
Defined in:
chipmunk/shape.crchipmunk/unsafe.cr
Constructors
-
.new(body : Body | Nil, verts : Array(Vect) | Slice(Vect), transform : Transform = Transform::IDENTITY, radius : Number = 0)
Initialize a polygon shape with rounded corners.
-
.new(body : Body | Nil, verts : Array(Vect) | Slice(Vect), radius : Number)
Initialize a polygon shape with rounded corners.
Class Method Summary
-
.area(verts : Array(Vect) | Slice(Vect), radius : Number = 0) : Float64
Calculate the signed area of a polygon.
-
.centroid(verts : Array(Vect) | Slice(Vect)) : Vect
Calculate the natural centroid of a polygon.
-
.convex_hull(verts : Array(Vect) | Slice(Vect), tol : Number = 0) : Tuple(Slice(Vect), Int32)
Calculate the convex hull of a given set of points.
-
.moment(m : Number, verts : Array(Vect) | Slice(Vect), offset : Vect = CP::Vect.new(0, 0), radius : Number = 0) : Float64
Calculate the moment of inertia for a solid polygon shape.
Instance Method Summary
-
#radius : Float64
Get the radius of a polygon shape.
-
#radius=(radius : Number)
Unsafe. Set the radius of a poly shape.
-
#set_verts(verts : Array(Vect) | Slice(Vect), transform : Transform = Transform::IDENTITY)
Unsafe. Set the vertices of a poly shape.
-
#size : Int32
Get the number of verts in a polygon shape.
-
#unsafe_fetch(index : Int) : Vect
Get the i-th vertex of a polygon shape.
Instance methods inherited from class CP::Shape
area : Float64
area,
bb : BB
bb,
body : Body | Nil
body,
body=(body : Body | Nil)
body=,
cache_bb : BB
cache_bb,
center_of_gravity : Vect
center_of_gravity,
collide(b : Shape) : ContactPointSet
collide,
collision_type : CollisionType
collision_type,
collision_type=(collision_type : Int)
collision_type=,
density : Float64
density,
density=(density : Number)
density=,
elasticity : Float64
elasticity,
elasticity=(elasticity : Number)
elasticity=,
filter : ShapeFilter
filter,
filter=(filter : ShapeFilter)
filter=,
friction : Float64
friction,
friction=(friction : Number)
friction=,
mass : Float64
mass,
mass=(mass : Number)
mass=,
moment : Float64
moment,
point_query(p : Vect) : PointQueryInfo
point_query,
segment_query(a : Vect, b : Vect, radius : Number = 0) : SegmentQueryInfo | Nil
segment_query,
sensor=(sensor : Bool)
sensor=,
sensor? : Bool
sensor?,
space : Space | Nil
space,
surface_velocity : Vect
surface_velocity,
surface_velocity=(surface_velocity : Vect)
surface_velocity=,
update(transform : Transform) : BB
update
Constructor Detail
Initialize a polygon shape with rounded corners. A convex hull will be created from the vertices.
The parameters are: the body to attach the poly to; the verts (vertices) of the polygon; the transform to apply to every vertex; the radius of the corners.
Adding a small radius will bevel the corners and can significantly reduce problems where the poly gets stuck on seams in your geometry.
Initialize a polygon shape with rounded corners. The vertices must be convex with a counter-clockwise winding.
Class Method Detail
Calculate the signed area of a polygon.
A clockwise winding gives positive area. This is probably backwards from what you expect, but matches Chipmunk's winding for poly shapes.
Calculate the natural centroid of a polygon.
Calculate the convex hull of a given set of points.
tol is the allowed amount to shrink the hull when simplifying it. A tolerance of 0.0 creates an exact hull.
Returns the convex hull and the index where the first vertex
in the hull came from (i.e. verts[first] == result[0]
)
Calculate the moment of inertia for a solid polygon shape.
Assumes its center of gravity is at its centroid. The offset is added to each vertex.
Instance Method Detail
Unsafe. Set the radius of a poly shape.
This change is only picked up as a change to the position of the shape's surface, but not its velocity. Changing it will not result in realistic physical behavior. Only use if you know what you are doing!
Unsafe. Set the vertices of a poly shape.
This change is only picked up as a change to the position of the shape's surface, but not its velocity. Changing it will not result in realistic physical behavior. Only use if you know what you are doing!