Polygon subtype of Shape.

Can be used to simulate any convex polygon.

Constructor

@:has_untyped@:value({ filter : null, material : null })new(localVerts:Dynamic, ?material:Material, ?filter:InteractionFilter)

Construct a new Polygon.

The localVerts parameter is typed Dynamic and may be one of: Array<Vec2>, flash.Vector<Vec2>, Vec2List, GeomPoly

Parameters:

localVerts

The local vertices of polygon.

material

The material for this polygon. (default new Material())

filter

The interaction filter for this polygon. (default new InteractionFilter())

Returns:

The constructed Polygon.

Throws:

#

If localVerts is null, or not of the expected Type.

#

If localVerts contains any disposed or null Vec2.

Variables

read onlyedges:EdgeList

Set of edges on polygon.

This list is immutable.

read onlylocalVerts:Vec2List

Local coordinates of vertices.

This list can be modified, but modifications to a Polygon that is part of a static Body inside of a Space will given an error in debug builds.

read onlyworldVerts:Vec2List

World coordinates of vertices.

This list can be accessed, but any queries of values will result in an error in debug builds unless this Polygon is part of a Body.

This list is immutable.

@:value(null)zpp_inner_zn:ZPP_Polygon = null

@private

Methods

validity():ValidationResult

Determine validity of polygon for use in a Nape simulation.

Static methods

@:value({ weak : false })staticbox(width:Float, height:Float, weak:Bool = false):Array<Vec2>

Construct a polygon representing an origin centred box.

This method is equivalent to calling: Polygon.rect(-width/2,-height/2,width,height)

Parameters:

width

The width of the box (This value may be negative but will make no difference).

height

The height of the box (This value may be negative but will make no difference).

weak

If true, the generated list of vertices will be allocated as weak Vec2s so that when this list is passed to a Nape function these Vec2s will be automatically sent back to object pool. (default false)

Returns:

An array of Vec2 representing the given box.

@:value({ weak : false })staticrect(x:Float, y:Float, width:Float, height:Float, weak:Bool = false):Array<Vec2>

Construct a polygon representing a rectangle.

For a dynamic object, you may consider use of the box method instead as dynamic bodies will only respond as expected if their centre of mass is equal to the origin.

The generate polygon will have coordinates equal to:

(x, y) -> (x + width, y + height)
Negative values of width/height are permitted so that the given x/y values may not necessarigly be the top-left corner of rectangle.

Parameters:

x

The x coordinate of rectangle.

y

The y coordinate of rectangle.

width

The width of the ractangle. This value may be negative.

height

The height of the rectangle This value may be negative.

weak

If true, the generated list of vertices will be allocated as weak Vec2s so that when this list is passed to a Nape function these Vec2s will be automatically sent back to object pool. (default false)

Returns:

An array of Vec2 representing the given rectangle.

@:value({ weak : false, angleOffset : 0.0 })staticregular(xRadius:Float, yRadius:Float, edgeCount:Int, angleOffset:Float = 0.0, weak:Bool = false):Array<Vec2>

Construct a regular polygon centred at origin.

Vertices are created at positions on the edge of an ellipsoid of given radii, when radii are not equal the vertices will not have an equal angle between them; it will be as though an actual regular polygon were created, and then squashed to conform to the input radii.

Parameters:

xRadius

The x radius of polygon before angleOffset rotation.

yRadius

The y radius of polygon before angleOffset rotation.

edgeCount

The number of edges/vertices in polygon.

angleOffset

The clockwise angular offset to generate vertices at in radians. (default 0.0)

weak

If true, the generated list of vertices will be allocated as weak Vec2s so that when this list is passed to a Nape function these Vec2s will be automatically sent back to object pool. (default false)

Returns:

An array of Vec2 representing the polygon.

Inherited Variables

Defined by Shape

read onlyangDrag:Float

Coeffecient of angular fluid drag for this Shape.

read onlyarea:Float

Area of the Hhape.

body:Null<Body>

Body this Shape is assigned to.

This value can be set to add Shape to the given Body, and set to null to remove it from its present Body.

read onlybounds:AABB

World space bounding box for this shape.

This value can be accessed even if the Shape is not part of a Body, however attempting to query its values would result in an error in debug builds.

This AABB is immutable.

read onlycastCircle:Null<Circle>

Faster equivalent to casting this to Circle type

read onlycastPolygon:Null<Polygon>

Faster equivalent to casting this to Polygon type

filter:InteractionFilter

InteractionFilter used by this shape.

fluidEnabled:Bool

Whether this shape is able to interact as a fluid.

Unless this field is true, this Shape can never interact as a fluid.

Just because this field is true however, does not mean this shape will always interact as a fluid, the final result is down to the combination of InteractionFilters on the pairing of shapes and sensory interaction takes higher priority.

