My Project
Loading...
Searching...
No Matches
Maths::Vec3< T > Class Template Reference

A 3D vector class template for mathematical operations. More...

#include <MVec3.hpp>

Public Member Functions

 Vec3 (T m_x, T m_y, T m_z)
 Ensure that T is an arithmetic type (float, double, int, etc.).
 Vec3 ()=default
 Default constructor (initializes components to zero).
 ~Vec3 ()=default
 Destructor.
x () const
 Returns the x-component.
y () const
 Returns the y-component.
z () const
 Returns the z-component.
void SetX (T newX)
 Sets the x-component.
void SetY (T newY)
 Sets the y-component.
void SetZ (T newZ)
 Sets the z-component.
void Set (T newX, T newY, T newZ)
 Sets all three components.
Vec3 Normalized () const
 Returns a normalized vector (unit length).
SqrtMagnitude () const
 Returns the squared magnitude of the vector.
Magnitude () const
 Returns the magnitude (length) of the vector.
This (int i) const
 Returns the component at index i (0=x, 1=y, 2=z).
bool Equal (const Vec3 &other) const
 Checks if this vector is equal to another vector.
std::string ToString () const
 Converts the vector to a string representation.
void Normalize ()
 Normalizes the vector in place.
Vec3 operator- (const Vec3 &other) const
 Subtracts another vector from this vector.
Vec3 operator+ (const Vec3 &other) const
 Adds another vector to this vector.
Vec3 operator* (const Vec3 &other) const
 Component-wise multiplication.
Vec3 operator* (T scalar) const
 Multiplies the vector by a scalar.
Vec3 operator/ (const Vec3 &other) const
 Component-wise division.
Vec3 operator/ (T scalar) const
 Divides the vector by a scalar.
bool operator== (const Vec3 &other) const
 Checks equality between two vectors.
bool operator!= (const Vec3 &other) const
 Checks inequality between two vectors.

Static Public Member Functions

static Vec3 Down ()
 Returns a vector pointing down (0, -1, 0).
static Vec3 Up ()
 Returns a vector pointing up (0, 1, 0).
static Vec3 Left ()
 Returns a vector pointing left (-1, 0, 0).
static Vec3 Right ()
 Returns a vector pointing right (1, 0, 0).
static Vec3 Back ()
 Returns a vector pointing back (0, 0, -1).
static Vec3 Forward ()
 Returns a vector pointing forward (0, 0, 1).
static Vec3 One ()
 Returns a vector with all components equal to 1.
static Vec3 Zero ()
 Returns a zero vector (0, 0, 0).
static Vec3 PositiveInfinity ()
 Returns a vector with all components set to positive infinity.
static Vec3 NegativeInfinity ()
 Returns a vector with all components set to negative infinity.
static Vec3 RotateTowards (const Vec3 &current, const Vec3 &target, const T maxRadiansDelta, const T maxMagnitudeDelta)
 Rotates a vector towards a target vector by a maximum radians delta and magnitude delta.
static Vec3 MoveTowards (const Vec3 &current, const Vec3 &target, const T maxDistanceDelta)
 Moves a vector towards a target vector by a maximum distance.
static Vec3 ProjectOnPlane (const Vec3 &vector, const Vec3 &planeNormal)
 Projects a vector onto a plane defined by its normal.
static Vec3 Reflect (const Vec3 &inDirection, const Vec3 &inNormal)
 Reflects a vector off a plane defined by a normal.
static Vec3 ClampMagnitude (const Vec3 &a, const T MaxLength)
 Clamps the magnitude of a vector to a maximum length.
static Vec3 SlerpUnclamped (const Vec3 &a, const Vec3 &b, const T t)
 Spherical linear interpolation (unclamped) between two vectors.
static Vec3 Project (const Vec3 &vector, const Vec3 &onNormal)
 Projects a vector onto another vector.
static Vec3 LerpUnclamped (const Vec3 &a, const Vec3 &b, const T t)
 Linear interpolation (unclamped) between two vectors.
static Vec3 Slerp (const Vec3 &a, const Vec3 &b, const T t)
 Spherical linear interpolation (clamped) between two vectors.
