Table of Contents

Class Vec3f

Namespace
Vintagestory.API.MathTools
Assembly
VintagestoryAPI.dll

Represents a vector of 3 floats. Go bug Tyron of you need more utility methods in this class.

[JsonObject(MemberSerialization.OptIn)]
[ProtoContract]
public class Vec3f : IVec3, IEquatable<Vec3f>
Inheritance
Vec3f
Implements
Inherited Members
Extension Methods

Constructors

Vec3f()

Creates a new vector with x/y/z = 0

public Vec3f()

Vec3f(float, float, float)

Create a new vector with given coordinates

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

Parameters

x float
y float
z float

Vec3f(float[])

Create a new vector with given coordinates

public Vec3f(float[] values)

Parameters

values float[]

Vec3f(Vec3i)

public Vec3f(Vec3i vec3i)

Parameters

vec3i Vec3i

Vec3f(Vec4f)

Create a new vector with given coordinates

public Vec3f(Vec4f vec)

Parameters

vec Vec4f

Fields

X

The X-Component of the vector

[JsonProperty]
[ProtoMember(1)]
public float X

Field Value

float

Y

The Y-Component of the vector

[JsonProperty]
[ProtoMember(2)]
public float Y

Field Value

float

Z

The Z-Component of the vector

[JsonProperty]
[ProtoMember(3)]
public float Z

Field Value

float

Properties

AsVec3i

public Vec3i AsVec3i { get; }

Property Value

Vec3i

B

Synonum for Z

public float B { get; set; }

Property Value

float

G

Synonum for Y

public float G { get; set; }

Property Value

float

Half

public static Vec3f Half { get; }

Property Value

Vec3f

IsZero

public bool IsZero { get; }

Property Value

bool

this[int]

Returns the n-th coordinate

public float this[int index] { get; set; }

Parameters

index int

Property Value

float

One

public static Vec3f One { get; }

Property Value

Vec3f

R

Synonum for X

public float R { get; set; }

Property Value

float

Zero

Create a new instance with x/y/z set to 0

public static Vec3f Zero { get; }

Property Value

Vec3f

Methods

Add(float, float, float)

Adds given x/y/z coordinates to the vector

public Vec3f Add(float x, float y, float z)

Parameters

x float
y float
z float

Returns

Vec3f

Add(Vec3f)

Adds given x/y/z coordinates to the vector

public Vec3f Add(Vec3f vec)

Parameters

vec Vec3f

Returns

Vec3f

AddCopy(float, float, float)

Adds given coordinates to a new vectors and returns it. The original calling vector remains unchanged

public Vec3f AddCopy(float x, float y, float z)

Parameters

x float
y float
z float

Returns

Vec3f

AddCopy(Vec3f)

Adds both vectors into a new vector. Both source vectors remain unchanged.

public Vec3f AddCopy(Vec3f vec)

Parameters

vec Vec3f

Returns

Vec3f

Clone()

Creates a copy of the vetor

public Vec3f Clone()

Returns

Vec3f

CreateFromBytes(BinaryReader)

public static Vec3f CreateFromBytes(BinaryReader reader)

Parameters

reader BinaryReader

Returns

Vec3f

Cross(Vec3f)

public Vec3f Cross(Vec3f vec)

Parameters

vec Vec3f

Returns

Vec3f

Cross(Vec3f, Vec3f)

Creates the cross product from a and b and sets own values accordingly

public void Cross(Vec3f a, Vec3f b)

Parameters

a Vec3f
b Vec3f

Cross(Vec3f, Vec4f)

Creates the cross product from a and b and sets own values accordingly

public void Cross(Vec3f a, Vec4f b)

Parameters

a Vec3f
b Vec4f

DistanceSq(double, double, double)

Calculates the square distance the two endpoints

public double DistanceSq(double x, double y, double z)

Parameters

x double
y double
z double

Returns

double

DistanceTo(Vec3d)

Calculates the distance the two endpoints

public float DistanceTo(Vec3d vec)

Parameters

vec Vec3d

Returns

float

DistanceTo(Vec3f)

public float DistanceTo(Vec3f vec)

Parameters

vec Vec3f

Returns

float

Dot(double[])

Returns the dot product with given vector

public double Dot(double[] pos)

Parameters

pos double[]

Returns

double

Dot(float[])

Returns the dot product with given vector

public double Dot(float[] pos)

Parameters

pos float[]

Returns

double

