Cabal Common Library Doc 2DCollision
From Elite Wiki
Contents
Overview
This is the main class for the 2D helpers with its members. Scripts can instantiate a copy, e.g.
this.myHelper = new Cabal_Common_2DCollision(); |
Properties
internalVersion
Number. Property to give OXPs a chance to check the required lib min. version easily. This number will be raised with every release.
var a = this.myHelper.internalVersion;
a -> 15 |
Methods
All methods are ignoring the z-coordinate .-)
boundingBox()
boundingBox: function( minmax, pos ) |
Checks if point is inside the bounding box.
Parameters:
- minmax
- Array. 4 positions in a.x,a.y,b.x,b.y
- pos
- Vector. Position to be checked.
Returns:
- inside
- Boolean. True if inside.
pointInPoly()
pointInPoly: function( nvert, vertx, verty, pos, con ) |
Checks if a point is inside a polygon.
Parameters:
- nvert
- Number of vertices in the polygon.
- vertx, verty
- Arrays containing the x- and y-coordinates of the polygon's vertices.
- pos
- Vector. x- and y-coordinate of the test point.
- con
- Boolean. Concave shapes may need to set it.
Returns:
- inside
- Boolean. True if inside.
pointOnLine()
pointOnLine: function( pa, pb, pos ) |
Checks if point is on a specified line with a tolerance of 0.4. This method has a problem with vertical lines. If it needs to be more accurate use .pointOnLineB().
Parameters:
- pa
- Vector. Starting point of the line.
- pb
- Vector. End point of the line.
- pos
- Vector. Position to be checked.
Returns:
- online
- Boolean. True if on line (within tolerance).
pointOnLineB()
pointOnLineB: function( p1,p2,p3,tol ) |
Checks if point is on a specified line. Based on Paul Bourkes explanation ([1]).
Parameters:
- p1
- Vector. Starting point of the line.
- p2
- Vector. End point of the line.
- p3
- Vector. Position to be checked.
- tol
- Number. Tolerance. Default 0.01.
Returns:
- online
- Boolean. True if on line (within tolerance).