BGE/Math

Alias: BGE.Math


Static Methods

createCornerPoints( topLeft: Vector, topRight: Vector, bottomLeft: Vector, bottomRight: Vector, ): CornerPoints

static

Parameters

Returns

isFloatArray44(x: dynamic): boolean

static

Parameters

  • x (dynamic)

Returns

  • boolean

getFloat44Identity(): dynamic

static

Returns

  • dynamic

fillFloat44(dest: dynamic, src: dynamic): void

static

Parameters

  • dest (dynamic)
  • src (dynamic)

Returns

  • void

lookAt(from: Vector, lookTo: Vector): dynamic

static

Parameters

Returns

  • dynamic

orthographicMatrix( top: float, bottom: float, left: float, right: float, far: float, near: float, ): dynamic

static

Parameters

  • top (float)
  • bottom (float)
  • left (float)
  • right (float)
  • far (float)
  • near (float)

Returns

  • dynamic

getScaleMatrix(scale: Vector): dynamic

static

Parameters

Returns

  • dynamic

getRotationMatrix(rotation: Vector): dynamic

static

Parameters

Returns

  • dynamic

getTranslationMatrix(position: Vector): dynamic

static

Parameters

Returns

  • dynamic

getTransformationMatrix( position: Vector, rotation: Vector, scale: Vector, ): dynamic

static

Parameters

Returns

  • dynamic

createTransform(): Transform

static

Returns

Min(a: float, b: float): float

static

Parameters

  • a (float)
  • b (float)

Returns

  • float

Max(a: float, b: float): float

static

Parameters

  • a (float)
  • b (float)

Returns

  • float

Clamp(number: float, minVal: float, maxVal: float): float

static

Parameters

  • number (float)
  • minVal (float)
  • maxVal (float)

Returns

  • float

Atan2(y: float, x: float): float

static

Parameters

  • y (float)
  • x (float)

Returns

  • float

IsIntegerEven(number: integer): boolean

static

Parameters

  • number (integer)

Returns

  • boolean

IsIntegerOdd(number: integer): boolean

static

Parameters

  • number (integer)

Returns

  • boolean

Power(number: float, pow: integer): float

static

Parameters

  • number (float)
  • pow (integer)

Returns

  • float

Round(number: float, decimals?: integer): float

static

Parameters

  • number (float)
  • decimals (integer, optional, default: 0)

Returns

  • float

DegreesToRadians(degrees: float): float

static

Parameters

  • degrees (float)

Returns

  • float

RadiansToDegrees(radians: float): float

static

Parameters

  • radians (float)

Returns

  • float

RandomInRange(lowestInt: integer, highestInt: integer): integer

static

Parameters

  • lowestInt (integer)
  • highestInt (integer)

Returns

  • integer

constrainAngle(angleRad: float): float

static

Parameters

  • angleRad (float)

Returns

  • float

RotateVectorAroundPoint2d( vector1: Vector, point: Vector, radians: float, ): Vector

static

Parameters

Returns

RotateVectorAroundPoint3d( vector1: Vector, point: Vector, axis: Vector, radians: float, ): Vector

static

Rotates vector1 around point in 3D by radians about the provided axis. axis does not need to be normalized.

Parameters

Returns

TotalDistance(vector1: Vector, vector2: Vector): float

static

Parameters

Returns

  • float

GetAngle(point1: Vector, point2: Vector): float

static

Parameters

Returns

  • float

GetAngleBetweenVectors( center: vector, point1: Vector, point2: Vector, ): float

static

Parameters

Returns

  • float

GetAngleAtPoint3d( center: Vector, point1: Vector, point2: Vector, ): float

static

Returns the angle at center between legs center->point1 and center->point2 in radians. Uses atan2(|u x v|, u · v) for stable 3D angle calculation in [0, PI].

Parameters

Returns

  • float

GetSliceAnglesAtPoint3d( centerPoint: Vector, lineStart: Vector, lineEnd: Vector, sliceLength: float, includeRemainder?: boolean, ): dynamic

static

Returns one theta (radians) per slice along the segment from lineStart to lineEnd, where each theta is measured at centerPoint between consecutive slice endpoints.

