constructor

Constructor of the Mover object

constructor(loc: any, vel: any, radius: any, mass: any, angle: any, friction: any, restitution: any)
Parameters
loc (any)
vel (any)
radius (any)
mass (any)
angle (any = 0)
friction (any = 0)
restitution (any = 0)

Engine

Create a namespace to store all the physics engine core functionality

Engine

Type: ({} | {})

Static Members
Core
Physics

mainGame

Engine Loop

mainGame(currentTime: any)
Parameters
currentTime (any) current time

collision

Collision detection

collision()

Type: function

resolveCollision

Resolve collision using the Impulse Method

resolveCollision(s1: any, s2: any, collisionInfo: CollisionInfo)
Parameters
s1 (any) one of the colliding objects
s2 (any) one od the colliding objects
collisionInfo (CollisionInfo) collision info calculated while collision detection

p

Collision position

p

Type: Vector

tangent

Tangent to a collision normal

tangent

Type: Vector

positionalCorrection

Reduces overlaps between objects by the predefined constant correctionRate

positionalCorrection(s1: any, s2: any, collisionInfo: CollisionInfo)
Parameters
s1 (any)
s2 (any)
collisionInfo (CollisionInfo)

correctionAmount

correctionAmount

Type: Vector

drag

Add drag to objects if they are in a drag area

drag()

j

Change Rigid Shape velocity due to drag

j

screen

Component to store canvas data

screen

Type: {mHeight: any, mWidth: any, mCanvas: HTMLElement, mContext: any}

x

Canvas boundaries

x

CollisionInfo

Class that represents collision info

new CollisionInfo()
Instance Members
setInfo(d, n, s)
changeDirection()
display()

DragArea

Class that represents a drag area

new DragArea()
Instance Members
update()
drawWater()

SineWave

Class that represents a sine wave used in DragArea animation

new SineWave()

sleep

Function to execute code after a given time

sleep(ms: any): Promise<unknown>
Parameters
ms (any) waiting time
Returns
Promise<unknown>:

Vector

A class that represents a vector using Cartesian coordinates

new Vector()
Instance Members
add(a)
subtract(a)
scale(n)
mag()
normalize()
dot(a)
cross(a)
rotate(angle, center)
draw(color)
copy()

constructor

Constructor of Circle class

constructor(mass: number, center: Vector, radius: number, angle: number, friction: number, restitution: number, gravity: boolean, info: string)
Parameters
mass (number) Circle mass
center (Vector) Circle center location
radius (number) Circle radius
angle (number = 0) Circle angle in radians
friction (number = 0) Circle friction
restitution (number = 0) Circle restitution (bounciness) (how much energy is preserved after collision)
gravity (boolean = true) consider Circle when applying gravity
info (string = "") additional info

rotate

Rotate circle

rotate(angle: number)
Parameters
angle (number) rotation angle in radians

displayBounds

Display hit box

displayBounds()

updateInertia

Set and update inertia

updateInertia()

collisionTest

Check if collision occurred, call specified methods to handle collision

collisionTest(otherShape: any, collisionInfo: any): boolean
Parameters
otherShape (any) other shape in the collision event
collisionInfo (any) collision info
Returns
boolean: did the collision occur

collidedCircCirc

Handle collision between circles

collidedCircCirc(c1: any, c2: any, collisionInfo: any): (boolean | CollisionInfo)
Parameters
c1 (any) first circle
c2 (any) second circle
collisionInfo (any) collision info
Returns
(boolean | CollisionInfo):

from1To2

from1To2

Type: Vector

constructor

Constructor of a Rectangle object

constructor(mass: number, center: Vector, width: number, height: number, angle: number, friction: number, restitution: number, gravity: boolean, info: string)
Parameters
mass (number) Mass of a Rectangle object
center (Vector) Mass center of a Rectangle object
width (number) Width of a Rectangle object
height (number) Height of a Rectangle object
angle (number = 0) Angle in radians of a Rectangle object axis to global (canvas) x-axis
friction (number = 0) Rectangle friction
restitution (number = 0) Rectangle restitution (bounciness) (how much energy is preserved after collision)
gravity (boolean = true) consider the Rectangle when applying gravity
info (string = "") additional info

vertex

Array to store vertex positions of the rectangle

vertex

Type: Array<Vector>

faceNormal

Array to store the face normal vectors

faceNormal

Type: Array<Vector>

computeVertex

Compute Rectangle vertices

computeVertex()

computeFaceNormal

Compute face normal vectors

computeFaceNormal()

rotate

Rotate Rectangle

rotate(angle: number)
Parameters
angle (number) Angle in radians

updateInertia

Set and update inertia

updateInertia()

collisionTest

collisionTest(otherShape: any, collisionInfo: any): boolean
Parameters
otherShape (any)
collisionInfo (any)
Returns
boolean:

findSupportPoint

Compute a support point based on dir (find a support point for any face normal)

