Table of Contents

Struct Vec3

Namespace
OnixRuntime.Api.Maths
Assembly
OnixRuntime.dll

Represents a 3D vector with floating-point X, Y, and Z components, and provides vector operations and utilities.

public struct Vec3 : IEquatable<Vec3>
Implements
Inherited Members

Constructors

Vec3()

Initializes a new instance of the Vec3 struct with zero values.

public Vec3()

Vec3(BlockPos)

Initializes a new instance of the Vec3 struct from a BlockPos.

public Vec3(BlockPos blockPos)

Parameters

blockPos BlockPos

The BlockPos to convert.

Vec3(Vector2, float)

Initializes a new instance of the Vec3 struct from a Vector2 and an optional Z value.

public Vec3(Vector2 xy, float z = 0)

Parameters

xy Vector2

The Vector2 for X and Y.

z float

The Z component (default 0).

Vec3(float)

Initializes a new instance of the Vec3 struct with all components set to the same value.

public Vec3(float value)

Parameters

value float

The value for X, Y, and Z.

Vec3(float, float, float)

Initializes a new instance of the Vec3 struct with the specified X, Y, and Z values.

public Vec3(float x, float y, float z)

Parameters

x float

The X component.

y float

The Y component.

z float

The Z component.

Fields

X

The X component of the vector.

public float X

Field Value

float

Y

The Y component of the vector.

public float Y

Field Value

float

Z

The Z component of the vector.

public float Z

Field Value

float

Properties

Direction

Gets the direction of the vector as a Vec2 (yaw, pitch).

public Vec2 Direction { get; }

Property Value

Vec2

Length

Gets the Euclidean length of the vector.

public float Length { get; }

Property Value

float

Magnitude

Gets the magnitude (length) of the vector.

public float Magnitude { get; }

Property Value

float

MagnitudeSqr

Gets the squared magnitude of the vector.

public float MagnitudeSqr { get; }

Property Value

float

Normalized

Gets a normalized version of this vector.

public Vec3 Normalized { get; }

Property Value

Vec3

One

Gets a Vec3 with all components set to one.

public static Vec3 One { get; }

Property Value

Vec3

Zero

Gets a Vec3 with all components set to zero.

public static Vec3 Zero { get; }

Property Value

Vec3

Methods

Angle(Vec3)

Returns the angle (in radians) between this and another Vec3.

public float Angle(Vec3 vec)

Parameters

vec Vec3

The other Vec3.

Returns

float

Ceil()

Returns a new Vec3 instance with each component rounded up to the nearest integer.

public Vec3 Ceil()

Returns

Vec3

A Vec3 where each component is the smallest integer greater than or equal to the corresponding component of the current instance.

Clamp(Vec3, Vec3)

Clamps this vector between two Vec3 values.

public Vec3 Clamp(Vec3 min, Vec3 max)

Parameters

min Vec3

The minimum Vec3.

max Vec3

The maximum Vec3.

Returns

Vec3

Clamp(float, float)

Clamps this vector between two scalar values.

public Vec3 Clamp(float min, float max)

Parameters

min float

The minimum value.

max float

The maximum value.

Returns

Vec3

Cross(Vec3)

Returns the cross product of this and another Vec3.

public Vec3 Cross(Vec3 vec)

Parameters

vec Vec3

The other Vec3.

Returns

Vec3

Distance(Vec3)

Returns the Euclidean distance to another Vec3.

public float Distance(Vec3 vec)

Parameters

vec Vec3

The other Vec3.

Returns

float

DistanceSqr(Vec3)

Returns the squared distance between this vector and another vector.

public float DistanceSqr(Vec3 vec)

Parameters

vec Vec3

The other vector to get the squared distance from.

Returns

float

The squared distance from that other vector.

Dot(Vec3)

Returns the dot product of this and another Vec3.

public float Dot(Vec3 vec)

Parameters

vec Vec3

The other Vec3.

Returns

float

Equals(Vec3)

Determines whether this instance is equal to another Vec3.

public bool Equals(Vec3 other)

Parameters

other Vec3

The other Vec3.

Returns

bool

Equals(object?)

Determines whether this instance is equal to a specified object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with.

Returns

bool

Floor()

Returns a new vector with each component rounded down to the nearest integer.

public Vec3 Floor()

Returns

Vec3

A Vec3 instance where each component is the largest integer less than or equal to the corresponding component of the current vector.

GetHashCode()

Returns the hash code for this Vec3.

public override int GetHashCode()

Returns

int

Lerp(Vec3, float)

Linearly interpolates between this and another Vec3.

public Vec3 Lerp(Vec3 vec, float t)

Parameters

vec Vec3

The target Vec3.

t float

The interpolation factor (0 to 1).

Returns

Vec3

Max(Vec3)

Returns a Vec3 with the maximum components of this and another Vec3.

public Vec3 Max(Vec3 vec)

Parameters

vec Vec3

The other Vec3.

Returns

Vec3

Min(Vec3)

Returns a Vec3 with the minimum components of this and another Vec3.

public Vec3 Min(Vec3 vec)

Parameters

vec Vec3

The other Vec3.

Returns

Vec3

Rotate(float, float)

Rotates this vector by the given yaw and pitch angles.

public Vec3 Rotate(float yaw, float pitch)

Parameters

yaw float

The yaw angle in radians.

pitch float

The pitch angle in radians.

Returns

Vec3

Round()

Rounds the components of the vector to the nearest integer values.

public Vec3 Round()

Returns

Vec3

A new Vec3 instance with each component rounded to the nearest integer.

SetDirection(Vec2)

Sets the direction of this vector, preserving its magnitude.

public void SetDirection(Vec2 direction)

Parameters

direction Vec2

