Claire's Game Engine
Full C++ Engine using OpenGL
Loading...
Searching...
No Matches
Vector4 Struct Reference

Vector4 is a 4D vector class used in graphics, math, and color representations. It supports arithmetic, normalization, dot/cross products, and interpolation. More...

#include <Vector4.h>

Public Member Functions

 Vector4 ()
 Default constructor. Initializes components to zero.
 
 Vector4 (float x, float y, float z, float w)
 Constructor with individual components.
 
 Vector4 (Vector3 vec3, float w=0)
 Constructs a Vector4 from a Vector3 and a w component.
 
float Magnitude () const
 Computes the magnitude (length) of the vector.
 
float MagnitudeSqr () const
 Computes the squared magnitude of the vector.
 
void Normalize ()
 Normalizes the vector to unit length.
 
std::string ToString () const
 Converts the vector to a readable string format.
 
const float * GetAsFloatPtr () const
 Gets a float pointer to the vector's data.
 
float & operator[] (int i)
 Accesses a component by index (0 = x, 1 = y, 2 = z, 3 = w).
 
Vector4operator*= (float scalar)
 
Vector4operator+= (const Vector4 &right)
 
Vector4operator-= (const Vector4 &right)
 

Static Public Member Functions

static Vector4 Normalize (const Vector4 &vec)
 Returns a normalized copy of the input vector.
 
static float Dot (const Vector4 &a, const Vector4 &b)
 Computes the dot product between two vectors.
 
static Vector4 Cross (const Vector4 &a, const Vector4 &b)
 Computes the 3D cross product of two vectors (ignores w).
 
static Vector4 Lerp (const Vector4 &a, const Vector4 &b, float f)
 Linearly interpolates between two vectors.
 
static Vector4 Reflect (const Vector4 &v, const Vector4 &n)
 Reflects a vector across a normal vector.
 

Public Attributes

float x = 0
 
float y = 0
 
float z = 0
 
float w = 0
 

Static Public Attributes

static const Vector4 ZERO
 
static const Vector4 ONE
 

Friends

class Matrix4
 
Vector4 operator+ (const Vector4 &a, const Vector4 &b)
 
Vector4 operator- (const Vector4 &a, const Vector4 &b)
 
Vector4 operator* (const Vector4 &left, const Vector4 &right)
 
Vector4 operator* (const Vector4 &vec, float scalar)
 
Vector4 operator* (float scalar, const Vector4 &vec)
 

Detailed Description

Vector4 is a 4D vector class used in graphics, math, and color representations. It supports arithmetic, normalization, dot/cross products, and interpolation.

Constructor & Destructor Documentation

◆ Vector4() [1/3]

Vector4::Vector4 ( )

Default constructor. Initializes components to zero.

◆ Vector4() [2/3]

Vector4::Vector4 ( float x,
float y,
float z,
float w )

Constructor with individual components.

Parameters
xX component.
yY component.
zZ component.
wW component.

◆ Vector4() [3/3]

Vector4::Vector4 ( Vector3 vec3,
float w = 0 )

Constructs a Vector4 from a Vector3 and a w component.

Parameters
vec3The 3D vector to use for x, y, z.
wThe w component (default: 0.0f).

Member Function Documentation

◆ Cross()

Vector4 Vector4::Cross ( const Vector4 & a,
const Vector4 & b )
static

Computes the 3D cross product of two vectors (ignores w).

Parameters
aFirst vector.
bSecond vector.
Returns
Resulting vector from cross product (w = 0).

◆ Dot()

float Vector4::Dot ( const Vector4 & a,
const Vector4 & b )
static

Computes the dot product between two vectors.

Parameters
aFirst vector.
bSecond vector.
Returns
Dot product result.

◆ GetAsFloatPtr()

const float * Vector4::GetAsFloatPtr ( ) const

Gets a float pointer to the vector's data.

Returns
Pointer to the first component (x).

◆ Lerp()

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

Linearly interpolates between two vectors.

Parameters
aStart vector.
bEnd vector.
fInterpolation factor (0.0 to 1.0).
Returns
Interpolated vector.

◆ Magnitude()

float Vector4::Magnitude ( ) const

Computes the magnitude (length) of the vector.

Returns
Magnitude of the vector.

◆ MagnitudeSqr()

float Vector4::MagnitudeSqr ( ) const

Computes the squared magnitude of the vector.

Returns
Squared magnitude.

◆ Normalize() [1/2]

void Vector4::Normalize ( )

Normalizes the vector to unit length.

◆ Normalize() [2/2]

Vector4 Vector4::Normalize ( const Vector4 & vec)
static

Returns a normalized copy of the input vector.

Parameters
vecVector to normalize.
Returns
Normalized vector.

◆ operator*=()

Vector4 & Vector4::operator*= ( float scalar)

◆ operator+=()

Vector4 & Vector4::operator+= ( const Vector4 & right)

◆ operator-=()

Vector4 & Vector4::operator-= ( const Vector4 & right)

◆ operator[]()

float & Vector4::operator[] ( int i)

Accesses a component by index (0 = x, 1 = y, 2 = z, 3 = w).

Parameters
iIndex of the component.
Returns
Reference to the component.

◆ Reflect()

Vector4 Vector4::Reflect ( const Vector4 & v,
const Vector4 & n )
static

Reflects a vector across a normal vector.

Parameters
vIncoming vector.
nNormal vector (should be normalized).
Returns
Reflected vector.

◆ ToString()

std::string Vector4::ToString ( ) const

Converts the vector to a readable string format.

Returns
String in format (x , y , z , w).

Friends And Related Symbol Documentation

◆ Matrix4

friend class Matrix4
friend

◆ operator* [1/3]

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

◆ operator* [2/3]

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

◆ operator* [3/3]

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

◆ operator+

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

◆ operator-

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

Member Data Documentation

◆ ONE

const Vector4 Vector4::ONE
static

◆ w

float Vector4::w = 0

◆ x

float Vector4::x = 0

◆ y

float Vector4::y = 0

◆ z

float Vector4::z = 0

◆ ZERO

const Vector4 Vector4::ZERO
static

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