static Vec3 Lerp (const Vec3 &a, const Vec3 &b, const T t)
 Linear interpolation (clamped) between two vectors.
static Vec3 Scale (const Vec3 &a, const Vec3 &b)
 Component-wise multiplication of two vectors.
static Vec3 Cross (const Vec3 &a, const Vec3 &b)
 Cross product of two vectors.
static Vec3 Min (const Vec3 &a, const Vec3 &b)
 Component-wise minimum of two vectors.
static Vec3 Max (const Vec3 &a, const Vec3 &b)
 Component-wise maximum of two vectors.
static T SignedAngle (const Vec3 &from, const Vec3 &to, const Vec3 &axis)
 Computes the signed angle between two vectors around a specified axis.
static T Distance (const Vec3 &a, const Vec3 &b)
 Calculates distance between two vectors.
static T Angle (const Vec3 &a, const Vec3 &b)
 Calculates angle between two vectors.
static T Dot (const Vec3 &a, const Vec3 &b)
 Dot product of two vectors.
static void OrthoNormalize (Vec3 &normal, Vec3 &tangent)
 Orthonormalizes two vectors (normal and tangent).

Public Attributes

m_x
 X component of the vector.
m_y
 Y component of the vector.
m_z
 Z component of the vector.

Detailed Description

template<typename T = float>
class Maths::Vec3< T >

A 3D vector class template for mathematical operations.

Template Parameters
TThe numeric type (e.g., float, double, int).

Constructor & Destructor Documentation

◆ Vec3() [1/2]

template<typename T = float>
Maths::Vec3< T >::Vec3 ( T m_x,
T m_y,
T m_z )

Ensure that T is an arithmetic type (float, double, int, etc.).

Constructs a vector with the given x, y, z components.

Parameters
m_xThe x-component.
m_yThe y-component.
m_zThe z-component.

◆ Vec3() [2/2]

template<typename T = float>
Maths::Vec3< T >::Vec3 ( )
default

Default constructor (initializes components to zero).

◆ ~Vec3()

template<typename T = float>
Maths::Vec3< T >::~Vec3 ( )
default

Destructor.

Member Function Documentation

◆ Angle()

template<typename T = float>
T Maths::Vec3< T >::Angle ( const Vec3< T > & a,
const Vec3< T > & b )
static

Calculates angle between two vectors.

◆ Back()

template<typename T = float>
Vec3 Maths::Vec3< T >::Back ( )
static

Returns a vector pointing back (0, 0, -1).

◆ ClampMagnitude()

template<typename T = float>
Vec3 Maths::Vec3< T >::ClampMagnitude ( const Vec3< T > & a,
const T MaxLength )
static

Clamps the magnitude of a vector to a maximum length.

◆ Cross()

template<typename T = float>
Vec3 Maths::Vec3< T >::Cross ( const Vec3< T > & a,
const Vec3< T > & b )
static

Cross product of two vectors.

◆ Distance()

template<typename T = float>
T Maths::Vec3< T >::Distance ( const Vec3< T > & a,
const Vec3< T > & b )
static

Calculates distance between two vectors.

◆ Dot()

template<typename T = float>
T Maths::Vec3< T >::Dot ( const Vec3< T > & a,
const Vec3< T > & b )
static

Dot product of two vectors.

◆ Down()

template<typename T = float>
Vec3 Maths::Vec3< T >::Down ( )
static

Returns a vector pointing down (0, -1, 0).

◆ Equal()

template<typename T = float>
bool Maths::Vec3< T >::Equal ( const Vec3< T > & other) const

Checks if this vector is equal to another vector.

Parameters
otherThe vector to compare.
Returns
True if equal, otherwise false.

◆ Forward()

template<typename T = float>
Vec3 Maths::Vec3< T >::Forward ( )
static

Returns a vector pointing forward (0, 0, 1).

◆ Left()

template<typename T = float>
Vec3 Maths::Vec3< T >::Left ( )
static

Returns a vector pointing left (-1, 0, 0).

◆ Lerp()

