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)
m PenguinEncounter moved page User:PenguinEncounter/Vector to Vector: Move to mainspace from user draft
PenguinEncounter (talk | contribs)
adjust targets
Tag: 2017 source edit
Line 30: Line 30:
! Method !! Brief description
! Method !! Brief description
|-
|-
{{User:PenguinEncounter/Vector/MethodIndex}}
{{:Vector/MethodIndex}}
|}
|}


Line 37: Line 37:
! Method !! Brief description
! Method !! Brief description
|-
|-
{{User:PenguinEncounter/Vector/OperatorIndex}}
{{:Vector/OperatorIndex}}
|}
|}


== Methods ==
== Methods ==
{{User:PenguinEncounter/Vector/Methods}}
{{:Vector/Methods}}


== Fields ==  
== Fields ==  
{{User:PenguinEncounter/Vector/Fields}}
{{:Vector/Fields}}


== Operators ==
== Operators ==
{{User:PenguinEncounter/Vector/Operators}}
{{:Vector/Operators}}

Revision as of 03:20, 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

Vector/MethodIndex
Method Brief description

Operators

Vector/OperatorIndex
Method Brief description

Methods

Vector/Methods

Fields

Vector/Fields

Operators

Vector/Operators