Class Vector3

Vector3 metatype, wrapper for godot_vector3.

Construct using the idiom Vector3(...), which calls __new.

The X, Y and Z components may be accessed through elements or the triplets x/y/z, r/g/b, s/t/p, width/height/depth, the pair u/v. Vector2 with two adjacent components may be get/set with pairs like xy or yz:

typedef union godot_vector3 {
    uint8_t data[12];
    float elements[3];
    // xyz
    struct { float x, y, z; };
    struct { Vector2 xy; float _; };
    struct { float _; Vector2 yz; };
    // rgb
    struct { float r, g, b; };
    struct { Vector2 rg; float _; };
    struct { float _; Vector2 gb; };
    // stp
    struct { float s, t, p; };
    struct { Vector2 st; float _; };
    struct { float _; Vector2 tp; };
    // uv
    struct { float u, v, _; };
    struct { Vector2 uv; float _; };
    // 3D Size: width/height/depth
    struct { float width, height, depth; };
} godot_vector3;

Methods

Vector3:abs () Returns a new vector with all components in absolute values (i.e.
Vector3:angle_to (b) Returns the minimum angle to the given vector, in radians.
Vector3:bounce (normal) Returns the vector "bounced off" from a plane defined by the given normal.
Vector3:ceil () Returns a new vector with all components rounded up (towards positive infinity).
Vector3:cross (b) Returns the cross product of this vector and b.
Vector3:cubic_interpolate () Performs a cubic interpolation between vectors pre_a, a, b, post_b (a is current), by the given amount t.
Vector3:direction_to (to) Returns the normalized vector pointing from this vector to b.
Vector3:distance_squared_to (b) Returns the squared distance between this vector and b.
Vector3:distance_to (b) Returns the distance between this vector and b.
Vector3:dot (b) Returns the dot product of this vector and b.
Vector3:floor () Returns a new vector with all components rounded down (towards negative infinity).
Vector3:inverse () Returns the inverse of the vector.
Vector3:is_normalized () Returns true if the vector is normalized.
Vector3:length () Returns the length (magnitude) of this vector.
Vector3:length_squared () Returns the squared length (squared magnitude) of this vector.
Vector3:linear_interpolate (b, t) Returns the result of the linear interpolation between this vector and b by amount t.
Vector3:max_axis () Returns the axis of the vector's largest value.
Vector3:min_axis () Returns the axis of the vector's smallest value.
Vector3:move_toward (to, delta) Moves this vector toward to by the fixed delta amount.
Vector3:normalized () Returns the vector scaled to unit length.
Vector3:outer (b) Returns the outer product with b.
Vector3:reflect (normal) Returns this vector reflected from a plane defined by the given normal.
Vector3:rotated (axis, phi) Rotates this vector around a given axis by phi radians.
Vector3:slide (normal) Returns this vector slid along a plane defined by the given normal.
Vector3:snapped (step) Returns this vector with each component snapped to the nearest multiple of step.
Vector3:to_diagonal_matrix () Returns a diagonal matrix with the vector as main diagonal.
Vector3:unpack () Returns all elements.

Metamethods

Vector3:__add (a, b) Addition operation
Vector3:__concat (a, b) Concatenates values.
Vector3:__div (a, b) Division operation
Vector3:__eq (a, b) Equality operation
Vector3:__lt (a, b) Less than operation
Vector3:__mod (a, b) Module operation
Vector3:__mul (a, b) Multiplication operation
Vector3:__new (...) Vector3 constructor, called by the idiom Vector3(...).
Vector3:__pow (a, b) Power operation
Vector3:__sub (a, b) Subtraction operation
Vector3:__tostring () Returns a Lua string representation of this vector.
Vector3:__unm () Unary minus operation

Constants

Vector3.AXIS_X Enumerated value for the X axis.
Vector3.AXIS_Y Enumerated value for the Y axis.
Vector3.AXIS_Z Enumerated value for the Z axis.
Vector3.BACK Back unit vector.
Vector3.DOWN Down unit vector.
Vector3.FORWARD Forward unit vector.
Vector3.INF Infinity vector, a vector with all components set to inf.
Vector3.LEFT Left unit vector.
Vector3.ONE One vector, a vector with all components set to 1.
Vector3.RIGHT Right unit vector.
Vector3.UP Up unit vector.
Vector3.ZERO Zero vector, a vector with all components set to 0.


Methods

Vector3:abs ()
Returns a new vector with all components in absolute values (i.e. positive).

Returns:

    Vector3
Vector3:angle_to (b)
Returns the minimum angle to the given vector, in radians.

Parameters:

Returns:

    number
Vector3:bounce (normal)
Returns the vector "bounced off" from a plane defined by the given normal.

Parameters:

Returns:

    Vector3
Vector3:ceil ()
Returns a new vector with all components rounded up (towards positive infinity).

Returns:

    Vector3
Vector3:cross (b)
Returns the cross product of this vector and b.

Parameters:

Returns:

    Vector3
Vector3:cubic_interpolate ()
Performs a cubic interpolation between vectors pre_a, a, b, post_b (a is current), by the given amount t. t is on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns:

    Vector3
Vector3:direction_to (to)
Returns the normalized vector pointing from this vector to b. Equivalent to (b - a).normalized().

Parameters:

Returns:

    Vector3
Vector3:distance_squared_to (b)
Returns the squared distance between this vector and b. This method runs faster than distance_to, so prefer it if you need to compare vectors or need the squared distance for some formula.

Parameters:

Returns:

    number
Vector3:distance_to (b)
Returns the distance between this vector and b.

Parameters:

Returns:

    number
Vector3:dot (b)
Returns the dot product of this vector and b.

Parameters:

Returns:

    Vector3
Vector3:floor ()
Returns a new vector with all components rounded down (towards negative infinity).

Returns:

    Vector3
Vector3:inverse ()
Returns the inverse of the vector. Equivalent to 1.0 / v.

Returns:

    Vector3
Vector3:is_normalized ()
Returns true if the vector is normalized.

Returns:

    bool
Vector3:length ()
Returns the length (magnitude) of this vector.

Returns:

    number
Vector3:length_squared ()
Returns the squared length (squared magnitude) of this vector. This method runs faster than length, so prefer it if you need to compare vectors or need the squared distance for some formula.

Returns:

    number
Vector3:linear_interpolate (b, t)
Returns the result of the linear interpolation between this vector and b by amount t. t is on the range of 0.0 to 1.0, representing the amount of interpolation.

Parameters:

Returns:

    Vector3
Vector3:max_axis ()
Returns the axis of the vector's largest value. If all components are equal, this method returns AXIS_Z.

Returns:

    int AXIS_X, AXIS_Y or AXIS_Z
Vector3:min_axis ()
Returns the axis of the vector's smallest value. If all components are equal, this method returns AXIS_Z.

Returns:

    int AXIS_X, AXIS_Y or AXIS_Z
Vector3:move_toward (to, delta)
Moves this vector toward to by the fixed delta amount.

Parameters:

Returns:

    Vector3
Vector3:normalized ()
Returns the vector scaled to unit length. Equivalent to v / v.length().

Returns:

    Vector3
Vector3:outer (b)
Returns the outer product with b.

Parameters:

Returns:

    Basis
Vector3:reflect (normal)
Returns this vector reflected from a plane defined by the given normal.

Parameters:

Returns:

    Vector3
Vector3:rotated (axis, phi)
Rotates this vector around a given axis by phi radians. The axis must be a normalized vector.

Parameters:

Returns:

    Vector3
Vector3:slide (normal)
Returns this vector slid along a plane defined by the given normal.

Parameters:

Returns:

    Vector3
Vector3:snapped (step)
Returns this vector with each component snapped to the nearest multiple of step. This can also be used to round to an arbitrary number of decimals.

Parameters:

Returns:

    Vector3
Vector3:to_diagonal_matrix ()
Returns a diagonal matrix with the vector as main diagonal. This is equivalent to a Basis with no rotation or shearing and this vector's components set as the scale.

Returns:

    Basis
Vector3:unpack ()
Returns all elements.

Returns:

  1. number X
  2. number Y
  3. number Z

Metamethods

Vector3:__add (a, b)
Addition operation

Parameters:

Returns:

    Vector3
Vector3:__concat (a, b)
Concatenates values.

Parameters:

  • a First value, stringified with GD.str
  • b First value, stringified with GD.str

Returns:

    String
Vector3:__div (a, b)
Division operation

Parameters:

Returns:

    Vector3
Vector3:__eq (a, b)
Equality operation

Parameters:

Returns:

    bool
Vector3:__lt (a, b)
Less than operation

Parameters:

Returns:

    bool
Vector3:__mod (a, b)
Module operation

Parameters:

Returns:

    Vector3
Vector3:__mul (a, b)
Multiplication operation

Parameters:

Returns:

    Vector3
Vector3:__new (...)

Vector3 constructor, called by the idiom Vector3(...).

  • Vector3(): all zeros (Vector3() == Vector3(0, 0, 0))
  • Vector3(number x): all components are set to x (Vector3(1) == Vector3(1, 1, 1))
  • Vector3(number x, number y[, number z = 0]): set XYZ
  • Vector3(Vector2 xy[, number z = 0]): set XYZ
  • Vector3(number x, Vector2 yz): set XYZ
  • Vector3(Vector3 other): copy values from other

Parameters:

  • ...

Returns:

    Vector3
Vector3:__pow (a, b)
Power operation

Parameters:

Returns:

    Vector3
Vector3:__sub (a, b)
Subtraction operation

Parameters:

Returns:

    Vector3
Vector3:__tostring ()
Returns a Lua string representation of this vector.

Returns:

    string
Vector3:__unm ()
Unary minus operation

Returns:

    Vector3

Constants

Vector3.AXIS_X
Enumerated value for the X axis.
  • AXIS_X 0
Vector3.AXIS_Y
Enumerated value for the Y axis.
  • AXIS_Y 1
Vector3.AXIS_Z
Enumerated value for the Z axis.
  • AXIS_Z 2
Vector3.BACK
Back unit vector. Represents the local direction of back, and the global direction of south.
  • BACK Vector3(0, 0, 1)
Vector3.DOWN
Down unit vector.
  • DOWN Vector3(0, -1, 0)
Vector3.FORWARD
Forward unit vector. Represents the local direction of forward, and the global direction of north.
  • FORWARD Vector3(0, 0, -1)
Vector3.INF
Infinity vector, a vector with all components set to inf.
  • INF Vector3(1 / 0)
Vector3.LEFT
Left unit vector. Represents the local direction of left, and the global direction of west.
  • LEFT Vector3(-1, 0, 0)
Vector3.ONE
One vector, a vector with all components set to 1.
  • ONE Vector3(1)
Vector3.RIGHT
Right unit vector. Right unit vector. Represents the local direction of right, and the global direction of east.
  • RIGHT Vector3(1, 0, 0)
Vector3.UP
Up unit vector.
  • UP Vector3(0, 1, 0)
Vector3.ZERO
Zero vector, a vector with all components set to 0.
  • ZERO Vector3(0)
generated by LDoc 1.4.6 Last updated 2023-01-04 08:52:34