Class: Vec3

og/math/Vec3.Vec3

Class represents a 3d vector.

new module:og/math/Vec3.Vec3(x, y, z)

Name Type Description
x number optional First value.
y number optional Second value.
z number optional Third value.

Members

xnumber

ynumber

znumber

static,constantmodule:og/math/Vec3.Vec3.BACKWARD

static,constantmodule:og/math/Vec3.Vec3.DOWN

static,constantmodule:og/math/Vec3.Vec3.FORWARD

static,constantmodule:og/math/Vec3.Vec3.LEFT

static,constantmodule:og/math/Vec3.Vec3.RIGHT

static,constantmodule:og/math/Vec3.Vec3.UNIT_X

static,constantmodule:og/math/Vec3.Vec3.UNIT_Y

static,constantmodule:og/math/Vec3.Vec3.UNIT_Z

static,constantmodule:og/math/Vec3.Vec3.UP

static,constantmodule:og/math/Vec3.Vec3.ZERO

Methods

add(point3){Vec3}

Gets two vectors summarization.
Name Type Description
point3 Vec3 Vector to add.
Returns:
Type Description
Vec3 Returns a sum vector.

addA(point3){Vec3}

Adds vector to the current.
Name Type Description
point3 Vec3 Point to add.
Returns:
Type Description
Vec3 -

angle(a){number}

Gets angle between two vectors.
Name Type Description
a Vec3 Another vector.
Returns:
Type Description
number -

clear(){Vec3}

Sets vector to zero.
Returns:
Type Description
Vec3 -

clone(){Vec3}

Returns clone vector.
Returns:
Type Description
Vec3 -

copy(point3){Vec3}

Copy input vector's values.
Name Type Description
point3 Vec3 Vector to copy.
Returns:
Type Description
Vec3 -

cross(point3){Vec3}

Gets vectors cross production.
Name Type Description
point3 Vec3 Another vector.
Returns:
Type Description
Vec3 -

distance(point3){number}

Gets distance to point.
Name Type Description
point3 Vec3 Distant point.
Returns:
Type Description
number -

distance2(point3){number}

Gets square distance to point.
Name Type Description
point3 Vec3 Distant point.
Returns:
Type Description
number -

div(vec){Vec3}

Divide current vector's components to another and returns new vector instance.
Name Type Description
vec Vec3 Div vector.
Returns:
Type Description
Vec3 -

divA(vec){Vec3}

Divide current vector's components to another. Results stores in the current vector object.
Name Type Description
vec Vec3 Div vector.
Returns:
Type Description
Vec3 -

dot(point3){number}

Gets vectors dot production.
Name Type Description
point3 Vec3 Another vector.
Returns:
Type Description
number -

dotArr(arr){number}

Gets vectors dot production.
Name Type Description
arr Array.<number> Array vector. (exactly 3 entries)
Returns:
Type Description
number -

equal(p){boolean}

Compares with vector. Returns true if it equals another.
Name Type Description
p Vec3 Vector to compare.
Returns:
Type Description
boolean -

getNormal(){Vec3}

Returns normalized vector.
Returns:
Type Description
Vec3 -
Converts vector's values to a quaternion object.
Returns:
Type Description
Quat -

getRotationTo(dest, fallbackAxis){Quat}

Gets the shortest arc quaternion to rotate this vector to the destination vector.
Name Type Description
dest Vec3 -
fallbackAxis Vec3 -
Returns:
Type Description
Quat -

isZero(){boolean}

Returns true if vector's values are zero.
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){Vec3}

Returns two vectors linear interpolation.
Name Type Description
v2 Vec3 End vector.
l number Interpolate value.
Returns:
Type Description
Vec3 -

mul(vec){Vec3}

Multiply current vector object to another and returns new vector instance.
Name Type Description
vec Vec3 Multiply vector.
Returns:
Type Description
Vec3 -

mulA(vec){Vec3}

Multiply current vector object to another and store result in the current instance.
Name Type Description
vec Vec3 Multiply vector.
Returns:
Type Description
Vec3 -

negate(){Vec3}

Negate current vector.
Returns:
Type Description
Vec3 -

negateTo(){Vec3}

Negate current vector to another instance.
Returns:
Type Description
Vec3 -

normal(){Vec3}

Returns normalized vector.
Deprecated
  • Yes
Returns:
Type Description
Vec3 -

normalize(){Vec3}

Normalize current vector.
Returns:
Type Description
Vec3 -

normalNegate(){Vec3}

Returns normalized negate vector.
Returns:
Type Description
Vec3 -

normalNegateScale(){Vec3}

Returns normalized negate scale vector.
Returns:
Type Description
Vec3 -

normalScale(){Vec3}

Returns normalized scale vector.
Returns:
Type Description
Vec3 -

projToRay(pos, direction){Vec3}

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

scale(scale){Vec3}

Scale current vector.
Name Type Description
scale number Scale value.
Returns:
Type Description
Vec3 -

