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)
Vector specific page
Tag: 2017 source edit
 
PenguinEncounter (talk | contribs)
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

  1. REDIRECT Vector/MethodIndex
Method Brief description

Fields

User:PenguinEncounter/Vector/FieldIndex
Method Brief description

Operators

  1. REDIRECT Vector/OperatorIndex
Method Brief description

Methods

  1. REDIRECT Vector/Methods

Fields

  1. REDIRECT Vector/Fields

Operators

  1. REDIRECT Vector/Operators