findSupportPoint(dir: Vector, ptOnEdge: Vector): {supportPoint: Vector, supportPointDist: number}
Parameters
dir (Vector) Negated face normal direction
ptOnEdge (Vector) A position on the given edge (e.g. a vertex)
Returns
{supportPoint: Vector, supportPointDist: number}:

findAxisLeastPenetration

Find the axis of the least penetration based on the support point with the least support point distant

findAxisLeastPenetration(otherRect: Rectangle, collisionInfo: any): boolean
Parameters
otherRect (Rectangle) other Rectangle with which collision occurs
collisionInfo (any) collision info
Returns
boolean: hasSupport

collidedRectRect

Compute the axis of lest penetration and choose smaller of the two results

collidedRectRect(r1: Rectangle, r2: Rectangle, collisionInfo: CollisionInfo): boolean
Parameters
r1 (Rectangle) Rectangle that called the method
r2 (Rectangle) Rectangle with which collision occurs
collisionInfo (CollisionInfo) collision info
Returns
boolean:

collidedRectCirc

Detect collision according to the relative position of the circle's center with respect to the rectangle

collidedRectCirc(otherCir: Circle, collisionInfo: CollisionInfo)
Parameters
otherCir (Circle) collided Circle
collisionInfo (CollisionInfo) collision info

supportPoint

supportPoint

Type: Vector

supportPoint

supportPoint

Type: Vector

collisionInfoR1

collisionInfoR1

Type: CollisionInfo

collisionInfoR1

collisionInfoR1

Type: CollisionInfo

collisionInfoR2

collisionInfoR2

Type: CollisionInfo

collisionInfoR2

collisionInfoR2

Type: CollisionInfo

radiusVec

radiusVec

Type: Vector

RigidShape

Abstract class that represents a rigid body

new RigidShape()
Instance Members
angularVelocity
update()
move(s)
updateMass(delta)
collisionTest(otherShape, collisionInfo)
boundTest(otherShape)

isGravity

Symplectic Euler Integration

isGravity

constructor

Constructor of a Triangle object

constructor(mass: number, center: Vector, width: number, height: number, angle: number, friction: number, restitution: number, gravity: boolean, info: string)
Parameters
mass (number) Mass of a Triangle object
center (Vector) Mass center of a Triangle object
width (number) Width of a Triangle object
height (number) Height of a Triangle object
angle (number = 0) Angle in radians of a Triangle object axis to global (canvas) x-axis
friction (number = 0) Triangle friction
restitution (number = 0) Triangle restitution (bounciness) (how much energy is preserved after collision)
gravity (boolean = true) consider the Triangle when applying gravity
info (string = "") additional info

vertex

Array to store vertex positions of the triangle

vertex

Type: Array<Vector>

faceNormal

Array to store the face normal vectors

faceNormal

Type: Array<Vector>

computeVertex

Compute Rectangle vertices

computeVertex()

computeFaceNormal

Compute face normal vectors

computeFaceNormal()

rotate

Rotate Rectangle

rotate(angle: number)
Parameters
angle (number) Angle in radians

updateInertia

Set and update inertia

updateInertia()

collisionTest

Check if collision occurred, call specified methods to handle collision

collisionTest(otherShape: any, collisionInfo: any): boolean
Parameters
otherShape (any) other shape in the collision event
collisionInfo (any) collision info
Returns
boolean: did the collision occur

findSupportPoint

Compute a support point based on dir (find a support point for any face normal)

findSupportPoint(dir: Vector, ptOnEdge: Vector): {supportPoint: Vector, supportPointDist: number}
Parameters
dir (Vector) Negated face normal direction
ptOnEdge (Vector) A position on the given edge (e.g. a vertex)
Returns
{supportPoint: Vector, supportPointDist: number}:

findAxisLeastPenetration

Find the axis of the least penetration based on the support point with the least support point distance

findAxisLeastPenetration(otherShape: (Rectangle | Triangle), collisionInfo: any): boolean
Parameters
otherShape ((Rectangle | Triangle)) other Rectangle or Triangle with which collision occurs
collisionInfo (any) collision info
Returns
boolean: hasSupport

collidedTrianTrianRect

Compute the axis of lest penetration and choose smaller of the two results

collidedTrianTrianRect(r1: Triangle, r2: (Triangle | Rectangle), collisionInfo: CollisionInfo): boolean
Parameters
r1 (Triangle) Triangle that called the method
r2 ((Triangle | Rectangle)) Triangle or Rectangle with which collision occurs
collisionInfo (CollisionInfo) collision info
Returns
boolean:

collidedTrianCirc

Detect collision according to the relative position of the circle's center with respect to the triangle

collidedTrianCirc(otherCirc: any, collisionInfo: any): boolean
Parameters
otherCirc (any) collided Circle
collisionInfo (any) collision info
Returns
boolean:

normal

normal

Type: Vector