Parameters

  • centerPoint (Vector)
  • lineStart (Vector)
  • lineEnd (Vector)
  • sliceLength (float)
  • includeRemainder (boolean, optional, default: false)

Returns

  • dynamic

average(num1: float, num2: float): float

static

Parameters

  • num1 (float)
  • num2 (float)

Returns

  • float

arraySum(nums: dynamic): float

static

Parameters

  • nums (dynamic)

Returns

  • float

arrayAverage(nums: dynamic): float

static

Parameters

  • nums (dynamic)

Returns

  • float

arrayMin(nums: dynamic): float

static

Parameters

  • nums (dynamic)

Returns

  • float

arrayMax(nums: dynamic): float

static

Parameters

  • nums (dynamic)

Returns

  • float

intersectRayWithPlane(plane: Plane, ray: Ray): BGE.Math.Vector

static

Parameters

Returns

  • BGE.Math.Vector

signedDistanceFromPointToPlane( plane: Plane, targetPoint: BGE.Math.Vector, ): float

static

Returns signed distance from a point to a plane. Positive/negative sign indicates which side of the plane normal the point is on.

Parameters

  • plane (Plane)
  • targetPoint (BGE.Math.Vector)

Returns

  • float

distanceFromPointToPlane( plane: Plane, targetPoint: BGE.Math.Vector, ): float

static

Returns the absolute shortest distance from a point to a plane.

Parameters

  • plane (Plane)
  • targetPoint (BGE.Math.Vector)

Returns

  • float

angleToPlaneSurfaceDeg( plane: BGE.Math.Plane, v: BGE.Math.Vector, ): float

static

0..90 deg 0 = parallel to plane, 90 = perpendicular to plane

Parameters

  • plane (BGE.Math.Plane)
  • v (BGE.Math.Vector)

Returns

  • float

angleToPlaneNormalDeg( plane: BGE.Math.Plane, v: BGE.Math.Vector, ): float

static

0..180 deg 0 = +normal, 180 = -normal, 90 = parallel to plane

Parameters

  • plane (BGE.Math.Plane)
  • v (BGE.Math.Vector)

Returns

  • float

closestPointOnPlane( plane: BGE.Math.Plane, point: BGE.Math.Vector, ): BGE.Math.Vector

static

Parameters

  • plane (BGE.Math.Plane)
  • point (BGE.Math.Vector)

Returns

  • BGE.Math.Vector

projectRayOntoPlane( plane: BGE.Math.Plane, ray: BGE.Math.Ray, ): BGE.Math.Ray

static

Parameters

  • plane (BGE.Math.Plane)
  • ray (BGE.Math.Ray)

Returns

  • BGE.Math.Ray

worldPointToTexturePixel( worldPoint: BGE.Math.Vector, textureCenterWorldPoint: BGE.Math.Vector, textureWidth: float, textureHeight: float, ): BGE.Math.Vector

static

Maps a world-space point on a plane to pixel coordinates within a textureWidth x textureHeight texture, anchored so that textureCenterWorldPoint corresponds to the texture's own center pixel (rather than world (0,0) mapping to the texture's (0,0) pixel, which would pin the texture to a fixed absolute-world-space footprint regardless of where the plane/camera actually are).

Parameters

  • worldPoint (BGE.Math.Vector) — a point on the plane, in world space
  • textureCenterWorldPoint (BGE.Math.Vector) — the world-space point that should map to the texture's center
  • textureWidth (float)
  • textureHeight (float)

Returns

  • BGE.Math.Vector — pixel coordinates within the texture (z unused)

VectorZero(): BGE.Math.Vector

static

Returns

  • BGE.Math.Vector

VectorFromFloatArray(array: dynamic): BGE.Math.Vector

static

Parameters

  • array (dynamic)

Returns

  • BGE.Math.Vector

createScaleVector( scale_x: float, scale_y?: dynamic, scale_z?: dynamic, ): BGE.Math.Vector

static

Parameters

  • scale_x (float) — horizontal scale
  • scale_y (dynamic, optional, default: "invalid") — vertical scale, or if invalid, use the horizontal scale as vertical scale
  • scale_z (dynamic, optional, default: "invalid")

Returns

  • BGE.Math.Vector

