Vector4 - stingray.Vector4 object reference - Stingray Lua API Reference

stingray.Vector4 object reference

Description

Describes a three-dimensional vector.

NOTE: Vector4 objects are temporary. You can only use them in the frame in which they were generated. If you need to save a Vector4 across multiple frames, use a Vector4Box instead. For more information, see Object Lifetimes and Userdata Binding.

Operators

You can use several operators like + and - to modify and transform Vector4 objects, described below.

Addition: +

You can add two vectors together using the + operator. For example:

newVector = vector1 + vector2

This is equivalent to the add() function.

Subtraction: -

You can subtract one vector from another using the - operator. For example:

newVector = vector1 - vector2

This is equivalent to the subtract() function.

Negation: -

You can negate a vector using the - operator as a prefix to any vector variable. For example:

negativeVector = -vector1

Multiplication: *

You can multiply a vector by a scalar value using the * operator. For example:

newVector = vector * scalarFactor

This is equivalent to the multiply() function. See also multiply_elements(), which lets you multiply two vectors together per-element.

Division: /

You can divide a vector by a scalar value using the / operator. For example:

newVector = vector / scalarFactor

This is equivalent to the divide() function. See also divide_elements(), which lets you divide one vector by another per-element.

Accessing components: []

You can set and retrieve component values by using the [] operator. Use the indices 1 or "x" for the X component, 2 or "y" for the Y component, 3 or "z" for the Z component, and 4 or "w" for the W component. For example:

yComponentValue = vector[2]
zComponentValue = vector["z"]

Data Members

w : number

The W component.

x : number

The X component.

y : number

The Y component.

z : number

The Z component.

Functions

Parameters

vector_a :

stingray.Vector4

The first vector to add.

vector_b :

stingray.Vector4

The second vector to add.

Returns

stingray.Vector4

The sum of the two input vectors.

Parameters

vector_a :

stingray.Vector4

The first point.

vector_b :

stingray.Vector4

The second point.

Returns

number

The scalar distance between vector_a and vector_b.

Parameters

vector_a :

stingray.Vector4

The first vector.

vector_b :

stingray.Vector4

The second vector.

Returns

number

The square of the distance between vector_a and vector_b.

Parameters

vector :

stingray.Vector4

The vector to divide.

factor :

number

A scalar value to divide into the vector.

Returns

stingray.Vector4

The quotient of the input vector and the scalar value.

Parameters

vector_a :

stingray.Vector4

The vector to be divided.

vector_b :

stingray.Vector4

The vector to divide into vector_a.

Returns

stingray.Vector4

The quotient of the two input vectors.

Parameters

vector_a :

stingray.Vector4

The first vector.

vector_b :

stingray.Vector4

The second vector.

Returns

number

The dot product.

Parameters

vector :

stingray.Vector4

The vector whose component will be returned.

index :

integer

The index of the component to return. Use 1 for the X component, 2 for the Y component, 3 for the Z component, or 4 for the W component

Returns

number

The value of the element at the specified index.

Parameters

vector_a :

stingray.Vector4

The first vector to compare.

vector_b :

stingray.Vector4

The second vector to compare.

Returns

boolean

Returns true if the two vectors are identical, or false otherwise.

Parameters

vector :

stingray.Vector4

The vector to be validated.

Returns

boolean

Returns true if all components of the vector are valid numbers, or false if any component is #NaN or #INF.

Parameters

vector :

stingray.Vector4

The vector whose length will be returned.

Returns

number

The length of the vector.

Parameters

vector_a :

stingray.Vector4

The first vector.

vector_b :

stingray.Vector4

The second vector.

ratio :

number

The interpolation ratio, or weight. May be any value between 0 and 1 inclusive. Values closer to 0 produce vectors closer to vector_a; values closer to 1 produce vectors closer to vector_b.

Returns

stingray.Vector4

The resulting vector.

Parameters

vector_a :

stingray.Vector4

The first vector.

vector_b :

stingray.Vector4

The second vector.

Returns

stingray.Vector4

The resulting vector.

Parameters

vector_a :

stingray.Vector4

The first vector.

vector_b :

stingray.Vector4

The second vector.

Returns

stingray.Vector4

The resulting vector.

Parameters

vector :

stingray.Vector4

The vector to multiply.

factor :

number

A scalar value to multiply with the vector.

Returns

stingray.Vector4

The product of the input vector and the scalar value.

Parameters

vector_a :

stingray.Vector4

The first vector to multiply.

vector_b :

stingray.Vector4

The second vector to multiply.

Returns

stingray.Vector4

The product of the two input vectors.

Parameters

vector :

stingray.Vector4

The vector to be normalized.

Returns

stingray.Vector4

The normalized vector.

Parameters

vector :

stingray.Vector4

The vector whose component will be set.

index :

integer

The index of the component to set. Use 1 for the X component, 2 for the Y component, 3 for the Z component, or 4 for the W component.

value :

number

The value to set at the specified index.

Returns
This function does not return any values.
Parameters

vector :

stingray.Vector4

The vector whose component will be set.

value :

number

The new value for the W component.

Returns
This function does not return any values.
Parameters

vector :

stingray.Vector4

The vector whose component will be set.

value :

number

The new value for the X component.

Returns
This function does not return any values.
Parameters

vector :

stingray.Vector4

The vector whose components will be set.

x :

number

The new value for the X component.

y :

number

The new value for the Y component.

z :

number

The new value for the Z component.

w :

number

The new value for the W component.

Returns
This function does not return any values.
Parameters

vector :

stingray.Vector4

The vector whose component will be set.

value :

number

The new value for the Y component.

Returns
This function does not return any values.
Parameters

vector :

stingray.Vector4

The vector whose component will be set.

value :

number

The new value for the Z component.

Returns
This function does not return any values.
Parameters

vector_a :

stingray.Vector4

The starting vector.

vector_b :

stingray.Vector4

The vector that will be subtracted.

Returns

stingray.Vector4

The result of the subtraction.

Parameters

vector :

stingray.Vector4

The vector to be broken down into its components.

Returns

number

The X component of the vector.

number

The Y component of the vector.

number

The Z component of the vector.

number

The W component of the vector.

Parameters

vector :

stingray.Vector4

The vector to return as a string.

Returns

string

The string representation.

Use this function only for debugging purposes; do not attempt to save the string and read it back into a new vector. Use a Vector4Box to save vectors across multiple frames.

Parameters

vector :

stingray.Vector4

The vector whose component will be returned.

Returns

number

The value of the W component.

Parameters

vector :

stingray.Vector4

The vector whose component will be returned.

Returns

number

The value of the X component.

Parameters

vector :

stingray.Vector4

The vector whose component will be returned.

Returns

number

The value of the Y component.

Parameters

vector :

stingray.Vector4

The vector whose component will be returned.

Returns

number

The value of the Z component.

Parameters
This function does not accept any parameters.
Returns

stingray.Vector4

The zero vector.