scaleTo(scale){Vec3}

Scale current vector to another instance.
Name Type Description
scale number Scale value.
Returns:
Type Description
Vec3 -

set(x, y, z){Vec3}

Sets vector's values.
Name Type Description
x number Value X.
y number Value Y.
z number Value Z.
Returns:
Type Description
Vec3 -

slerp(v2, t){Vec3}

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 Vec3 -
t number The parameter t is clamped to the range [0, 1].
Returns:
Type Description
Vec3 -

smerp(v2, t){Vec3}

Returns vector interpolation by v(t) = v1 * t + v2 * (1 - t)
Name Type Description
v2 Vec3 End vector.
t number Interpolate value.
Returns:
Type Description
Vec3 -

sub(point3){Vec3}

Gets vector subtraction.
Name Type Description
point3 Vec3 Subtract vector.
Returns:
Type Description
Vec3 Returns new instance of a subtraction

subA(point3){Vec3}

Subtract vector from the current.
Name Type Description
point3 Vec3 Subtract vector.
Returns:
Type Description
Vec3 -

toArray(){Array.<number>}

Converts vector to a number array.
Returns:
Type Description
Array.<number> - (exactly 3 entries)

toString(){string}

Converts vector to text string.
Returns:
Type Description
string -

toVec(){Array.<number>}

Converts vector to a number array.
Deprecated
  • Yes
Returns:
Type Description
Array.<number> - (exactly 3 entries)

toVec4(){Vec4}

Converts to 4d vector, Fourth value is 1.0.
Returns:
Type Description
Vec4 -

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

Returns summary vector.
Name Type Description
a Vec3 First vector.
b Vec3 Second vector.
Returns:
Type Description
Vec3 - Summary vector.

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

Gets angle between two vectors.
Name Type Description
a Vec3 First vector.
b Vec3 Second vector.
Returns:
Type Description
number -

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

Returns vector components division product one to another.
Name Type Description
a Vec3 First vector.
b Vec3 Second vector.
Returns:
Type Description
Vec3 -

staticmodule:og/math/Vec3.Vec3.doubleToTwoFloat32Array(value, high, low){Array.<number>}

Separate 63 bit Vec3 to two Vec3 32 bit float values.
Name Type Description
value number Double type value.
high Float32Array Out vector high values.
low Float32Array Out vector low values.
Returns:
Type Description
Array.<number> Encoded array. (exactly 2 entries)

staticmodule:og/math/Vec3.Vec3.doubleToTwoFloats(value, high, low){Array.<number>}

Separate 63 bit Vec3 to two Vec3 32 bit float values.
Name Type Description
value number Double type value.
high Vec3 Out vector high values.
low Vec3 Out vector low values.
Returns:
Type Description
Array.<number> Encoded array. (exactly 2 entries)

staticmodule:og/math/Vec3.Vec3.fromVec(arr){Vec3}

Creates 3d vector from array.
Name Type Description
arr Array.<number> Input array (exactly 3 entries)
Returns:
Type Description
Vec3 -

staticmodule:og/math/Vec3.Vec3.lerp(v1, v2, l){Vec3}

Returns two vectors linear interpolation.
Name Type Description
v1 Vec3 Start vector.
v2 Vec3 End vector.
l number Interpolate value.
Returns:
Type Description
Vec3 -

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

Returns two vectors production.
Name Type Description
a Vec3 First vector.
b Vec3 Second vector.
Returns:
Type Description
Vec3 -

staticmodule:og/math/Vec3.Vec3.noncollinear(a, b){Vec3}

Returns true if two vectors are non collinear.
Name Type Description
a Vec3 First vector.
b Vec3 Second vector.
Returns:
Type Description
Vec3 -

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

Makes vectors normalized and orthogonal to each other. Normalizes normal. Normalizes tangent and makes sure it is orthogonal to normal (that is, angle between them is 90 degrees).
Name Type Description
normal Vec3 Normal vector.
tangent Vec3 Tangent vector.
Returns:
Type Description
Vec3 -

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

Get projection of the first vector to the second.
Name Type Description
b Vec3 First vector.
a Vec3 Second vector.
Returns:
Type Description
Vec3 -

staticmodule:og/math/Vec3.Vec3.proj_b_to_plane(b, n, def){Vec3}

Get projection of the vector to plane where n - normal to the plane.
Name Type Description
b Vec3 Vector to project.
n Vec3 Plane normal.
def Vec3 optional Default value for non existed result.
Returns:
Type Description
Vec3 -

staticmodule:og/math/Vec3.Vec3.projToVec(a){Vec3}

Get projection of the first vector to the second.
Name Type Description
a Vec3 Project vector.
Returns:
Type Description
Vec3 -

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

Returns scaled vector.
Name Type Description
a Vec3 Input vector.
scale number Scale value.
Returns:
Type Description
Vec3 -

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

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