The direction as a Vec2 (yaw, pitch).

SetMagnitude(float)

Sets the magnitude (length) of this vector.

public void SetMagnitude(float magnitude)

Parameters

magnitude float

The new magnitude.

ToString()

Returns a string representation of this Vec3.

public override string ToString()

Returns

string

ToString(string, CultureInfo?)

Returns a formatted string representation of this Vec3.

public string ToString(string format, CultureInfo? culture = null)

Parameters

format string

The format string.

culture CultureInfo

The culture to use for formatting.

Returns

string

WithX(float)

Creates a new Vec3 instance with the specified X value, while retaining the current Y and Z values.

public Vec3 WithX(float x)

Parameters

x float

The new X value for the vector.

Returns

Vec3

A new Vec3 instance with the specified X value and the current Y and Z values.

WithY(float)

Creates a new Vec3 instance with the Y component set to the specified value, while retaining the X and Z components of the current instance.

public Vec3 WithY(float y)

Parameters

y float

The new value for the Y component.

Returns

Vec3

A new Vec3 instance with the updated Y component.

WithZ(float)

Creates a new Vec3 instance with the specified Z-coordinate, while preserving the X and Y coordinates of the current instance.

public Vec3 WithZ(float z)

Parameters

z float

The new Z-coordinate for the resulting Vec3 instance.

Returns

Vec3

A new Vec3 instance with the specified Z-coordinate and the same X and Y coordinates as the current instance.

Operators

operator +(Vec3, Vec3)

Adds two Vec3 vectors.

public static Vec3 operator +(Vec3 left, Vec3 right)

Parameters

left Vec3

The left Vec3.

right Vec3

The right Vec3.

Returns

Vec3

operator +(Vec3, float)

Adds a scalar value to a Vec3.

public static Vec3 operator +(Vec3 vec, float value)

Parameters

vec Vec3

The Vec3.

value float

The scalar value.

Returns

Vec3

operator /(Vec3, Vec3)

Divides two Vec3 vectors component-wise.

public static Vec3 operator /(Vec3 vec, Vec3 scalar)

Parameters

vec Vec3

The first Vec3.

scalar Vec3

The second Vec3.

Returns

Vec3

operator /(Vec3, float)

Divides a Vec3 by a scalar value.

public static Vec3 operator /(Vec3 vec, float scalar)

Parameters

vec Vec3

The Vec3.

scalar float

The scalar value.

Returns

Vec3

operator ==(Vec3, Vec3)

Determines whether two Vec3 instances are equal.

public static bool operator ==(Vec3 left, Vec3 right)

Parameters

left Vec3

The left Vec3.

right Vec3

The right Vec3.

Returns

bool

operator >(Vec3, Vec3)

Determines whether one Vec3 is greater than another.

public static bool operator >(Vec3 left, Vec3 right)

Parameters

left Vec3

The left Vec3.

right Vec3

The right Vec3.

Returns

bool

operator >=(Vec3, Vec3)

Determines whether one Vec3 is greater than or equal to another.

public static bool operator >=(Vec3 left, Vec3 right)

Parameters

left Vec3

The left Vec3.

right Vec3

The right Vec3.

Returns

bool

implicit operator Vector3(Vec3)

Implicitly converts a Vec3 to a Vector3.

public static implicit operator Vector3(Vec3 vec)

Parameters

vec Vec3

The Vec3.

Returns

Vector3

implicit operator Vec3(Vector3)

Implicitly converts a Vector3 to a Vec3.

public static implicit operator Vec3(Vector3 vec)

Parameters

vec Vector3

The Vector3.

Returns

Vec3

operator !=(Vec3, Vec3)

Determines whether two Vec3 instances are not equal.

public static bool operator !=(Vec3 left, Vec3 right)

Parameters

left Vec3

The left Vec3.

right Vec3

The right Vec3.

Returns

bool

operator <(Vec3, Vec3)

Determines whether one Vec3 is less than another.

public static bool operator <(Vec3 left, Vec3 right)

Parameters

left Vec3

The left Vec3.

right Vec3

The right Vec3.

Returns

bool

operator <=(Vec3, Vec3)

Determines whether one Vec3 is less than or equal to another.

public static bool operator <=(Vec3 left, Vec3 right)

Parameters

left Vec3

The left Vec3.

right Vec3

The right Vec3.

Returns

bool

operator *(Vec3, Vec3)

Multiplies two Vec3 vectors component-wise.

public static Vec3 operator *(Vec3 vec, Vec3 other)

Parameters

vec Vec3

The first Vec3.

other Vec3

The second Vec3.

Returns

Vec3

operator *(Vec3, float)

Multiplies a Vec3 by a scalar value.

public static Vec3 operator *(Vec3 vec, float scalar)

Parameters

vec Vec3

The Vec3.

scalar float

The scalar value.

Returns

Vec3

operator *(float, Vec3)

Multiplies a scalar value by a Vec3.

public static Vec3 operator *(float scalar, Vec3 vec)

Parameters

scalar float

The scalar value.

vec Vec3

The Vec3.

Returns

Vec3

operator -(Vec3, Vec3)

Subtracts one Vec3 from another.

public static Vec3 operator -(Vec3 left, Vec3 right)

Parameters

left Vec3

The left Vec3.

right Vec3

The right Vec3.

Returns

Vec3

operator -(Vec3, float)

Subtracts a scalar value from a Vec3.

public static Vec3 operator -(Vec3 vec, float value)

Parameters

vec Vec3

The Vec3.

value float

The scalar value.

Returns

Vec3

operator -(Vec3)

Negates a Vec3.

public static Vec3 operator -(Vec3 vec)

Parameters

vec Vec3

The Vec3 to negate.

Returns

Vec3