Clutter Engine 0.0.1
Loading...
Searching...
No Matches
Vector3 Struct Reference

A 3D vector structure. More...

#include <Vector3.h>

Public Member Functions

 Vector3 ()
 Default constructor. Initializes all components to zero.
 
 Vector3 (float pXYZ)
 Constructs a vector with all components set to the same value.
 
 Vector3 (Vector2 pXY)
 Constructs a vector from a Vector2, z is set to 0.
 
 Vector3 (float xP, float yP, float zP)
 Constructs a vector with specified x, y, and z values.
 
void Set (float xP, float yP, float zP)
 Sets the vector components.
 
float LengthSq () const
 Returns the squared length of the vector.
 
float Length () const
 Returns the length (magnitude) of the vector.
 
void Normalize ()
 Normalizes the vector in place.
 
const float * GetAsFloatPtr () const
 Returns a pointer to the vector's data as a float array.
 
float & operator[] (int index)
 Accesses a component by index.
 
const float & operator[] (int index) const
 Accesses a component by index (const).
 
Vector3operator/= (float scalar)
 Divides the vector by a scalar in place.
 
Vector3 operator- () const
 Negates the vector.
 
Vector3operator*= (float scalar)
 Multiplies the vector by a scalar in place.
 
Vector3operator+= (const Vector3 &right)
 Adds another vector to this vector in place.
 
Vector3operator-= (const Vector3 &right)
 Subtracts another vector from this vector in place.
 
Vector3 Normalized () const
 Returns a normalized copy of this vector.
 
Vector3 Abs () const
 Returns a vector with the absolute values of each component.
 
std::string ToString ()
 Returns a string representation of the vector.
 
Vector2 xy ()
 Returns the x and y components as a Vector2.
 
Vector2 xz ()
 Returns the x and z components as a Vector2.
 
Vector2 yz ()
 Returns the y and z components as a Vector2.
 
void Clamp (float minValue, float maxValue)
 Clamps the vector components to the given range in place.
 

Static Public Member Functions

static Vector3 Normalize (const Vector3 &vec)
 Returns a normalized copy of the provided vector.
 
static float Dot (const Vector3 &a, const Vector3 &b)
 Computes the dot product of two vectors.
 
static Vector3 Cross (const Vector3 &a, const Vector3 &b)
 Computes the cross product of two vectors.
 
static Vector3 Lerp (const Vector3 &a, const Vector3 &b, float f)
 Linearly interpolates between two vectors.
 
static Vector3 VInterp (const Vector3 &current, const Vector3 &target, float interpSpeed, float deltaTime=-1)
 Linearly interpolates between two vectors with speed and delta time.
 
static Vector3 Reflect (const Vector3 &v, const Vector3 &n)
 Reflects a vector about a normal.
 
static Vector3 Transform (Vector3 &vec, class Matrix4 &mat, float w=1.0f)
 Transforms a vector by a matrix.
 
static Vector3 TransformWithPerspDiv (Vector3 &vec, class Matrix4 &mat, float w=1.0f)
 Transforms the vector by a matrix and applies perspective division.
 
static Vector3 Transform (const Vector3 &v, const class Quaternion &q)
 Transforms a vector by a quaternion.
 
static Vector3 Clamp (const Vector3 &vec, float minValue, float maxValue)
 Clamps the vector components to the given range.
 

Public Attributes

float x = 0
 The x component of the vector.
 
float y = 0
 The y component of the vector.
 
float z = 0
 The z component of the vector.
 

Static Public Attributes

static const Vector3 Zero
 A vector with all components set to zero.
 
static const Vector3 One
 A vector with all components set to one.
 
static const Vector3 Up
 A vector pointing up (0, 1, 0).
 
static const Vector3 Down
 A vector pointing down (0, -1, 0).
 
static const Vector3 Left
 A vector pointing left (-1, 0, 0).
 
static const Vector3 Right
 A vector pointing right (1, 0, 0).
 
static const Vector3 Forward
 A vector pointing forward (0, 0, 1).
 
static const Vector3 Backward
 A vector pointing backward (0, 0, -1).
 
static const Vector3 Infinity
 A vector with all components set to positive infinity.
 
static const Vector3 NegInfinity
 A vector with all components set to negative infinity.
 

Friends

Vector3 operator+ (const Vector3 &a, const Vector3 &b)
 Adds two vectors.
 
Vector3 operator/ (const Vector3 &vec, float scalar)
 Divides a vector by a scalar.
 
Vector3 operator/ (const Vector3 &a, const Vector3 &b)
 Divides two vectors component-wise.
 
Vector3 operator- (const Vector3 &a, const Vector3 &b)
 Subtracts two vectors.
 
