Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Vector: Difference between revisions

From FiguraMC
PenguinEncounter (talk | contribs)
clown emoji
Tag: 2017 source edit
PenguinEncounter (talk | contribs)
Add fields section
Tag: 2017 source edit
Line 33: Line 33:
|-
|-
{{:Vector/MethodIndex}}
{{:Vector/MethodIndex}}
|}
== Fields ==
{| class="wikitable"
! Field !! Brief description
{{:Vector/FieldIndex}}
|}
|}



Revision as of 04:38, 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

Vector/MethodIndex
Method Brief description

Fields

Field Brief description

Vector/FieldIndex

Operators

Vector/OperatorIndex
Operator Brief description

Methods

Vector/Methods

Fields

Vector/Fields

Operators

Vector/Operators