template<typename T = float>
Vec3 Maths::Vec3< T >::Lerp ( const Vec3< T > & a,
const Vec3< T > & b,
const T t )
static

Linear interpolation (clamped) between two vectors.

◆ LerpUnclamped()

template<typename T = float>
Vec3 Maths::Vec3< T >::LerpUnclamped ( const Vec3< T > & a,
const Vec3< T > & b,
const T t )
static

Linear interpolation (unclamped) between two vectors.

◆ Magnitude()

template<typename T = float>
T Maths::Vec3< T >::Magnitude ( ) const

Returns the magnitude (length) of the vector.

Returns
Magnitude.

◆ Max()

template<typename T = float>
Vec3 Maths::Vec3< T >::Max ( const Vec3< T > & a,
const Vec3< T > & b )
static

Component-wise maximum of two vectors.

◆ Min()

template<typename T = float>
Vec3 Maths::Vec3< T >::Min ( const Vec3< T > & a,
const Vec3< T > & b )
static

Component-wise minimum of two vectors.

◆ MoveTowards()

template<typename T = float>
Vec3 Maths::Vec3< T >::MoveTowards ( const Vec3< T > & current,
const Vec3< T > & target,
const T maxDistanceDelta )
static

Moves a vector towards a target vector by a maximum distance.

◆ NegativeInfinity()

template<typename T = float>
Vec3 Maths::Vec3< T >::NegativeInfinity ( )
static

Returns a vector with all components set to negative infinity.

◆ Normalize()

template<typename T = float>
void Maths::Vec3< T >::Normalize ( )

Normalizes the vector in place.

◆ Normalized()

template<typename T = float>
Vec3 Maths::Vec3< T >::Normalized ( ) const

Returns a normalized vector (unit length).

Returns
Normalized vector.

◆ One()

template<typename T = float>
Vec3 Maths::Vec3< T >::One ( )
static

Returns a vector with all components equal to 1.

◆ operator!=()

template<typename T = float>
bool Maths::Vec3< T >::operator!= ( const Vec3< T > & other) const

Checks inequality between two vectors.

◆ operator*() [1/2]

template<typename T = float>
Vec3 Maths::Vec3< T >::operator* ( const Vec3< T > & other) const

Component-wise multiplication.

◆ operator*() [2/2]

template<typename T = float>
Vec3 Maths::Vec3< T >::operator* ( T scalar) const

Multiplies the vector by a scalar.

◆ operator+()

template<typename T = float>
Vec3 Maths::Vec3< T >::operator+ ( const Vec3< T > & other) const

Adds another vector to this vector.

◆ operator-()

template<typename T = float>
Vec3 Maths::Vec3< T >::operator- ( const Vec3< T > & other) const

Subtracts another vector from this vector.

◆ operator/() [1/2]

template<typename T = float>
Vec3 Maths::Vec3< T >::operator/ ( const Vec3< T > & other) const

Component-wise division.

◆ operator/() [2/2]

template<typename T = float>
Vec3 Maths::Vec3< T >::operator/ ( T scalar) const

Divides the vector by a scalar.

◆ operator==()

template<typename T = float>
bool Maths::Vec3< T >::operator== ( const Vec3< T > & other) const

Checks equality between two vectors.

◆ OrthoNormalize()

template<typename T = float>
void Maths::Vec3< T >::OrthoNormalize ( Vec3< T > & normal,
Vec3< T > & tangent )
static

Orthonormalizes two vectors (normal and tangent).

◆ PositiveInfinity()

template<typename T = float>
Vec3 Maths::Vec3< T >::PositiveInfinity ( )
static

Returns a vector with all components set to positive infinity.

◆ Project()

template<typename T = float>
Vec3 Maths::Vec3< T >::Project ( const Vec3< T > & vector,
const Vec3< T > & onNormal )
static

Projects a vector onto another vector.

◆ ProjectOnPlane()

template<typename T = float>
Vec3 Maths::Vec3< T >::ProjectOnPlane ( const Vec3< T > & vector,
const Vec3< T > & planeNormal )
static

Projects a vector onto a plane defined by its normal.

◆ Reflect()