fluidProperties:FluidProperties

FluidProperties used by this shape.

This object provides information for buoyancy and fluid drag computations when this shape is interacting as a fluid.

read onlyinertia:Float

Non-mass weighted moment of inertia for Shape.

localCOM:Vec2

Local space centre of mass of this Shape.

This Vec2 can be set and is equivalent to performing the necessary translation of the Shape in local coordinates, and also equivalent to this.localCOM.set(value).
Setting this value whilst this shape is part of a static Body that is part of a Space is not permitted.

material:Material

Material used by this shape.

sensorEnabled:Bool

Whether this shape is able to interact as sensor.

Unless this field is true, this Shape can never interact as a sensor.

Just because this field is true however, does not mean this shape will always interact as a sensor, the final result is down to the combination of InteractionFilters on the pairing of shapes. Sensor interaction has highest priority.

read onlytype:ShapeType

Type of shape.

read onlyworldCOM:Vec2

World space centre of mass of this Shape.

This value can be accessed even if Shape is not in a Body, but attempting to query the values of it will return an error in debug builds unless the Shape is in a Body.

This Vec2 is immutable.

@:value(null)zpp_inner:ZPP_Shape = null

@private

Defined by Interactor

read onlycastBody:Null<Body>

Fast equivalent to cast(interactor, Body)

read onlycastCompound:Null<Compound>

Fast equivalent to cast(interactor, Compound)

read onlycastShape:Null<Shape>

Fast equivalent to cast(interactor, Shape)

read onlycbTypes:CbTypeList

Set of CbType's assigned to this Interactor.

group:Null<InteractionGroup>

InteractionGroup assigned to this Interactor.

read onlyid:Int

Unique id of this Interactor.

read onlyuserData:Dynamic<Dynamic>

Dynamic object for user to store additional data.

This object cannot be set, only its dynamically created properties may be set. In AS3 the type of this property is &#42

This object will be lazily constructed so that until accessed for the first time, will be null internally.

@:value(null)zpp_inner_i:ZPP_Interactor = null

@private

Inherited Methods

Defined by Shape

contains(point:Vec2):Bool

Test containment of world-space coordinate in Shape.

This Shape must be part of a Body so that world coordinates are defined.

Parameters:

point

The point to check for containment.

Returns:

True if point is contained within the Shape.

Throws:

If

point is null or disposed of.

If

this shape is not part of a Body.

copy():Shape

Produce an exact copy of this Shape.

The copied shape will be identical with the copied Shape's userData object being assigned the same fields as 'this' Shape with the same values copied over by reference for object types.

Returns:

A copy of this shape.

inlineisCircle():Bool

Faster equivalent to type == ShapeType.CIRCLE

Returns:

True if shape is a Circle type.

inlineisPolygon():Bool

Faster equivalent to type == ShapeType.POLYGON

Returns:

True if shape is a Polygon type.

rotate(angle:Float):Shape

Rotate this shape in its local coordinate system.

Parameters:

angle

The number of radians to rotate this Shape by in a clockwise direction.

Returns:

A reference to 'this' Shape.

Throws:

#

If this shape is part of a static body that is inside of a Space.

scale(scalex:Float, scaley:Float):Shape

Scale this shape in its local coordinate system.

For Circle shapes, scalex and scaley must be exactly equal.

Parameters:

scalex

The x-coordinate scaling to apply to Shape.

scaley

The y-coordinate scaling to apply to Shape.

Returns:

A reference to 'this' Shape.

Throws:

#

If this shape is part of a static body that is inside of a Space.

#

If scalex or scaley is 0. Negative values 'are' permitted.

@:keeptoString():String

@private

transform(matrix:Mat23):Shape

Apply local transformation matrix to Shape.

For Circle shapes, the matrix must be equiorthogonal.

Parameters:

matrix

The matrix to transform Shape by.

Returns:

A reference to 'this' Shape.

Throws:

#

If matrix is null or singular.

#

If shape is a Circle, and matrix is not equiorthogonal.

#

If this shape is part of a static body that is inside of a Space.

translate(translation:Vec2):Shape

Translate this shape in its local coordinate system.

This is equivalent to: shape.localCOM.addeq(displacement)

Parameters:

translation

The local translation to apply to Shape.

Returns:

A reference to 'this' Shape.

Throws:

#

If translation is null or has been disposed of.

#

If this shape is part of a static body that is inside of a Space.

Defined by Interactor

inlineisBody():Bool

Fast equivalent to Std.is(interactor, Body)

Returns:

true if this Interactor is a Body.

inlineisCompound():Bool

Fast equivalent to Std.is(interactor, Compound)

Returns:

true if this Interactor is a Compound.

inlineisShape():Bool

Fast equivalent to Std.is(interactor, Shape)

Returns:

true if this Interactor is a Shape.