Vector3 operator* (const Vector3 &left, const Vector3 &right)
 Multiplies two vectors component-wise.
 
Vector3 operator* (const Vector3 &vec, float scalar)
 Multiplies a vector by a scalar.
 
Vector3 operator* (float scalar, const Vector3 &vec)
 Multiplies a scalar by a vector.
 
Vector3 Clamp (Vector3 temp, float minValue, float maxValue)
 Clamps the vector components to the given range.
 

Detailed Description

A 3D vector structure.

Constructor & Destructor Documentation

◆ Vector3() [1/3]

Vector3::Vector3 ( float pXYZ)
inline

Constructs a vector with all components set to the same value.

Parameters
pXYZThe value to set for x, y, and z.

◆ Vector3() [2/3]

Vector3::Vector3 ( Vector2 pXY)
inline

Constructs a vector from a Vector2, z is set to 0.

Parameters
pXYThe Vector2 to use for x and y.

◆ Vector3() [3/3]

Vector3::Vector3 ( float xP,
float yP,
float zP )
inline

Constructs a vector with specified x, y, and z values.

Parameters
xPThe x component.
yPThe y component.
zPThe z component.

Member Function Documentation

◆ Abs()

Vector3 Vector3::Abs ( ) const
inline

Returns a vector with the absolute values of each component.

Returns
The vector with absolute values.

◆ Clamp() [1/2]

static Vector3 Vector3::Clamp ( const Vector3 & vec,
float minValue,
float maxValue )
inlinestatic

Clamps the vector components to the given range.

Parameters
vecThe vector to clamp.
minValueThe minimum value.
maxValueThe maximum value.
Returns
The clamped vector.

◆ Clamp() [2/2]

void Vector3::Clamp ( float minValue,
float maxValue )
inline

Clamps the vector components to the given range in place.

Parameters
minValueThe minimum value.
maxValueThe maximum value.

◆ Cross()

static Vector3 Vector3::Cross ( const Vector3 & a,
const Vector3 & b )
inlinestatic

Computes the cross product of two vectors.

Parameters
aThe first vector.
bThe second vector.
Returns
The cross product.

◆ Dot()

static float Vector3::Dot ( const Vector3 & a,
const Vector3 & b )
inlinestatic

Computes the dot product of two vectors.

Parameters
aThe first vector.
bThe second vector.
Returns
The dot product.

◆ GetAsFloatPtr()

const float * Vector3::GetAsFloatPtr ( ) const
inline

Returns a pointer to the vector's data as a float array.

Returns
Pointer to the float array.

◆ Length()

float Vector3::Length ( ) const

Returns the length (magnitude) of the vector.

Returns
The length.

◆ LengthSq()

float Vector3::LengthSq ( ) const

Returns the squared length of the vector.

Returns
The squared length.

◆ Lerp()

static Vector3 Vector3::Lerp ( const Vector3 & a,
const Vector3 & b,
float f )
inlinestatic

Linearly interpolates between two vectors.

Parameters
aThe start vector.
bThe end vector.
fThe interpolation factor (0-1).
Returns
The interpolated vector.

◆ Normalize()

static Vector3 Vector3::Normalize ( const Vector3 & vec)
inlinestatic

Returns a normalized copy of the provided vector.

Parameters
vecThe vector to normalize.
Returns
The normalized vector.

◆ Normalized()

Vector3 Vector3::Normalized ( ) const
inline

Returns a normalized copy of this vector.

Returns
The normalized vector.

◆ operator*=()

Vector3 & Vector3::operator*= ( float scalar)
inline

Multiplies the vector by a scalar in place.

Parameters
scalarThe scalar value.
Returns
Reference to this vector.

◆ operator+=()

Vector3 & Vector3::operator+= ( const Vector3 & right)
inline

Adds another vector to this vector in place.

Parameters
rightThe vector to add.
Returns
Reference to this vector.

◆ operator-()

Vector3 Vector3::operator- ( ) const
inline

Negates the vector.

Returns
The negated vector.

◆ operator-=()

Vector3 & Vector3::operator-= ( const Vector3 & right)
inline

Subtracts another vector from this vector in place.

Parameters
rightThe vector to subtract.
Returns
Reference to this vector.

◆ operator/=()

Vector3 & Vector3::operator/= ( float scalar)
inline

Divides the vector by a scalar in place.

Parameters
scalarThe scalar value.
Returns
Reference to this vector.

◆ operator[]() [1/2]

float & Vector3::operator[] ( int index)
inline

Accesses a component by index.

Parameters
indexThe index (0=x, 1=y, 2=z).
Returns
Reference to the component.
Exceptions
std::out_of_rangeif index is not 0, 1, or 2.