template<typename T = float>
Vec3 Maths::Vec3< T >::Reflect ( const Vec3< T > & inDirection,
const Vec3< T > & inNormal )
static

Reflects a vector off a plane defined by a normal.

◆ Right()

template<typename T = float>
Vec3 Maths::Vec3< T >::Right ( )
static

Returns a vector pointing right (1, 0, 0).

◆ RotateTowards()

template<typename T = float>
Vec3 Maths::Vec3< T >::RotateTowards ( const Vec3< T > & current,
const Vec3< T > & target,
const T maxRadiansDelta,
const T maxMagnitudeDelta )
static

Rotates a vector towards a target vector by a maximum radians delta and magnitude delta.

◆ Scale()

template<typename T = float>
Vec3 Maths::Vec3< T >::Scale ( const Vec3< T > & a,
const Vec3< T > & b )
static

Component-wise multiplication of two vectors.

◆ Set()

template<typename T = float>
void Maths::Vec3< T >::Set ( T newX,
T newY,
T newZ )
inline

Sets all three components.

Parameters
newXNew x-component.
newYNew y-component.
newZNew z-component.

◆ SetX()

template<typename T = float>
void Maths::Vec3< T >::SetX ( T newX)
inline

Sets the x-component.

Parameters
newXThe new x value.

◆ SetY()

template<typename T = float>
void Maths::Vec3< T >::SetY ( T newY)
inline

Sets the y-component.

Parameters
newYThe new y value.

◆ SetZ()

template<typename T = float>
void Maths::Vec3< T >::SetZ ( T newZ)
inline

Sets the z-component.

Parameters
newZThe new z value.

◆ SignedAngle()

template<typename T = float>
T Maths::Vec3< T >::SignedAngle ( const Vec3< T > & from,
const Vec3< T > & to,
const Vec3< T > & axis )
static

Computes the signed angle between two vectors around a specified axis.

◆ Slerp()

template<typename T = float>
Vec3 Maths::Vec3< T >::Slerp ( const Vec3< T > & a,
const Vec3< T > & b,
const T t )
static

Spherical linear interpolation (clamped) between two vectors.

◆ SlerpUnclamped()

template<typename T = float>
Vec3 Maths::Vec3< T >::SlerpUnclamped ( const Vec3< T > & a,
const Vec3< T > & b,
const T t )
static

Spherical linear interpolation (unclamped) between two vectors.

◆ SqrtMagnitude()

template<typename T = float>
T Maths::Vec3< T >::SqrtMagnitude ( ) const

Returns the squared magnitude of the vector.

Returns
Squared magnitude.

◆ This()

template<typename T = float>
T Maths::Vec3< T >::This ( int i) const

Returns the component at index i (0=x, 1=y, 2=z).

Parameters
iIndex of component.
Returns
Component value.

◆ ToString()

template<typename T = float>
std::string Maths::Vec3< T >::ToString ( ) const

Converts the vector to a string representation.

Returns
A string representing the vector.

◆ Up()

template<typename T = float>
Vec3 Maths::Vec3< T >::Up ( )
static

Returns a vector pointing up (0, 1, 0).

◆ x()

template<typename T = float>
T Maths::Vec3< T >::x ( ) const
inline

Returns the x-component.

Returns
The x-component.

◆ y()

template<typename T = float>
T Maths::Vec3< T >::y ( ) const
inline

Returns the y-component.

Returns
The y-component.

◆ z()

template<typename T = float>
T Maths::Vec3< T >::z ( ) const
inline

Returns the z-component.

Returns
The z-component.

◆ Zero()

template<typename T = float>
Vec3 Maths::Vec3< T >::Zero ( )
static

Returns a zero vector (0, 0, 0).

Member Data Documentation

◆ m_x

template<typename T = float>
T Maths::Vec3< T >::m_x

X component of the vector.

◆ m_y

template<typename T = float>
T Maths::Vec3< T >::m_y

Y component of the vector.

◆ m_z

template<typename T = float>
T Maths::Vec3< T >::m_z

Z component of the vector.


The documentation for this class was generated from the following file: