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
blockPosBlockPosThe 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
Vec3(float)
Initializes a new instance of the Vec3 struct with all components set to the same value.
public Vec3(float value)
Parameters
valuefloatThe 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
Fields
X
The X component of the vector.
public float X
Field Value
Y
The Y component of the vector.
public float Y
Field Value
Z
The Z component of the vector.
public float Z
Field Value
Properties
Direction
Gets the direction of the vector as a Vec2 (yaw, pitch).
public Vec2 Direction { get; }
Property Value
Length
Gets the Euclidean length of the vector.
public float Length { get; }
Property Value
Magnitude
Gets the magnitude (length) of the vector.
public float Magnitude { get; }
Property Value
MagnitudeSqr
Gets the squared magnitude of the vector.
public float MagnitudeSqr { get; }
Property Value
Normalized
Gets a normalized version of this vector.
public Vec3 Normalized { get; }
Property Value
One
Gets a Vec3 with all components set to one.
public static Vec3 One { get; }
Property Value
Zero
Gets a Vec3 with all components set to zero.
public static Vec3 Zero { get; }
Property Value
Methods
Angle(Vec3)
Returns the angle (in radians) between this and another Vec3.
public float Angle(Vec3 vec)
Parameters
vecVec3The other Vec3.
Returns
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
Returns
Clamp(float, float)
Clamps this vector between two scalar values.
public Vec3 Clamp(float min, float max)
Parameters
Returns
Cross(Vec3)
Returns the cross product of this and another Vec3.
public Vec3 Cross(Vec3 vec)
Parameters
vecVec3The other Vec3.
Returns
Distance(Vec3)
Returns the Euclidean distance to another Vec3.
public float Distance(Vec3 vec)
Parameters
vecVec3The other Vec3.
Returns
DistanceSqr(Vec3)
Returns the squared distance between this vector and another vector.
public float DistanceSqr(Vec3 vec)
Parameters
vecVec3The 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
vecVec3The other Vec3.
Returns
Equals(Vec3)
Determines whether this instance is equal to another Vec3.
public bool Equals(Vec3 other)
Parameters
otherVec3The other Vec3.
Returns
Equals(object?)
Determines whether this instance is equal to a specified object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with.
Returns
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
Lerp(Vec3, float)
Linearly interpolates between this and another Vec3.
public Vec3 Lerp(Vec3 vec, float t)
Parameters
Returns
Max(Vec3)
Returns a Vec3 with the maximum components of this and another Vec3.
public Vec3 Max(Vec3 vec)
Parameters
vecVec3The other Vec3.
Returns
Min(Vec3)
Returns a Vec3 with the minimum components of this and another Vec3.
public Vec3 Min(Vec3 vec)
Parameters
vecVec3The other Vec3.
Returns
Rotate(float, float)
Rotates this vector by the given yaw and pitch angles.
public Vec3 Rotate(float yaw, float pitch)
Parameters
Returns
Round()
Rounds the components of the vector to the nearest integer values.
public Vec3 Round()
Returns
SetDirection(Vec2)
Sets the direction of this vector, preserving its magnitude.
public void SetDirection(Vec2 direction)
Parameters
directionVec2The direction as a Vec2 (yaw, pitch).
SetMagnitude(float)
Sets the magnitude (length) of this vector.
public void SetMagnitude(float magnitude)
Parameters
magnitudefloatThe new magnitude.
ToString()
Returns a string representation of this Vec3.
public override string ToString()
Returns
ToString(string, CultureInfo?)
Returns a formatted string representation of this Vec3.
public string ToString(string format, CultureInfo? culture = null)
Parameters
formatstringThe format string.
cultureCultureInfoThe culture to use for formatting.
Returns
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
xfloatThe new X value for the vector.
Returns
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
yfloatThe new value for the Y component.
Returns
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
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
Returns
operator +(Vec3, float)
Adds a scalar value to a Vec3.
public static Vec3 operator +(Vec3 vec, float value)
Parameters
Returns
operator /(Vec3, Vec3)
Divides two Vec3 vectors component-wise.
public static Vec3 operator /(Vec3 vec, Vec3 scalar)
Parameters
Returns
operator /(Vec3, float)
Divides a Vec3 by a scalar value.
public static Vec3 operator /(Vec3 vec, float scalar)
Parameters
Returns
operator ==(Vec3, Vec3)
Determines whether two Vec3 instances are equal.
public static bool operator ==(Vec3 left, Vec3 right)
Parameters
Returns
operator >(Vec3, Vec3)
Determines whether one Vec3 is greater than another.
public static bool operator >(Vec3 left, Vec3 right)
Parameters
Returns
operator >=(Vec3, Vec3)
Determines whether one Vec3 is greater than or equal to another.
public static bool operator >=(Vec3 left, Vec3 right)
Parameters
Returns
implicit operator Vector3(Vec3)
Implicitly converts a Vec3 to a Vector3.
public static implicit operator Vector3(Vec3 vec)
Parameters
vecVec3The Vec3.
Returns
implicit operator Vec3(Vector3)
Implicitly converts a Vector3 to a Vec3.
public static implicit operator Vec3(Vector3 vec)
Parameters
vecVector3The Vector3.
Returns
operator !=(Vec3, Vec3)
Determines whether two Vec3 instances are not equal.
public static bool operator !=(Vec3 left, Vec3 right)
Parameters
Returns
operator <(Vec3, Vec3)
Determines whether one Vec3 is less than another.
public static bool operator <(Vec3 left, Vec3 right)
Parameters
Returns
operator <=(Vec3, Vec3)
Determines whether one Vec3 is less than or equal to another.
public static bool operator <=(Vec3 left, Vec3 right)
Parameters
Returns
operator *(Vec3, Vec3)
Multiplies two Vec3 vectors component-wise.
public static Vec3 operator *(Vec3 vec, Vec3 other)
Parameters
Returns
operator *(Vec3, float)
Multiplies a Vec3 by a scalar value.
public static Vec3 operator *(Vec3 vec, float scalar)
Parameters
Returns
operator *(float, Vec3)
Multiplies a scalar value by a Vec3.
public static Vec3 operator *(float scalar, Vec3 vec)
Parameters
Returns
operator -(Vec3, Vec3)
Subtracts one Vec3 from another.
public static Vec3 operator -(Vec3 left, Vec3 right)
Parameters
Returns
operator -(Vec3, float)
Subtracts a scalar value from a Vec3.
public static Vec3 operator -(Vec3 vec, float value)
Parameters
Returns
operator -(Vec3)
Negates a Vec3.
public static Vec3 operator -(Vec3 vec)
Parameters
vecVec3The Vec3 to negate.