C# Class Nez.PhysicsShapes.Polygon

Inheritance: Shape
Exibir arquivo Open project: prime31/Nez Class Usage Examples

Public Properties

Property Type Description
_edgeNormals Vector2[]
isUnrotated bool
points Vector2[]

Protected Properties

Property Type Description
_originalPoints Vector2[]

Public Methods

Method Description
Polygon ( Vector2 points ) : System

constructs a Polygon from points. points should be specified in clockwise fashion without duplicating the first/last point and they should be centered around 0,0.

Polygon ( int vertCount, float radius ) : System

creates a symmetrical polygon based on the radius and vertCount passed in

buildEdgeNormals ( ) : void

builds the Polygon edge normals. These are lazily created and updated only by the edgeNormals getter

buildSymmetricalPolygon ( int vertCount, float radius ) : Vector2[]

builds a symmetrical polygon (hexagon, octogon, n-gon) and returns the points

collidesWithLine ( Vector2 start, Vector2 end, RaycastHit &hit ) : bool
collidesWithShape ( Shape other, CollisionResult &result ) : bool
containsPoint ( Vector2 point ) : bool

essentially what the algorithm is doing is shooting a ray from point out. If it intersects an odd number of polygon sides we know it is inside the polygon.

findPolygonCenter ( Vector2 points ) : Vector2

finds the center of the Polygon. Note that this will be accurate for regular polygons. Irregular polygons have no center.

getClosestPointOnPolygonToPoint ( Vector2 points, Vector2 point, float &distanceSquared, Vector2 &edgeNormal ) : Vector2

iterates all the edges of the polygon and gets the closest point on any edge to point. Returns via out the squared distance to the closest point and the normal of the edge it is on. point should be in the space of the Polygon (point - poly.position)

getFarthestPointInDirection ( Vector2 points, Vector2 direction ) : Vector2
overlaps ( Shape other ) : bool
pointCollidesWithShape ( Vector2 point, CollisionResult &result ) : bool
recalculateCenterAndEdgeNormals ( ) : void

recalculates the Polygon centers. This must be called if the points are changed!

recenterPolygonVerts ( Vector2 points ) : void

recenters the points of the polygon

Private Methods

Method Description
Polygon ( Vector2 points, bool isBox ) : System
recalculateBounds ( Collider collider ) : void

Method Details

Polygon() public method

constructs a Polygon from points. points should be specified in clockwise fashion without duplicating the first/last point and they should be centered around 0,0.
public Polygon ( Vector2 points ) : System
points Vector2 Points.
return System

Polygon() public method

creates a symmetrical polygon based on the radius and vertCount passed in
public Polygon ( int vertCount, float radius ) : System
vertCount int Vert count.
radius float Radius.
return System

buildEdgeNormals() public method

builds the Polygon edge normals. These are lazily created and updated only by the edgeNormals getter
public buildEdgeNormals ( ) : void
return void

buildSymmetricalPolygon() public static method

builds a symmetrical polygon (hexagon, octogon, n-gon) and returns the points
public static buildSymmetricalPolygon ( int vertCount, float radius ) : Vector2[]
vertCount int Vert count.
radius float Radius.
return Vector2[]

collidesWithLine() public method

public collidesWithLine ( Vector2 start, Vector2 end, RaycastHit &hit ) : bool
start Vector2
end Vector2
hit RaycastHit
return bool

collidesWithShape() public method

public collidesWithShape ( Shape other, CollisionResult &result ) : bool
other Shape
result CollisionResult
return bool

containsPoint() public method

essentially what the algorithm is doing is shooting a ray from point out. If it intersects an odd number of polygon sides we know it is inside the polygon.
public containsPoint ( Vector2 point ) : bool
point Vector2 Point.
return bool

findPolygonCenter() public static method

finds the center of the Polygon. Note that this will be accurate for regular polygons. Irregular polygons have no center.
public static findPolygonCenter ( Vector2 points ) : Vector2
points Vector2 Points.
return Vector2

getClosestPointOnPolygonToPoint() public static method

iterates all the edges of the polygon and gets the closest point on any edge to point. Returns via out the squared distance to the closest point and the normal of the edge it is on. point should be in the space of the Polygon (point - poly.position)
public static getClosestPointOnPolygonToPoint ( Vector2 points, Vector2 point, float &distanceSquared, Vector2 &edgeNormal ) : Vector2
points Vector2
point Vector2 Point.
distanceSquared float Distance squared.
edgeNormal Vector2 Edge normal.
return Vector2

getFarthestPointInDirection() public static method

public static getFarthestPointInDirection ( Vector2 points, Vector2 direction ) : Vector2
points Vector2
direction Vector2
return Vector2

overlaps() public method

public overlaps ( Shape other ) : bool
other Shape
return bool

pointCollidesWithShape() public method

public pointCollidesWithShape ( Vector2 point, CollisionResult &result ) : bool
point Vector2
result CollisionResult
return bool

recalculateCenterAndEdgeNormals() public method

recalculates the Polygon centers. This must be called if the points are changed!
public recalculateCenterAndEdgeNormals ( ) : void
return void

recenterPolygonVerts() public static method

recenters the points of the polygon
public static recenterPolygonVerts ( Vector2 points ) : void
points Vector2 Points.
return void

Property Details

_edgeNormals public_oe property

public Vector2[] _edgeNormals
return Vector2[]

_originalPoints protected_oe property

protected Vector2[] _originalPoints
return Vector2[]

isUnrotated public_oe property

public bool isUnrotated
return bool

points public_oe property

the points that make up the Polygon. They should be CCW and convex.
public Vector2[] points
return Vector2[]