More actions
Vector specific page Tag: 2017 source edit |
add operator section Tag: 2017 source edit |
||
Line 38: | Line 38: | ||
|- | |- | ||
{{User:PenguinEncounter/Vector/FieldIndex}} | {{User:PenguinEncounter/Vector/FieldIndex}} | ||
|} | |||
== Operators == | |||
{| class="wikitable" | |||
! Method !! Brief description | |||
|- | |||
{{User:PenguinEncounter/Vector/OperatorIndex}} | |||
|} | |} | ||
Line 45: | Line 52: | ||
== Fields == | == Fields == | ||
{{User:PenguinEncounter/Vector/Fields}} | {{User:PenguinEncounter/Vector/Fields}} | ||
== Operators == | |||
{{User:PenguinEncounter/Vector/Operators}} |
Revision as of 02:55, 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.
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
- REDIRECT Vector/MethodIndex
Method | Brief description |
---|
Fields
Method | Brief description |
---|
Operators
- REDIRECT Vector/OperatorIndex
Method | Brief description |
---|
Methods
- REDIRECT Vector/Methods
Fields
- REDIRECT Vector/Fields
Operators
- REDIRECT Vector/Operators