Class: Vec2

og/math/Vec2~Vec2

new Vec2(x, y)

Class represents a 3d vector.
Name Type Description
x number optional First value.
y number optional Second value.

Members

xnumber

ynumber

static,constantmodule:og/math/Vec2~Vec2.DOWN

static,constantmodule:og/math/Vec2~Vec2.LEFT

static,constantmodule:og/math/Vec2~Vec2.RIGHT

static,constantmodule:og/math/Vec2~Vec2.UP

static,constantmodule:og/math/Vec2~Vec2.ZERO

Methods

add(v){og.math.Vec2}

Summarize two vectors.
Name Type Description
v og.math.Vec2
Returns:
Type Description
og.math.Vec2

addA(v){og.math.Vec2}

Adds vector to the current.
Name Type Description
v og.math.Vec2
Returns:
Type Description
og.math.Vec2

angle(a){number}

Gets angle between two vectors.
Name Type Description
a og.math.Vec2 Another vector.
Returns:
Type Description
number

clear(){og.math.Vec2}

Sets vector to zero.
Returns:
Type Description
og.math.Vec2

clone(){og.math.Vec2}

Returns clone vector.
Returns:
Type Description
og.math.Vec2

copy(point2){og.math.Vec2}

Copy input vector's values.
Name Type Description
point2 og.math.Vec2 Vector to copy.
Returns:
Type Description
og.math.Vec2

cross(v){og.math.Vec2}

Gets vectors cross production.
Name Type Description
v og.math.Vec2 Another vector.
Returns:
Type Description
og.math.Vec2

distance(p){number}

Gets distance to point.
Name Type Description
p og.math.Vec2 Distant point.
Returns:
Type Description
number

divA(vec){og.math.Vec2}

Divide current vector's components to another. Results stores in the current vector object.
Name Type Description
vec og.math.Vec2
Returns:
Type Description
og.math.Vec2

dot(v){number}

Gets vectors dot production.
Name Type Description
v og.math.Vec2 Another vector.
Returns:
Type Description
number

dotArr(arr){number}

Gets vectors dot production.
Name Type Description
arr Array.<number, number> Array vector.
Returns:
Type Description
number

equal(p){boolean}

Compares with vector. Returns true if it equals another.
Name Type Description
p og.math.Vec2 Vector to compare.
Returns:
Type Description
boolean

length(){number}

Gets vector's length.
Returns:
Type Description
number

length2(){number}

Returns squared vector's length.
Returns:
Type Description
number

lerp(v2, l){og.math.Vec2}

Returns two vectors linear interpolation.
Name Type Description
v2 og.math.Vec2 End vector.
l number Interpolate value.
Returns:
Type Description
og.math.Vec2

mul(vec){og.math.Vec2}

Multiply current vector object to another and returns new vector instance.
Name Type Description
vec og.math.Vec2 Multiply vector.
Returns:
Type Description
og.math.Vec2

mulA(vec){og.math.Vec2}

Multiply current vector object to another and store result in the current instance.
Name Type Description
vec og.math.Vec2 Multiply vector.
Returns:
Type Description
og.math.Vec2

negate(){og.math.Vec2}

Negate current vector.
Returns:
Type Description
og.math.Vec2

negateTo(){og.math.Vec2}

Negate current vector to another instance.
Returns:
Type Description
og.math.Vec2

normal(){og.math.Vec2}

Returns normalized vector.
Returns:
Type Description
og.math.Vec2

normalize(){og.math.Vec2}

Normalize current vector.
Returns:
Type Description
og.math.Vec2

projToRay(pos, direction){og.math.Vec2}

Gets projected point coordinates of the current vector on the ray.
Name Type Description
pos og.math.Vec2 Ray position.
direction og.math.Vec2 Ray direction.
Returns:
Type Description
og.math.Vec2

scale(scale){og.math.Vec2}

Scale current vector.
Name Type Description
scale number Scale value.
Returns:
Type Description
og.math.Vec2

scaleTo(scale){og.math.Vec2}

Scale current vector to another instance.
Name Type Description
scale number Scale value.
Returns:
Type Description
og.math.Vec2

set(x, y){og.math.Vec2}

Sets vector's values.
Name Type Description
x number Value X.
y number Value Y.
Returns:
Type Description
og.math.Vec2

slerp(v2, t){og.math.Vec2}

Spherically interpolates between two vectors. Interpolates between current and v2 vector by amount t. The difference between this and linear interpolation (aka, "lerp") is that the vectors are treated as directions rather than points in space. The direction of the returned vector is interpolated by the angle and its magnitude is interpolated between the magnitudes of from and to.
Name Type Description
v2 og.math.Vec2 -
t number The parameter t is clamped to the range [0, 1].
Returns:
Type Description
og.math.Vec2

sub(v){og.math.Vec2}

Subtract vector from the current.
Name Type Description
v og.math.Vec2 Subtract vector.
Returns:
Type Description
og.math.Vec2

subA(v){og.math.Vec2}

Subtract vector from the current where results saved on the current instance.
Name Type Description
v og.math.Vec2 Subtract vector.
Returns:
Type Description
og.math.Vec2

toVec(){Array.<number, number>}

Converts vector to a number array.
Returns:
Type Description
Array.<number, number>

toVector3(){og.Vec3}

Converts to 3d vector, third value is 0.0.
Returns:
Type Description
og.Vec3

staticmodule:og/math/Vec2~Vec2.add(a, b){og.math.Vec2}

Returns summary vector.
Name Type Description
a og.math.Vec2 First vector.
b og.math.Vec2 Second vector.
Returns:
Type Description
og.math.Vec2 - Summary vector.

staticmodule:og/math/Vec2~Vec2.angle(a, b){number}

Gets angle between two vectors.
Name Type Description
a og.math.Vec2 First vector.
b og.math.Vec2 Second vector.
Returns:
Type Description
number

staticmodule:og/math/Vec2~Vec2.div(a, b){og.math.Vec2}

Returns vector components division product one to another.
Name Type Description
a og.math.Vec2 First vector.
b og.math.Vec2 Second vector.
Returns:
Type Description
og.math.Vec2

staticmodule:og/math/Vec2~Vec2.mul(a, b){og.math.Vec2}

Returns two vectors production.
Name Type Description
a og.math.Vec2 First vector.
b og.math.Vec2 Second vector.
Returns:
Type Description
og.math.Vec2

staticmodule:og/math/Vec2~Vec2.orthoNormalize(normal, tangent){og.math.Vec2}

Makes vectors normalized and orthogonal to each other.
Name Type Description
normal og.math.Vec2 Normal vector.
tangent og.math.Vec2 Tangent vector.
Returns:
Type Description
og.math.Vec2

staticmodule:og/math/Vec2~Vec2.proj_b_to_a(b, a){og.math.Vec2}

Get projection of the first vector to the second.
Name Type Description
b og.math.Vec2 First vector.
a og.math.Vec2 Second vector.
Returns:
Type Description
og.math.Vec2

staticmodule:og/math/Vec2~Vec2.scale(a, scale){og.math.Vec2}

Returns scaled vector.
Name Type Description
a og.math.Vec2 Input vector.
scale number Scale value.
Returns:
Type Description
og.math.Vec2

staticmodule:og/math/Vec2~Vec2.sub(a, b){og.math.Vec2}

Returns two vectors subtraction.
Name Type Description
a og.math.Vec2 First vector.
b og.math.Vec2 Second vector.
Returns:
Type Description
og.math.Vec2 - Vectors subtraction.