GCubeSDK
©2026 FenixFox®Studios

Vector2

Class representing a 2D vector with x, y components.
A 2D vector is an ordered pair of numbers (labeled x and y), which can be used to represent a point in 2D space, a direction and length, or any arbitrary ordered pair of numbers.

  • Mathematical operations (add, subtract, multiply, divide)
  • Vector operations (dot product, normalization)
  • Geometric operations (distance, angle, projection)

Methods

Vector2()

Default constructor - creates a vector at origin (0, 0)

Vector2(f32 x, f32 y)

Value constructor for common init path

x X component of the vector 0.0f
y Y component of the vector 0.0f

Vector2(const Vector3& v)

Constructor from Vector3 (drops z component)

v Vector3 to copy from

Vector2& set(f32 x, f32 y)

Sets the vector components

x X component value
y Y component value

Vector2& setX(f32 x)

Sets the X component

x X component value

Vector2& setY(f32 y)

Sets the Y component

y Y component value

f32 getX() const

Gets the X component

f32 getY() const

Gets the Y component

f32 getComponent(u32 index) const

Gets component by index (0=x, 1=y)

index Component index (0 or 1)

Vector2& setComponent(u32 index, f32 value)

Sets component by index (0=x, 1=y)

index Component index (0 or 1)
value Component value

Vector2& add(const Vector2& v)

Adds another vector to this vector

v Vector to add

Vector2& addScalar(f32 s)

Adds a scalar to all components

s Scalar value to add

Vector2& sub(const Vector2& v)

Subtracts another vector from this vector

v Vector to subtract

Vector2& subScalar(f32 s)

Subtracts a scalar from all components

s Scalar value to subtract

Vector2& multiply(const Vector2& v)

Multiplies this vector by another vector (component-wise)

v Vector to multiply by

Vector2& multiplyScalar(f32 s)

Multiplies all components by a scalar

s Scalar value to multiply by

Vector2& divide(const Vector2& v)

Divides this vector by another vector (component-wise)

v Vector to divide by

Vector2& divideScalar(f32 s)

Divides all components by a scalar

s Scalar value to divide by

f32 dot(const Vector2& v) const

Calculates dot product with another vector

v Vector to calculate dot product with

f32 length() const

Calculates the length (magnitude) of the vector

f32 lengthSq() const

Calculates the squared length of the vector

Vector2& normalize()

Normalizes the vector to unit length

f32 distanceTo(const Vector2& v) const

Calculates distance to another vector

v Target vector

f32 distanceToSquared(const Vector2& v) const

Calculates squared distance to another vector

v Target vector

f32 angle() const

Calculates the angle of the vector in radians

Vector2& setFromAngle(f32 angle)

Sets vector from angle in radians

angle Angle in radians

Vector2 operator+(const Vector2& v) const

Addition operator

v Vector to add

Vector2 operator-(const Vector2& v) const

Subtraction operator

v Vector to subtract

Vector2 operator*(const Vector2& v) const

Multiplication operator (component-wise)

v Vector to multiply by

Vector2 operator*(f32 s) const

Scalar multiplication operator

s Scalar to multiply by

Vector2 operator/(const Vector2& v) const

Division operator (component-wise)

v Vector to divide by

Vector2 operator/(f32 s) const

Scalar division operator

s Scalar to divide by

Vector2& operator+=(const Vector2& v)

Addition assignment operator

v Vector to add

Vector2& operator-=(const Vector2& v)

Subtraction assignment operator

v Vector to subtract

Vector2& operator*=(const Vector2& v)

Multiplication assignment operator

v Vector to multiply by

Vector2& operator*=(f32 s)

Scalar multiplication assignment operator

s Scalar to multiply by

Vector2& operator/=(const Vector2& v)

Division assignment operator

v Vector to divide by

Vector2& operator/=(f32 s)

Scalar division assignment operator

s Scalar to divide by

bool operator==(const Vector2& v) const

Equality operator

v Vector to compare with

bool operator!=(const Vector2& v) const

Inequality operator

v Vector to compare with

Vector2& copy(const Vector2& v)

Copies values from another vector

v Source vector

Vector2& clone() const

Creates a copy of this vector

Vector2& zero()

Sets all components to zero

Vector2& negate()

Negates all components

Vector2& abs()

Sets all components to their absolute values

Vector2& min(const Vector2& v)

Sets each component to the minimum of this and v

v Vector to compare with

Vector2& max(const Vector2& v)

Sets each component to the maximum of this and v

v Vector to compare with

Vector2& clamp(const Vector2& min, const Vector2& max)

Clamps each component between min and max

min Minimum values
max Maximum values

Vector2& clampScalar(f32 minVal, f32 maxVal)

Clamps all components between minVal and maxVal

minVal Minimum value
maxVal Maximum value

Vector2& clampLength(f32 min, f32 max)

Clamps vector length between min and max

min Minimum length
max Maximum length

Vector2& floor()

Rounds each component down to nearest integer

Vector2& ceil()

Rounds each component up to nearest integer

Vector2& round()

Rounds each component to nearest integer

Vector2& roundToZero()

Rounds each component towards zero

Vector3 toVector3(f32 z = 0.0f) const

Converts to Vector3 with optional z component

z Z component value 0.0f

Vector2& fromArray(const f32* array, u32 offset = 0)

Sets vector from array

array Source array
offset Array offset 0

f32* toArray(f32* array = nullptr, u32 offset = 0) const

Converts vector to array

array Target array (if nullptr, creates new)
offset Array offset 0

Properties

id u32 Unique identifier
isVector2 bool Read-only tag
name string Optional display name
uuid string UUID string
x f32 X component
y f32 Y component