Vec3

January 7, 2026 ยท View on GitHub

GMR Docs > Types > Vec3

Vec3

3D vector for positions and colors.

Table of Contents

Instance Methods

#initialize

Create a new Vec3 with optional x, y, and z values.

Parameters:

NameTypeDescription
xFloatThe x component (default: 0)
yFloatThe y component (default: 0)
zFloatThe z component (default: 0)

Returns: Vec3 - The new vector

Example:

Vec3.new(1, 2, 3)     # (1, 2, 3)

#x

Get the x component.

Returns: Float - The x value

Example:

x = vec.x

#y

Get the y component.

Returns: Float - The y value

Example:

y = vec.y

#z

Get the z component.

Returns: Float - The z value

Example:

z = vec.z

#+

Add two vectors, returning a new Vec3.

Parameters:

NameTypeDescription
otherVec3The vector to add

Returns: Vec3 - A new vector with the sum

Example:

result = Vec3.new(1, 2, 3) + Vec3.new(1, 1, 1)  # Vec3(2, 3, 4)

#-

Subtract two vectors, returning a new Vec3.

Parameters:

NameTypeDescription
otherVec3The vector to subtract

Returns: Vec3 - A new vector with the difference

Example:

result = Vec3.new(5, 5, 5) - Vec3.new(1, 2, 3)  # Vec3(4, 3, 2)

#*

Multiply vector by a scalar, returning a new Vec3.

Parameters:

NameTypeDescription
scalarFloatThe scalar value

Returns: Vec3 - A new scaled vector

Example:

result = Vec3.new(1, 2, 3) * 2.0  # Vec3(2, 4, 6)

#/

Divide vector by a scalar, returning a new Vec3.

Parameters:

NameTypeDescription
scalarFloatThe scalar value (must not be zero)

Returns: Vec3 - A new scaled vector

Example:

result = Vec3.new(10, 20, 30) / 10.0  # Vec3(1, 2, 3)

#to_s

A rectangle with position (x, y) and dimensions (w, h). Used for bounds, source rectangles, collision areas, and UI layout.

Returns: String - String in format "Vec3(x, y, z)"

Example:

# UI layout helper
  class UILayoutHelper
    def initialize(container)


Back to Types | Documentation Home