Difference between revisions of "Cabal Common Library Doc 2DCollision"

From Elite Wiki
m (Profiling added)
m (formatting)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Overview ==
 
== Overview ==
This is the main class for the 2D helpers with its members. Scripts can instantiate a copy, e.g.
+
This is the main class for the 2D helpers with its members and part of the [[Cabal_Common_Library]]. Scripts can instantiate a copy, e.g.
{{CodeEx|codeex=this.myHelper = new Cabal_Common_2DCollision();}}
+
this.myHelper = new worldScripts.Cabal_Common_Functions.Cabal_Common_2DCollision();
  +
Versions before v1.6 have used <code>this.myHelper = new Cabal_Common_2DCollision();</code>
  +
   
 
== Properties ==
 
== Properties ==
 
=== internalVersion ===
 
=== internalVersion ===
 
Number. Property to give OXPs a chance to check the required lib min. version easily. This number will be raised with every release.
 
Number. Property to give OXPs a chance to check the required lib min. version easily. This number will be raised with every release.
{{CodeEx|codeex=var a = this.myHelper.internalVersion;
+
var a = this.myHelper.internalVersion;
a -> {{CCL_Int}}}}
+
  +
Current version is {{CodeEx|codeex={{CCL_Int}}}}
  +
   
 
== Methods ==
 
== Methods ==

Latest revision as of 00:17, 16 September 2013

Overview

This is the main class for the 2D helpers with its members and part of the Cabal_Common_Library. Scripts can instantiate a copy, e.g.

 this.myHelper = new worldScripts.Cabal_Common_Functions.Cabal_Common_2DCollision();

Versions before v1.6 have used 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;

Current version is

15


Methods

All methods are ignoring the z-coordinate .-)

boundingBox()

boundingBox: function( minmax, pos )
Profiler
Native 0.000042s
Extension 0.000013s
JS 0.000136s

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 )
Profiler
Native 0.000042s
Extension 0.000012s
JS 0.000101s

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 )
Profiler
Native 0.000240s
Extension 0.000123s
JS 0.000252s

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 )
Profiler
Native 0.000272s
Extension 0.000141s
JS 0.000303s

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).