vec3 class by value built-in

Three-dimensional vector with floating-point components

Constructors

vec3(const vec3&in)
Creates a copy of another vector
vec3(const vec3i&in)
Creates a vector from an integer vector
vec3(float, float, float)
Creates a vector from X, Y and Z components
vec3(int, int, int)
Creates a vector from integer X, Y and Z components

Functions

void normalize()
Scales the vector in place to a length of 1
vec3 normalized() const
Returns a copy of the vector scaled to a length of 1

Operators

vec3 opAdd(const vec3&in) const +
Adds two vectors
vec3& opAddAssign(const vec3&in) +=
Adds another vector in place
vec3& opAssign(const vec3&in) =
Copies another vector
vec3 opDiv(float) const /
Divides every component by a number
vec3 opDiv(const vec3&in) const /
Divides the vectors component by component
vec3& opDivAssign(float) /=
Divides every component by a number in place
vec3& opDivAssign(const vec3&in) /=
Divides by another vector component by component in place
bool opEquals(const vec3&in) const ==
Returns whether all components are exactly equal
vec3 opMul(float) const *
Multiplies every component by a number
vec3 opMul(const vec3&in) const *
Multiplies the vectors component by component
vec3& opMulAssign(float) *=
Multiplies every component by a number in place
vec3& opMulAssign(const vec3&in) *=
Multiplies by another vector component by component in place
vec3 opNeg() const -x
Returns the vector with all components negated
vec3 opSub(const vec3&in) const -
Subtracts two vectors
vec3& opSubAssign(const vec3&in) -=
Subtracts another vector in place

Properties

float length read-only
Length of the vector
float lengthSquared read-only
Squared length of the vector
float x
X component
float y
Y component
float z
Z component

Function documentation

void vec3::normalize()

Scales the vector in place to a length of 1

A zero-length vector becomes NaN in all components.

vec3 vec3::normalized() const

Returns a copy of the vector scaled to a length of 1

A zero-length vector gives NaN in all components.

Operator documentation

bool vec3::opEquals(const vec3&in) const ==

Returns whether all components are exactly equal

Use closeTo() on the components to allow for rounding errors.

Property documentation

float vec3::lengthSquared read-only

Squared length of the vector

Cheaper than the length, useful for comparing distances.