Class Vector4
Implements
Index
Constructors
Properties
Accessors
Methods
Constructors
constructor
-
Creates a Vector4 object from the given floats.
Parameters
- x: number = 0
x value of the vector
- y: number = 0
y value of the vector
- z: number = 0
z value of the vector
- w: number = 0
w value of the vector
Returns Vector4
- x: number = 0
Properties
Readonlydimension
Readonlyrank
Static_ V8 Performance Hack
If the first vector is flagged with integers (as everything is 0,0,0,0), V8 stores all of the properties as integers internally because it doesn't know any better yet. If subsequent vectors are created with non-integer values, V8 determines that it would be best to represent these properties as doubles instead of integers, and henceforth it will use floating-point representation for all Vector4 instances that it creates. But the original Vector4 instances are unchanged and has a "deprecated map". If we keep using the Vector4 instances from step 1, it will now be a poison pill which will mess up optimizations in any code it touches.
Accessors
w
-
get w(): number
Gets or sets the w coordinate
Returns number
-
set w(value: number): void
Parameters
- value: number
Returns void
x
-
get x(): number
Gets or sets the x coordinate
Returns number
-
set x(value: number): void
Parameters
- value: number
Returns void
y
-
get y(): number
Gets or sets the y coordinate
Returns number
-
set y(value: number): void
Parameters
- value: number
Returns void
z
-
get z(): number
Gets or sets the z coordinate
Returns number
-
set z(value: number): void
Parameters
- value: number
Returns void
StaticZero Read Only
-
Gets a zero Vector4 that must not be updated
Returns DeepImmutable<Vector4>
Methods
add
-
Returns a new Vector4 as the result of the addition of the current Vector4 and the given one.
Parameters
- otherVector: DeepImmutable<IVector4Like>
the vector to add
Returns Vector4
the resulting vector
- otherVector: DeepImmutable<IVector4Like>
add In Place
-
Adds the given vector to the current Vector4.
Parameters
- otherVector: DeepImmutable<Vector4>
the vector to add
Returns this
the updated Vector4.
- otherVector: DeepImmutable<Vector4>
add In Place From Floats
-
Adds the given coordinates to the current Vector4
Parameters
- x: number
defines the x coordinate of the operand
- y: number
defines the y coordinate of the operand
- z: number
defines the z coordinate of the operand
- w: number
defines the w coordinate of the operand
Returns this
the current updated Vector4
- x: number
add To Ref
-
Updates the given vector "result" with the result of the addition of the current Vector4 and the given one.
Type Parameters
- T extends IVector4Like
Parameters
- otherVector: DeepImmutable<IVector4Like>
the vector to add
- result: T
the vector to store the result
Returns T
result input
as Array
-
Returns a new array populated with 4 elements : the Vector4 coordinates.
Returns [number, number, number, number]
the resulting array
clone
copy From
-
Updates the current Vector4 with the given one coordinates.
Parameters
- source: DeepImmutable<IVector4Like>
the source vector to copy from
Returns this
the updated Vector4.
- source: DeepImmutable<IVector4Like>
copy From Floats
-
Updates the current Vector4 coordinates with the given floats.
Parameters
- x: number
float to copy from
- y: number
float to copy from
- z: number
float to copy from
- w: number
float to copy from
Returns this
the updated Vector4.
- x: number
divide
-
Returns a new Vector4 set with the division result of the current Vector4 by the given one.
Parameters
- otherVector: DeepImmutable<IVector4Like>
vector to devide with
Returns Vector4
resulting new vector
- otherVector: DeepImmutable<IVector4Like>
divide In Place
-
Divides the current Vector3 coordinates by the given ones.
Parameters
- otherVector: DeepImmutable<IVector4Like>
vector to devide with
Returns this
the updated Vector3.
- otherVector: DeepImmutable<IVector4Like>
divide To Ref
-
Updates the given vector "result" with the division result of the current Vector4 by the given one.
Type Parameters
- T extends IVector4Like
Parameters
- otherVector: DeepImmutable<IVector4Like>
vector to devide with
- result: T
vector to store the result
Returns T
result input
dot
-
Returns the dot product (float) between the current vectors and "otherVector"
Parameters
- otherVector: DeepImmutable<IVector4Like>
defines the right operand
Returns number
the dot product
- otherVector: DeepImmutable<IVector4Like>
equals
-
Boolean : True if the current Vector4 coordinates are stricly equal to the given ones.
Parameters
- otherVector: DeepImmutable<IVector4Like>
the vector to compare against
Returns boolean
true if they are equal
- otherVector: DeepImmutable<IVector4Like>
equals To Floats
-
Boolean : True if the given floats are strictly equal to the current Vector4 coordinates.
Parameters
- x: number
x value to compare against
- y: number
y value to compare against
- z: number
z value to compare against
- w: number
w value to compare against
Returns boolean
true if equal
- x: number
equals With Epsilon
-
Boolean : True if the current Vector4 coordinates are each beneath the distance "epsilon" from the given vector ones.
Parameters
- otherVector: DeepImmutable<IVector4Like>
vector to compare against
- epsilon: number = Epsilon
(Default: very small number)
Returns boolean
true if they are equal
- otherVector: DeepImmutable<IVector4Like>
floor
floor To Ref
fract
fract To Ref
from Array
-
Update the current vector from an array
Parameters
- array: FloatArray
defines the destination array
- offset: number = 0
defines the offset in the destination array
Returns this
the current Vector3
- array: FloatArray
get Class Name
-
Returns the string "Vector4".
Returns string
"Vector4"
get Hash Code
-
Returns the Vector4 hash code.
Returns number
a unique hash code
length
-
Returns the Vector4 length (float).
Returns number
the length
length Squared
-
Returns the Vector4 squared length (float).
Returns number
the length squared
maximize In Place
-
Updates the Vector4 coordinates with the maximum values between its own and the given vector ones
Parameters
- other: DeepImmutable<IVector4Like>
defines the second operand
Returns this
the current updated Vector4
- other: DeepImmutable<IVector4Like>
maximize In Place From Floats
-
Updates the current Vector4 with the maximal coordinate values between its and the given coordinates.
Parameters
- x: number
defines the x coordinate of the operand
- y: number
defines the y coordinate of the operand
- z: number
defines the z coordinate of the operand
- w: number
defines the w coordinate of the operand
Returns this
the current updated Vector4
- x: number
minimize In Place
-
Updates the Vector4 coordinates with the minimum values between its own and the given vector ones
Parameters
- other: DeepImmutable<IVector4Like>
defines the second operand
Returns this
the current updated Vector4
- other: DeepImmutable<IVector4Like>
minimize In Place From Floats
-
Updates the current Vector4 with the minimal coordinate values between its and the given coordinates
Parameters
- x: number
defines the x coordinate of the operand
- y: number
defines the y coordinate of the operand
- z: number
defines the z coordinate of the operand
- w: number
defines the w coordinate of the operand
Returns this
the current updated Vector4
- x: number
multiply
-
Returns a new Vector4 set with the multiplication result of the current Vector4 and the given one.
Parameters
- otherVector: DeepImmutable<IVector4Like>
vector to multiple with
Returns Vector4
resulting new vector
- otherVector: DeepImmutable<IVector4Like>
multiply By Floats
-
Returns a new Vector4 set with the multiplication result of the given floats and the current Vector4 coordinates.
Parameters
- x: number
x value multiply with
- y: number
y value multiply with
- z: number
z value multiply with
- w: number
w value multiply with
Returns Vector4
resulting new vector
- x: number
multiply In Place
-
Multiplies in place the current Vector4 by the given one.
Parameters
- otherVector: DeepImmutable<IVector4Like>
vector to multiple with
Returns this
the updated Vector4.
- otherVector: DeepImmutable<IVector4Like>
multiply To Ref
-
Updates the given vector "result" with the multiplication result of the current Vector4 and the given one.
Type Parameters
- T extends IVector4Like
Parameters
- otherVector: DeepImmutable<IVector4Like>
vector to multiple with
- result: T
vector to store the result
Returns T
result input
negate
-
Returns a new Vector4 set with the current Vector4 negated coordinates.
Returns Vector4
a new vector with the negated values
negate In Place
-
Negate this vector in place
Returns this
this
negate To Ref
normalize
-
Normalizes in place the Vector4.
Returns this
the updated Vector4.
normalize From Length
-
Normalize the current Vector4 with the given input length. Please note that this is an in place operation.
Parameters
- len: number
the length of the vector
Returns this
the current updated Vector4
- len: number
normalize To New
normalize To Ref
scale
-
Returns a new Vector4 set with the current Vector4 coordinates multiplied by scale (float).
Parameters
- scale: number
the number to scale with
Returns Vector4
a new vector with the result
- scale: number
scale And Add To Ref
scale In Place
-
Multiplies the current Vector4 coordinates by scale (float).
Parameters
- scale: number
the number to scale with
Returns this
the updated Vector4.
- scale: number
scale To Ref
set
-
Updates the current Vector4 coordinates with the given floats.
Parameters
- x: number
float to set from
- y: number
float to set from
- z: number
float to set from
- w: number
float to set from
Returns this
the updated Vector4.
- x: number
set All
-
Copies the given float to the current Vector4 coordinates
Parameters
- v: number
defines the x, y, z and w coordinates of the operand
Returns this
the current updated Vector4
- v: number
subtract
-
Returns a new Vector4 with the result of the subtraction of the given vector from the current Vector4.
Parameters
- otherVector: DeepImmutable<IVector4Like>
the vector to add
Returns Vector4
the new vector with the result
- otherVector: DeepImmutable<IVector4Like>
subtract From Floats
-
Returns a new Vector4 set with the result of the subtraction of the given floats from the current Vector4 coordinates.
Parameters
- x: number
value to subtract
- y: number
value to subtract
- z: number
value to subtract
- w: number
value to subtract
Returns Vector4
new vector containing the result
- x: number
subtract From Floats To Ref
-
subtractFromFloatsToRef<T extends IVector4Like>(
x: number,
y: number,
z: number,
w: number,
result: T,
): TSets the given vector "result" set with the result of the subtraction of the given floats from the current Vector4 coordinates.
Type Parameters
- T extends IVector4Like
Parameters
- x: number
value to subtract
- y: number
value to subtract
- z: number
value to subtract
- w: number
value to subtract
- result: T
the vector to store the result in
Returns T
result input
subtract In Place
-
Subtract in place the given vector from the current Vector4.
Parameters
- otherVector: DeepImmutable<IVector4Like>
the vector to subtract
Returns this
the updated Vector4.
- otherVector: DeepImmutable<IVector4Like>
subtract To Ref
-
Sets the given vector "result" with the result of the subtraction of the given vector from the current Vector4.
Type Parameters
- T extends IVector4Like
Parameters
- otherVector: DeepImmutable<IVector4Like>
the vector to subtract
- result: T
the vector to store the result
Returns T
result input
to Array
-
Populates the given array from the given index with the Vector4 coordinates.
Parameters
- array: FloatArray
array to populate
Optionalindex: numberindex of the array to start at (default: 0)
Returns this
the Vector4.
- array: FloatArray
to String
-
Returns the string with the Vector4 coordinates.
Returns string
a string containing all the vector values
to Vector3
-
Returns a new Vector3 from the Vector4 (x, y, z) coordinates.
Returns Vector3
this converted to a new vector3
StaticCenter
-
Returns a new Vector4 located at the center between the vectors "value1" and "value2".
Parameters
- value1: DeepImmutable<IVector4Like>
value to calulate the center between
- value2: DeepImmutable<IVector4Like>
value to calulate the center between
Returns Vector4
the center between the two vectors
- value1: DeepImmutable<IVector4Like>
StaticCenter To Ref
-
CenterToRef<T extends IVector4Like>(
value1: DeepImmutable<IVector4Like>,
value2: DeepImmutable<IVector4Like>,
ref: T,
): TGets the center of the vectors "value1" and "value2" and stores the result in the vector "ref"
Type Parameters
- T extends IVector4Like
Parameters
- value1: DeepImmutable<IVector4Like>
defines first vector
- value2: DeepImmutable<IVector4Like>
defines second vector
- ref: T
defines third vector
Returns T
ref
StaticCheck Extends
-
Checks if a given vector is inside a specific range Example Playground https://playground.babylonjs.com/#R1F8YU#75
Parameters
Returns void
StaticClamp
-
Clamp(
value: DeepImmutable<IVector4Like>,
min: DeepImmutable<IVector4Like>,
max: DeepImmutable<IVector4Like>,
): Vector4Returns a new Vector4 set with the coordinates of "value", if the vector "value" is in the cube defined by the vectors "min" and "max" If a coordinate value of "value" is lower than one of the "min" coordinate, then this "value" coordinate is set with the "min" one If a coordinate value of "value" is greater than one of the "max" coordinate, then this "value" coordinate is set with the "max" one
Parameters
- value: DeepImmutable<IVector4Like>
defines the current value
- min: DeepImmutable<IVector4Like>
defines the lower range value
- max: DeepImmutable<IVector4Like>
defines the upper range value
Returns Vector4
the new Vector4
- value: DeepImmutable<IVector4Like>
StaticClamp To Ref
-
ClampToRef<T extends IVector4Like>(
value: DeepImmutable<IVector4Like>,
min: DeepImmutable<IVector4Like>,
max: DeepImmutable<IVector4Like>,
result: T,
): TSets the given vector "result" with the coordinates of "value", if the vector "value" is in the cube defined by the vectors "min" and "max" If a coordinate value of "value" is lower than one of the "min" coordinate, then this "value" coordinate is set with the "min" one If a coordinate value of "value" is greater than one of the "max" coordinate, then this "value" coordinate is set with the "max" one
Type Parameters
- T extends IVector4Like
Parameters
- value: DeepImmutable<IVector4Like>
defines the current value
- min: DeepImmutable<IVector4Like>
defines the lower range value
- max: DeepImmutable<IVector4Like>
defines the upper range value
- result: T
defines the Vector4 where to store the result
Returns T
result input
StaticDistance
-
Returns the distance (float) between the vectors "value1" and "value2".
Parameters
- value1: DeepImmutable<IVector4Like>
value to calulate the distance between
- value2: DeepImmutable<IVector4Like>
value to calulate the distance between
Returns number
the distance between the two vectors
- value1: DeepImmutable<IVector4Like>
StaticDistance Squared
-
Returns the squared distance (float) between the vectors "value1" and "value2".
Parameters
- value1: DeepImmutable<IVector4Like>
value to calulate the distance between
- value2: DeepImmutable<IVector4Like>
value to calulate the distance between
Returns number
the distance between the two vectors squared
- value1: DeepImmutable<IVector4Like>
StaticDot
-
Returns the dot product (float) between the vectors "left" and "right"
Parameters
- left: DeepImmutable<IVector4Like>
defines the left operand
- right: DeepImmutable<IVector4Like>
defines the right operand
Returns number
the dot product
- left: DeepImmutable<IVector4Like>
StaticFrom Array
-
Returns a new Vector4 set from the starting index of the given array.
Parameters
- array: DeepImmutable<ArrayLike<number>>
the array to pull values from
Optionaloffset: numberthe offset into the array to start at
Returns Vector4
the new vector
- array: DeepImmutable<ArrayLike<number>>
StaticFrom Array To Ref
-
FromArrayToRef<T extends IVector4Like>(
array: DeepImmutable<ArrayLike<number>>,
offset: number,
result: T,
): TUpdates the given vector "result" from the starting index of the given array.
Type Parameters
- T extends IVector4Like
Parameters
- array: DeepImmutable<ArrayLike<number>>
the array to pull values from
- offset: number
the offset into the array to start at
- result: T
the vector to store the result in
Returns T
result input
StaticFrom Float Array To Ref
-
FromFloatArrayToRef<T extends IVector4Like>(
array: DeepImmutable<Float32Array>,
offset: number,
result: T,
): TUpdates the given vector "result" from the starting index of the given Float32Array.
Type Parameters
- T extends IVector4Like
Parameters
- array: DeepImmutable<Float32Array>
the array to pull values from
- offset: number
the offset into the array to start at
- result: T
the vector to store the result in
Returns T
result input
StaticFrom Floats To Ref
StaticFrom Vector3
StaticMaximize
-
Returns a vector with the maximum values from the left and right vectors
Parameters
- left: DeepImmutable<IVector4Like>
left vector to maximize
- right: DeepImmutable<IVector4Like>
right vector to maximize
Returns Vector4
a new vector with the maximum of the left and right vector values
- left: DeepImmutable<IVector4Like>
StaticMinimize
-
Returns a vector with the minimum values from the left and right vectors
Type Parameters
- T extends Vector4
Parameters
- left: DeepImmutable<T>
left vector to minimize
- right: DeepImmutable<Vector4>
right vector to minimize
Returns Vector4
a new vector with the minimum of the left and right vector values
StaticNormalize
-
Returns a new normalized Vector4 from the given one.
Parameters
- vector: DeepImmutable<Vector4>
the vector to normalize
Returns Vector4
the vector
- vector: DeepImmutable<Vector4>
StaticNormalize To Ref
-
Updates the given vector "result" from the normalization of the given one.
Type Parameters
- T extends IVector4Like
Parameters
- vector: DeepImmutable<Vector4>
the vector to normalize
- result: T
the vector to store the result in
Returns T
result input
StaticOne
StaticRandom
-
Returns a new Vector4 with random values between min and max
Parameters
- min: number = 0
the minimum random value
- max: number = 1
the maximum random value
Returns Vector4
a Vector4 with random values between min and max
- min: number = 0
StaticRandom To Ref
StaticTransform Coordinates
-
TransformCoordinates(
vector: DeepImmutable<Vector3>,
transformation: DeepImmutable<Matrix>,
): Vector4Returns a new Vector4 set with the result of the transformation by the given matrix of the given vector. This method computes tranformed coordinates only, not transformed direction vectors (ie. it takes translation in account) The difference with Vector3.TransformCoordinates is that the w component is not used to divide the other coordinates but is returned in the w coordinate instead
Parameters
- vector: DeepImmutable<Vector3>
defines the Vector3 to transform
- transformation: DeepImmutable<Matrix>
defines the transformation matrix
Returns Vector4
the transformed Vector4
- vector: DeepImmutable<Vector3>
StaticTransform Coordinates From Floats To Ref
-
TransformCoordinatesFromFloatsToRef<T extends IVector4Like>(
x: number,
y: number,
z: number,
transformation: DeepImmutable<Matrix>,
result: T,
): TSets the given vector "result" coordinates with the result of the transformation by the given matrix of the given floats (x, y, z) This method computes tranformed coordinates only, not transformed direction vectors The difference with Vector3.TransformCoordinatesFromFloatsToRef is that the w component is not used to divide the other coordinates but is returned in the w coordinate instead
Type Parameters
- T extends IVector4Like
Parameters
- x: number
define the x coordinate of the source vector
- y: number
define the y coordinate of the source vector
- z: number
define the z coordinate of the source vector
- transformation: DeepImmutable<Matrix>
defines the transformation matrix
- result: T
defines the Vector4 where to store the result
Returns T
result input
StaticTransform Coordinates To Ref
-
TransformCoordinatesToRef<T extends IVector4Like>(
vector: DeepImmutable<Vector3>,
transformation: DeepImmutable<Matrix>,
result: T,
): TSets the given vector "result" coordinates with the result of the transformation by the given matrix of the given vector This method computes tranformed coordinates only, not transformed direction vectors (ie. it takes translation in account) The difference with Vector3.TransformCoordinatesToRef is that the w component is not used to divide the other coordinates but is returned in the w coordinate instead
Type Parameters
- T extends IVector4Like
Parameters
- vector: DeepImmutable<Vector3>
defines the Vector3 to transform
- transformation: DeepImmutable<Matrix>
defines the transformation matrix
- result: T
defines the Vector4 where to store the result
Returns T
result input
StaticTransform Normal
-
TransformNormal(
vector: DeepImmutable<IVector4Like>,
transformation: DeepImmutable<Matrix>,
): Vector4Returns a new Vector4 set with the result of the normal transformation by the given matrix of the given vector. This methods computes transformed normalized direction vectors only.
Parameters
- vector: DeepImmutable<IVector4Like>
the vector to transform
- transformation: DeepImmutable<Matrix>
the transformation matrix to apply
Returns Vector4
the new vector
- vector: DeepImmutable<IVector4Like>
StaticTransform Normal From Floats To Ref
-
TransformNormalFromFloatsToRef<T extends IVector4Like>(
x: number,
y: number,
z: number,
w: number,
transformation: DeepImmutable<Matrix>,
result: T,
): TSets the given vector "result" with the result of the normal transformation by the given matrix of the given floats (x, y, z, w). This methods computes transformed normalized direction vectors only.
Type Parameters
- T extends IVector4Like
Parameters
- x: number
value to transform
- y: number
value to transform
- z: number
value to transform
- w: number
value to transform
- transformation: DeepImmutable<Matrix>
the transformation matrix to apply
- result: T
the vector to store the results in
Returns T
result input
StaticTransform Normal To Ref
-
TransformNormalToRef<T extends IVector4Like>(
vector: DeepImmutable<IVector4Like>,
transformation: DeepImmutable<Matrix>,
result: T,
): TSets the given vector "result" with the result of the normal transformation by the given matrix of the given vector. This methods computes transformed normalized direction vectors only.
Type Parameters
- T extends IVector4Like
Parameters
- vector: DeepImmutable<IVector4Like>
the vector to transform
- transformation: DeepImmutable<Matrix>
the transformation matrix to apply
- result: T
the vector to store the result in
Returns T
result input
Vector4 class created for EulerAngle class conversion to Quaternion