Vector3¶
The Vector3 class represents a three-dimensional vector with x, y, and z components, providing essential functionalities for vector operations.
Usage¶
To use this class, add the following require at the top of your script:
local Vector3 = require 'engine/math/vector3'
Reference¶
- class Vector3¶
- module:
- static fromData(data)¶
Create a vector object from data
- Parameters:
data (
table) – the data table- Returns:
the new Vector3 object
- Return type:
- static new(x, y, z)¶
Create new vector
- Parameters:
x (
number) – x componenty (
number) – y componentz (
number) – z component
- Returns:
the new vector
- Return type:
- set(x, y, z)¶
Set values of vector
- Parameters:
x (
number) – x componenty (
number) – y componentz (
number) – z component
- get()¶
Get values of vector
- Returns:
the x,y,z values
- Return type:
number or number or number
- toData()¶
Get values of vector as table
- Returns:
the values
- Return type:
table
- static distance(va, vb)¶
Calculate distance between 2 vectors
- static dot(lhs, rhs)¶
Calculate dot product of 2 vectors
- static lerp(from, to, t)¶
Linear interpolation between 2 vectors
- magnitude()¶
Calculate magnitude of the vector
- Returns:
magnitude value
- Return type:
number
- sqrMagnitude()¶
Calculate squared magnitude of the vector (faster than magnitude)
- Returns:
squared magnitude value
- Return type:
number
- static max(lhs, rhs)¶
Return the maximum values from both vectors for each component
- static min(lhs, rhs)¶
Return the minimum values from both vectors for each component
- normalized()¶
Return the normalized version of the vector
- Returns:
normalized vector
- Return type:
- clampMagnitude(maxLength)¶
Clamp the magnitude of the vector
- Parameters:
maxLength (
number) – maximum length- Returns:
returns itself
- Return type:
- static project(a, b)¶
Project vector onto another vector
- projectOnPlane(planeNormal)¶
Project vector onto a plane defined by normal
- reflect(inNormal)¶
Reflect vector off a plane defined by normal
- static rotateTowards(current, target, maxRadiansDelta, maxMagnitudeDelta)¶
Rotate vector towards target vector
- static moveTowards(current, target, maxDistanceDelta)¶
Move vector towards target vector
- static smoothDamp(current, target, currentVelocity, smoothTime, deltaTime)¶
Smoothly interpolates a vector toward a target with velocity damping
- Parameters:
- Returns:
smoothed position
- Return type:
- Returns:
updated velocity
- Return type:
- add(vb)¶
Adds another vector to this vector
- sub(vb)¶
Subtracts another vector from this vector
- mul(d)¶
Multiplies this vector by a scalar
- Parameters:
d (
number) – scalar value- Returns:
returns itself
- Return type:
- div(d)¶
Divides this vector by a scalar
- Parameters:
d (
number) – scalar value- Returns:
returns itself
- Return type:
- mulVec(vb)¶
Multiplies this vector by another vector (component-wise)
- mulQuat(quat)¶
Multiply quaternion with this vector
- Parameters:
quat (
Quaternion) – input quaternion- Returns:
returns itself
- Return type:
- static angle(from, to)¶
Calculate angle between two vectors
- static angleAroundAxis(from, to, axis)¶
Calculate signed angle between two vectors around an axis
- static createFrustumRays(viewDirection, fov, resX, resY)¶
Creates an array of Vector3 objects which are the direction vectors of the frustum
- Parameters:
viewDirection (
Vector3) – a view vectorfov (
number) – Field of view value in degreesresX (
number) – resolution width. Needs to be at least 2resY (
number) – resolution height Needs to be at least 2
- Returns:
Array of Vector3 objects which have the count width * height
- Return type:
table
- static cross(lhs, rhs)¶
Cross product of two vectors
- static slerp(from, to, t)¶
Spherical interpolation between two vectors
- static orthoNormalize(va, vb, vc)¶
Orthonormalize three vectors