distanceFromPlane( planePoint: BGE.Math.Vector, planeNormal: BGE.Math.Vector, targetPoint: BGE.Math.Vector, ): float

static

Parameters

  • planePoint (BGE.Math.Vector)
  • planeNormal (BGE.Math.Vector)
  • targetPoint (BGE.Math.Vector)

Returns

  • float

midPointBetweenPoints( a: BGE.Math.Vector, b: BGE.Math.Vector, ): BGE.Math.Vector

static

Parameters

  • a (BGE.Math.Vector)
  • b (BGE.Math.Vector)

Returns

  • BGE.Math.Vector

averagePoint(points: Array.<BGE.Math.Vector>): BGE.Math.Vector

static

The centroid of a set of points - their component-wise average. Note this is not the same as the center of their bounding box (see getBounds).

Parameters

  • points (Array.<BGE.Math.Vector>)

Returns

  • BGE.Math.Vector — the average of every point, or the origin if given no points

getBounds(points: dynamic): dynamic

static

Parameters

  • points (dynamic)

Returns

  • dynamic

boundsOverlapRect( points: Array.<BGE.Math.Vector>, width: float, height: float, ): boolean

static

Checks if the (x, y) bounding box of points overlaps the axis-aligned rectangle [0, width] x [0, height] at all.

Parameters

  • points (Array.<BGE.Math.Vector>)
  • width (float)
  • height (float)

Returns

  • boolean

getBoundingCubePoints(points: dynamic): dynamic

static

Parameters

  • points (dynamic)

Returns

  • dynamic

vectorArraysEqual(a?: dynamic, b?: dynamic): boolean

static

Parameters

  • a (dynamic, optional, default: "[]")
  • b (dynamic, optional, default: "[]")

Returns

  • boolean

vectorArrayCopy(a?: dynamic): dynamic

static

Parameters

  • a (dynamic, optional, default: "[]")

Returns

  • dynamic

intersectPointPoint( p1: Vector, p2: Vector, p3: Vector, p4: Vector, mustBeInSegment?: boolean, ): BGE.Math.Vector

static

From https://paulbourke.net/geometry/pointlineplane/javascript.txt

Parameters

Returns

  • BGE.Math.Vector

intersectPointAngle( p1: BGE.Math.Vector, angle1FromXAxis: float, p2: BGE.Math.Vector, angle2FromXAxis: float, ): BGE.Math.Vector

static

Parameters

  • p1 (BGE.Math.Vector)
  • angle1FromXAxis (float)
  • p2 (BGE.Math.Vector)
  • angle2FromXAxis (float)

Returns

  • BGE.Math.Vector

Enums

BGE.Math.WindingDirection

enumstaticreadonly

Properties

  • clockwise (default: 0)
  • counterclockwise (default: 1)

Other

CornerPoints

static

Properties

  • topLeft (dynamic)
  • topRight (dynamic)
  • bottomLeft (dynamic)
  • bottomRight (dynamic)

Transform

static

Properties

  • position (BGE.Math.Vector)
  • rotation (BGE.Math.vector)
  • scale (BGE.Math.Vector)

Triangle

static

Properties

  • lengths (dynamic)
  • angles (dynamic)
  • anglesToNext (dynamic)
  • anglesToPrevious (dynamic)
  • points (dynamic)
  • longestIndex (integer)
  • height (float)
  • winding (WindingDirection)
  • angleRotatedFromOriginal (float)

Circle

static

Parameters

  • x (float, optional, default: 0)
  • y (float, optional, default: 0)
  • radius (float, optional, default: 0)

Properties

  • x (float)
  • y (float)
  • radius (float)

Returns

  • BGE.Math.Circle

PI

staticreadonly

Default: 3.14159265358

HALF_PI

staticreadonly

Default: 1.57079632679

Plane

static

Properties

Ray

static

Properties

Rectangle

static

Parameters

  • x (float, optional, default: 0)
  • y (float, optional, default: 0)
  • width (float, optional, default: 0)
  • height (float, optional, default: 0)

Properties

  • x (float)
  • y (float)
  • width (float)
  • height (float)

Returns

  • BGE.Math.Rectangle

Vector

static

Properties

  • x (float)
  • y (float)
  • z (float)