More actions
No edit summary |
clown emoji Tag: 2017 source edit |
||
Line 37: | Line 37: | ||
== Operators == | == Operators == | ||
{| class="wikitable" | {| class="wikitable" | ||
! | ! Operator !! Brief description | ||
|- | |- | ||
{{:Vector/OperatorIndex}} | {{:Vector/OperatorIndex}} |
Revision as of 04:26, 29 October 2024
A vector is a data structure that holds 2, 3, or 4 numbers. It is commonly used to refer to positions and rotations of things.
For a higher-level overview of vectors, read Vectors and Matrices.
Swizzling
Swizzling refers to changing components of vectors by re-arranging the values already present.
To perform a swizzling operation, index the vector with between 2 and 4 x
, y
, z
, w
, or _
characters.
A new vector will be formed from the components specified (i.e. v.xxxx
will create a new vector from the x
component of v
repeated 4 times.) The _
component will fill in a value of 0 in any position where it is specified.
For example, if v
is a Vector4, the following are all valid and return a new Vector4:
v.xyzw
v.xxzz
v.wzyx
v.wyxy
v.___x
Swizzling operations can also transform vectors between sizes.
For example, to create a Vector2 from a Vector3's x and y components, use v3.xy
.
This works in both directions – a common action is upgrading a Vector2 to a Vector3 by adding a 0 as the Z component:
local vec2 = vec(1, 2)
print(vec2) -- {1, 2}
local vec3 = vec2.xy_ -- or .x_y, ._xy, ...
print(vec3) -- {1, 2, 0}
Methods
Method | Brief description |
---|
Operators
Operator | Brief description |
---|