◆ operator[]() [2/2]

const float & Vector3::operator[] ( int index) const
inline

Accesses a component by index (const).

Parameters
indexThe index (0=x, 1=y, 2=z).
Returns
Const reference to the component.
Exceptions
std::out_of_rangeif index is not 0, 1, or 2.

◆ Reflect()

static Vector3 Vector3::Reflect ( const Vector3 & v,
const Vector3 & n )
inlinestatic

Reflects a vector about a normal.

Parameters
vThe vector to reflect.
nThe normal vector (should be normalized).
Returns
The reflected vector.

◆ Set()

void Vector3::Set ( float xP,
float yP,
float zP )

Sets the vector components.

Parameters
xPThe x component.
yPThe y component.
zPThe z component.

◆ ToString()

std::string Vector3::ToString ( )
inline

Returns a string representation of the vector.

Returns
The string representation.

◆ Transform() [1/2]

static Vector3 Vector3::Transform ( const Vector3 & v,
const class Quaternion & q )
static

Transforms a vector by a quaternion.

Parameters
vThe vector to transform.
qThe quaternion.
Returns
The transformed vector.

◆ Transform() [2/2]

Vector3 Vector3::Transform ( Vector3 & vec,
class Matrix4 & mat,
float w = 1.0f )
static

Transforms a vector by a matrix.

Parameters
vecThe vector to transform.
matThe transformation matrix.
wThe w component (default 1.0f).
Returns
The transformed vector.

◆ TransformWithPerspDiv()

Vector3 Vector3::TransformWithPerspDiv ( Vector3 & vec,
class Matrix4 & mat,
float w = 1.0f )
static

Transforms the vector by a matrix and applies perspective division.

Parameters
vecThe vector to transform.
matThe transformation matrix.
wThe w component (default 1.0f).
Returns
The transformed vector.

◆ VInterp()

static Vector3 Vector3::VInterp ( const Vector3 & current,
const Vector3 & target,
float interpSpeed,
float deltaTime = -1 )
inlinestatic

Linearly interpolates between two vectors with speed and delta time.

Parameters
currentThe current vector.
targetThe target vector.
interpSpeedThe interpolation speed.
deltaTimeThe time step (optional).
Returns
The interpolated vector.

◆ xy()

Vector2 Vector3::xy ( )
inline

Returns the x and y components as a Vector2.

Returns
The Vector2 (x, y).

◆ xz()

Vector2 Vector3::xz ( )
inline

Returns the x and z components as a Vector2.

Returns
The Vector2 (x, z).

◆ yz()

Vector2 Vector3::yz ( )
inline

Returns the y and z components as a Vector2.

Returns
The Vector2 (y, z).

Friends And Related Symbol Documentation

◆ Clamp

Vector3 Clamp ( Vector3 temp,
float minValue,
float maxValue )
friend

Clamps the vector components to the given range.

Parameters
tempThe vector to clamp.
minValueThe minimum value.
maxValueThe maximum value.
Returns
The clamped vector.

◆ operator* [1/3]

Vector3 operator* ( const Vector3 & left,
const Vector3 & right )
friend

Multiplies two vectors component-wise.

Parameters
leftThe first vector.
rightThe second vector.
Returns
The result of the multiplication.

◆ operator* [2/3]

Vector3 operator* ( const Vector3 & vec,
float scalar )
friend

Multiplies a vector by a scalar.

Parameters
vecThe vector.
scalarThe scalar value.
Returns
The scaled vector.

◆ operator* [3/3]

Vector3 operator* ( float scalar,
const Vector3 & vec )
friend

Multiplies a scalar by a vector.

Parameters
scalarThe scalar value.
vecThe vector.
Returns
The scaled vector.

◆ operator+

Vector3 operator+ ( const Vector3 & a,
const Vector3 & b )
friend

Adds two vectors.

Parameters
aThe first vector.
bThe second vector.
Returns
The sum of the vectors.

◆ operator-

Vector3 operator- ( const Vector3 & a,
const Vector3 & b )
friend

Subtracts two vectors.

Parameters
aThe first vector.
bThe second vector.
Returns
The difference of the vectors.

◆ operator/ [1/2]

Vector3 operator/ ( const Vector3 & a,
const Vector3 & b )
friend

Divides two vectors component-wise.

Parameters
aThe numerator vector.
bThe denominator vector.
Returns
The result of the division.

◆ operator/ [2/2]

Vector3 operator/ ( const Vector3 & vec,
float scalar )
friend

Divides a vector by a scalar.

Parameters
vecThe vector.
scalarThe scalar value.
Returns
The scaled vector.

The documentation for this struct was generated from the following files: