Shaku

Shaku JS

Back To Table of Content

Vector3

Vector3

A Vector object for 3d positions.

Kind: global class

new Vector3(x, y, z)

Create the Vector object.

Param Type Default Description
x number 0 Vector X.
y number 0 Vector Y.
z number 0 Vector Z.

vector3.clone() ⇒ Vector3

Clone the vector.

Kind: instance method of Vector3
Returns: Vector3 - cloned vector.

vector3.set(x, y, z) ⇒ Vector3

Set vector value.

Kind: instance method of Vector3
Returns: Vector3 - this.

Param Type Description
x Number X component.
y Number Y component.
z Number Z component.

vector3.copy() ⇒ Vector3

Copy values from other vector into self.

Kind: instance method of Vector3
Returns: Vector3 - this.

vector3.add(Other) ⇒ Vector3

Return a new vector of this + other.

Kind: instance method of Vector3
Returns: Vector3 - result vector.

Param Type Description
Other Number | Vector3 Vector3 or number to add to all components.

vector3.sub(Other) ⇒ Vector3

Return a new vector of this - other.

Kind: instance method of Vector3
Returns: Vector3 - result vector.

Param Type Description
Other Number | Vector3 Vector3 or number to sub from all components.

vector3.div(Other) ⇒ Vector3

Return a new vector of this / other.

Kind: instance method of Vector3
Returns: Vector3 - result vector.

Param Type Description
Other Number | Vector3 Vector3 or number to divide by all components.

vector3.mul(Other) ⇒ Vector3

Return a new vector of this * other.

Kind: instance method of Vector3
Returns: Vector3 - result vector.

Param Type Description
Other Number | Vector3 Vector3 or number to multiply with all components.

vector3.round() ⇒ Vector3

Return a round copy of this vector.

Kind: instance method of Vector3
Returns: Vector3 - result vector.

vector3.floor() ⇒ Vector3

Return a floored copy of this vector.

Kind: instance method of Vector3
Returns: Vector3 - result vector.

vector3.ceil() ⇒ Vector3

Return a ceiled copy of this vector.

Kind: instance method of Vector3
Returns: Vector3 - result vector.

vector3.normalized() ⇒ Vector3

Return a normalized copy of this vector.

Kind: instance method of Vector3
Returns: Vector3 - result vector.

vector3.addSelf(Other) ⇒ Vector3

Add other vector values to self.

Kind: instance method of Vector3
Returns: Vector3 - this.

Param Type Description
Other Number | Vector3 Vector or number to add.

vector3.subSelf(Other) ⇒ Vector3

Sub other vector values from self.

Kind: instance method of Vector3
Returns: Vector3 - this.

Param Type Description
Other Number | Vector3 Vector or number to substract.

vector3.divSelf(Other) ⇒ Vector3

Divide this vector by other vector values.

Kind: instance method of Vector3
Returns: Vector3 - this.

Param Type Description
Other Number | Vector3 Vector or number to divide by.

vector3.mulSelf(Other) ⇒ Vector3

Multiply this vector by other vector values.

Kind: instance method of Vector3
Returns: Vector3 - this.

Param Type Description
Other Number | Vector3 Vector or number to multiply by.

vector3.roundSelf() ⇒ Vector3

Round self.

Kind: instance method of Vector3
Returns: Vector3 - this.

vector3.floorSelf() ⇒ Vector3

Floor self.

Kind: instance method of Vector3
Returns: Vector3 - this.

vector3.ceilSelf() ⇒ Vector3

Ceil self.

Kind: instance method of Vector3
Returns: Vector3 - this.

vector3.normalizeSelf() ⇒ Vector3

Return a normalized copy of this vector.

Kind: instance method of Vector3
Returns: Vector3 - this.

vector3.equals(other) ⇒ Boolean

Return if vector equals another vector.

Kind: instance method of Vector3
Returns: Boolean - if vectors are equal.

Param Type Description
other Vector3 Other vector to compare to.

vector3.approximate(other, threshold) ⇒ Boolean

Return if vector approximately equals another vector.

Kind: instance method of Vector3
Returns: Boolean - if vectors are equal.

Param Type Description
other Vector3 Other vector to compare to.
threshold Number Distance threshold to consider as equal. Defaults to 1.

vector3.length() ⇒ Number

Return vector length (aka magnitude).

Kind: instance method of Vector3
Returns: Number - Vector length.

vector3.scaled() ⇒ Vector3

Return a copy of this vector multiplied by a factor.

Kind: instance method of Vector3
Returns: Vector3 - result vector.

vector3.distanceTo(other) ⇒ Number

Calculate distance between this vector and another vector.

Kind: instance method of Vector3
Returns: Number - Distance between vectors.

Param Type Description
other Vector3 Other vector.

vector3.distanceToSquared(other) ⇒ Number

Calculate squared distance between this vector and another vector.

Kind: instance method of Vector3
Returns: Number - Distance between vectors.

Param Type Description
other Vector3 Other vector.

vector3.clamp(min, max) ⇒ Vector3

Return a clone and clamp its values to be between min and max.

Kind: instance method of Vector3
Returns: Vector3 - Clamped vector.

Param Type Description
min Vector3 Min vector.
max Vector3 Max vector.

vector3.clampSelf(min, max) ⇒ Vector3

Clamp this vector values to be between min and max.

Kind: instance method of Vector3
Returns: Vector3 - Self.

Param Type Description
min Vector3 Min vector.
max Vector3 Max vector.

vector3.dot(other) ⇒ Number

Calculate the dot product with another vector.

Kind: instance method of Vector3
Returns: Number - Dot product value.