Dot(FastVec3f)

public float Dot(FastVec3f a)

Parameters

a FastVec3f

Returns

float

Dot(Vec3d)

Returns the dot product with given vector

public float Dot(Vec3d a)

Parameters

a Vec3d

Returns

float

Dot(Vec3f)

Returns the dot product with given vector

public float Dot(Vec3f a)

Parameters

a Vec3f

Returns

float

Equals(object)

Determines whether the specified object is equal to the current object.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

Equals(Vec3f)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(Vec3f other)

Parameters

other Vec3f

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(Vec3f, double)

public bool Equals(Vec3f other, double epsilon)

Parameters

other Vec3f
epsilon double

Returns

bool

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

Length()

Returns the length of this vector

public float Length()

Returns

float

Mul(float)

Multiplies each coordinate with given multiplier

public Vec3f Mul(float multiplier)

Parameters

multiplier float

Returns

Vec3f

Negate()

public void Negate()

Normalize()

Turns the vector into a unit vector with length 1, but only if length is non-zero

public Vec3f Normalize()

Returns

Vec3f

NormalizedCopy()

Creates a new vectors that is the normalized version of this vector.

public Vec3f NormalizedCopy()

Returns

Vec3f

ReduceBy(float)

Substracts val from each coordinate if the coordinate if positive, otherwise it is added. If 0, the value is unchanged. The value must be a positive number

public void ReduceBy(float val)

Parameters

val float

Set(float, float, float)

Sets the vector to this coordinates

public Vec3f Set(float x, float y, float z)

Parameters

x float
y float
z float

Returns

Vec3f

Set(float[])

public Vec3f Set(float[] vec)

Parameters

vec float[]

Returns

Vec3f

Set(Vec3d)

Sets the vector to the coordinates of given vector

public Vec3f Set(Vec3d vec)

Parameters

vec Vec3d

Returns

Vec3f

Set(Vec3f)

Sets the vector to the coordinates of given vector

public void Set(Vec3f vec)

Parameters

vec Vec3f

Sub(Vec3f)

Substracts given x/y/z coordinates to the vector

public Vec3f Sub(Vec3f vec)

Parameters

vec Vec3f

Returns

Vec3f

Sub(Vec3i)

public Vec3f Sub(Vec3i vec)

Parameters

vec Vec3i

Returns

Vec3f

ToBytes(BinaryWriter)

public void ToBytes(BinaryWriter writer)

Parameters

writer BinaryWriter

ToDoubleArray()

public double[] ToDoubleArray()

Returns

double[]

ToString()

Simple string represenation of the x/y/z components

public override string ToString()

Returns

string

ToVec3d()

Creates a new double precision vector with the same coordinates

public Vec3d ToVec3d()

Returns

Vec3d

ToVec4f(float)

public Vec4f ToVec4f(float w)

Parameters

w float

Returns

Vec4f

Operators

operator +(Vec3f, float)

public static Vec3f operator +(Vec3f left, float right)

Parameters

left Vec3f
right float

Returns

Vec3f

operator +(Vec3f, Vec3f)

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

Parameters

left Vec3f
right Vec3f

Returns

Vec3f

operator /(Vec3f, float)

public static Vec3f operator /(Vec3f left, float right)

Parameters

left Vec3f
right float

Returns

Vec3f

operator ==(Vec3f, Vec3f)

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

Parameters

left Vec3f
right Vec3f

Returns

bool

operator !=(Vec3f, Vec3f)

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

Parameters

left Vec3f
right Vec3f

Returns

bool

operator *(float, Vec3f)

public static Vec3f operator *(float left, Vec3f right)

Parameters

left float
right Vec3f

Returns

Vec3f

operator *(Vec3f, float)

public static Vec3f operator *(Vec3f left, float right)

Parameters

left Vec3f
right float

Returns

Vec3f

operator *(Vec3f, Vec3f)

public static float operator *(Vec3f left, Vec3f right)

Parameters

left Vec3f
right Vec3f

Returns

float

operator -(float, Vec3f)

public static Vec3f operator -(float left, Vec3f right)

Parameters

left float
right Vec3f

Returns

Vec3f

operator -(Vec3f, float)

public static Vec3f operator -(Vec3f left, float right)

Parameters

left Vec3f
right float

Returns

Vec3f

operator -(Vec3f, Vec3f)

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

Parameters

left Vec3f
right Vec3f

Returns

Vec3f