C# Класс Nez.PhysicsShapes.Polygon

Наследование: Shape
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
_edgeNormals Vector2[]
isUnrotated bool
points Vector2[]

Защищенные свойства (Protected)

Свойство Тип Описание
_originalPoints Vector2[]

Открытые методы

Метод Описание
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

Приватные методы

Метод Описание
Polygon ( Vector2 points, bool isBox ) : System
recalculateBounds ( Collider collider ) : void

Описание методов

Polygon() публичный Метод

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.
Результат System

Polygon() публичный Метод

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.
Результат System

buildEdgeNormals() публичный Метод

builds the Polygon edge normals. These are lazily created and updated only by the edgeNormals getter
public buildEdgeNormals ( ) : void
Результат void

buildSymmetricalPolygon() публичный статический Метод

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.
Результат Vector2[]

collidesWithLine() публичный Метод

public collidesWithLine ( Vector2 start, Vector2 end, RaycastHit &hit ) : bool
start Vector2
end Vector2
hit RaycastHit
Результат bool

collidesWithShape() публичный Метод

public collidesWithShape ( Shape other, CollisionResult &result ) : bool
other Shape
result CollisionResult
Результат bool

containsPoint() публичный Метод

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.
Результат bool

findPolygonCenter() публичный статический Метод

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.
Результат Vector2

getClosestPointOnPolygonToPoint() публичный статический Метод

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.
Результат Vector2

getFarthestPointInDirection() публичный статический Метод

public static getFarthestPointInDirection ( Vector2 points, Vector2 direction ) : Vector2
points Vector2
direction Vector2
Результат Vector2

overlaps() публичный Метод

public overlaps ( Shape other ) : bool
other Shape
Результат bool

pointCollidesWithShape() публичный Метод

public pointCollidesWithShape ( Vector2 point, CollisionResult &result ) : bool
point Vector2
result CollisionResult
Результат bool

recalculateCenterAndEdgeNormals() публичный Метод

recalculates the Polygon centers. This must be called if the points are changed!
public recalculateCenterAndEdgeNormals ( ) : void
Результат void

recenterPolygonVerts() публичный статический Метод

recenters the points of the polygon
public static recenterPolygonVerts ( Vector2 points ) : void
points Vector2 Points.
Результат void

Описание свойств

_edgeNormals публичное свойство

public Vector2[] _edgeNormals
Результат Vector2[]

_originalPoints защищенное свойство

protected Vector2[] _originalPoints
Результат Vector2[]

isUnrotated публичное свойство

public bool isUnrotated
Результат bool

points публичное свойство

the points that make up the Polygon. They should be CCW and convex.
public Vector2[] points
Результат Vector2[]