Param Type Description
other Vector3 Vector to calculate dot with.

vector3.minSelf(v) ⇒ Vector3

Set self values to be min values between self and a given vector.

Kind: instance method of Vector3
Returns: Vector3 - Self.

Param Type Description
v Vector3 Vector to min with.

vector3.maxSelf(v) ⇒ Vector3

Set self values to be max values between self and a given vector.

Kind: instance method of Vector3
Returns: Vector3 - Self.

Param Type Description
v Vector3 Vector to max with.

vector3.min(v) ⇒ Vector3

Create a clone vector that is the min result between self and a given vector.

Kind: instance method of Vector3
Returns: Vector3 - Result vector.

Param Type Description
v Vector3 Vector to min with.

vector3.max(v) ⇒ Vector3

Create a clone vector that is the max result between self and a given vector.

Kind: instance method of Vector3
Returns: Vector3 - Result vector.

Param Type Description
v Vector3 Vector to max with.

vector3.string()

Convert to string.

Kind: instance method of Vector3

vector3.toArray() ⇒ Array.<Number>

Convert to array of numbers.

Kind: instance method of Vector3
Returns: Array.<Number> - Vector components as array.

vector3.toDict(minimized) ⇒ \*

Convert to dictionary.

Kind: instance method of Vector3
Returns: \* - Dictionary with {x,y,z}

Param Type Description
minimized Boolean If true, will not include keys that their values are 0. You can use fromDict on minimized dicts.

Vector3.zeroReadonly

Vector with 0,0,0 values as a frozen shared object. Be careful not to try and change it.

Kind: static property of Vector3

Vector3.oneReadonly

Vector with 1,1,1 values as a frozen shared object. Be careful not to try and change it.

Kind: static property of Vector3

Vector3.halfReadonly

Vector with 0.5,0.5,0.5 values as a frozen shared object. Be careful not to try and change it.

Kind: static property of Vector3

Vector3.leftReadonly

Vector with -1,0,0 values as a frozen shared object. Be careful not to try and change it.

Kind: static property of Vector3

Vector3.rightReadonly

Vector with 1,0,0 values as a frozen shared object. Be careful not to try and change it.

Kind: static property of Vector3

Vector3.upReadonly

Vector with 0,-1,0 values as a frozen shared object. Be careful not to try and change it.

Kind: static property of Vector3

Vector3.downReadonly

Vector with 0,1,0 values as a frozen shared object. Be careful not to try and change it.

Kind: static property of Vector3

Vector3.frontReadonly

Vector with 0,0,1 values as a frozen shared object. Be careful not to try and change it.

Kind: static property of Vector3

Vector3.backReadonly

Vector with 0,0,-1 values as a frozen shared object. Be careful not to try and change it.

Kind: static property of Vector3

Vector3.zero() ⇒ Vector3

Get vector with 0,0,0 values.

Kind: static method of Vector3
Returns: Vector3 - result vector.

Vector3.one() ⇒ Vector3

Get vector with 1,1,1 values.

Kind: static method of Vector3
Returns: Vector3 - result vector.

Vector3.half() ⇒ Vector3

Get vector with 0.5,0.5 values.

Kind: static method of Vector3
Returns: Vector3 - result vector.

Vector3.left() ⇒ Vector3

Get vector with -1,0,0 values.

Kind: static method of Vector3
Returns: Vector3 - result vector.

Vector3.right() ⇒ Vector3

Get vector with 1,0,0 values.

Kind: static method of Vector3
Returns: Vector3 - result vector.

Vector3.up() ⇒ Vector3

Get vector with 0,-1,0 values.

Kind: static method of Vector3
Returns: Vector3 - result vector.

Vector3.down() ⇒ Vector3

Get vector with 0,1,0 values.

Kind: static method of Vector3
Returns: Vector3 - result vector.

Vector3.front() ⇒ Vector3

Get vector with 0,0,1 values.

Kind: static method of Vector3
Returns: Vector3 - result vector.

Vector3.back() ⇒ Vector3

Get vector with 0,0,-1 values.

Kind: static method of Vector3
Returns: Vector3 - result vector.

Vector3.lerp(p1, p2, a) ⇒ Vector3

Lerp between two vectors.

Kind: static method of Vector3
Returns: Vector3 - result vector.

Param Type Description
p1 Vector3 First vector.
p2 Vector3 Second vector.
a Number Lerp factor (0.0 - 1.0).

Vector3.distance(p1, p2) ⇒ Number

Calculate distance between two vectors.

Kind: static method of Vector3
Returns: Number - Distance between vectors.

Param Type Description
p1 Vector3 First vector.
p2 Vector3 Second vector.

Vector3.crossVector(p1, p2) ⇒ Vector3

Return cross product between two vectors.

Kind: static method of Vector3
Returns: Vector3 - Crossed vector.

Param Type Description
p1 Vector3 First vector.
p2 Vector3 Second vector.

Vector3.parse(str) ⇒ Vector3

Parse and return a vector object from string in the form of “x,y”.

Kind: static method of Vector3
Returns: Vector3 - Parsed vector.

Param Type Description
str String String to parse.

Vector3.fromArray(arr) ⇒ Vector3

Create vector from array of numbers.

Kind: static method of Vector3
Returns: Vector3 - Vector instance.

Param Type Description
arr Array.<Number> Array of numbers to create vector from.

Vector3.fromDict(data) ⇒ Vector3

Create vector from a dictionary.

Kind: static method of Vector3
Returns: Vector3 - Newly created vector.

Param Type Description
data \* Dictionary with {x,y,z}.