SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::Math::Vector3D Class Reference

#include <Vector.hpp>

Public Member Functions

 Vector3D ()
 Vector3D (float x, float y, float z)
void Add (float x, float y, float z)
void AddX (float val)
void AddY (float val)
void AddZ (float val)
Vector< float, 3 > BaseVector ()
Vector3D Cross (const Vector3D &other) const
float Dot (const Vector3D &other) const
float GetX () const
float GetY () const
float GetZ () const
float Magnitude () const
Vector3DNormalize ()
Vector3D Normalized () const
bool operator!= (const Vector3D &other) const
Vector3D operator* (const Vector3D &other) const
Vector3D operator* (float scalar) const
Vector3D operator+ (const Vector3D &other) const
Vector3Doperator+= (const Vector3D &other)
Vector3D operator- (const Vector3D &other) const
Vector3Doperator-= (const Vector3D &other)
Vector3D operator/ (float scalar) const
bool operator== (const Vector3D &other) const
void Set (float x, float y, float z)
void SetX (float val)
void SetY (float val)
void SetZ (float val)
float * ToArray ()
std::string ToString () const
std::string ToString (uint8_t precision) const

Static Public Member Functions

static Vector3D Backward ()
static Vector3D Down ()
static Vector3D Forward ()
static Vector3D Identity ()
static Vector3D Left ()
static Vector3D Right ()
static Vector3D Up ()
static Vector3D Zero ()

Friends

std::ostream & operator<< (std::ostream &os, const Vector3D &vec)

Detailed Description

Three-component float vector: the workhorse type for positions, directions, scales, normals, and velocities across the engine.

Wraps Vector<float, 3> with named accessors, full arithmetic, and the geometric operations you need day to day: Dot(), Cross(), Magnitude(), Normalize() (in place) and Normalized() (returns a copy). Note that operator* with another Vector3D is componentwise, not a dot or cross product.

Named constants cover the axis directions: Zero(), Identity(), Up(), Down(), Left(), Right(), Forward(), and Backward().

Vector3D camPos(-5.0f, 3.0f, -5.0f);
Vector3D target(0.0f, 0.0f, 0.0f);
Vector3D forward = (target - camPos).Normalized();
float distance = (target - camPos).Magnitude();
// Build a right vector from forward and world up
Vector3D right = forward.Cross(Vector3D::Up()).Normalized();
// Facing test: positive means the target is in front
bool inFront = forward.Dot(target - camPos) > 0.0f;
// Move along a direction
camPos += forward * (speed * deltaTime);
float Dot(const Vector3D &other) const
Definition Vector.hpp:417
Vector3D Normalized() const
Definition Vector.hpp:454
Vector3D Cross(const Vector3D &other) const
Definition Vector.hpp:421
float Magnitude() const
Definition Vector.hpp:430
static Vector3D Up()
Definition Vector.hpp:497
See also
Vector2D, Vector4D, Vector, Quaternion

Definition at line 353 of file Vector.hpp.

Constructor & Destructor Documentation

◆ Vector3D() [1/2]

Sleak::Math::Vector3D::Vector3D ( )
inline

Definition at line 356 of file Vector.hpp.

◆ Vector3D() [2/2]

Sleak::Math::Vector3D::Vector3D ( float x,
float y,
float z )
inline

Definition at line 357 of file Vector.hpp.

Member Function Documentation

◆ Add()

void Sleak::Math::Vector3D::Add ( float x,
float y,
float z )
inline

Definition at line 375 of file Vector.hpp.

◆ AddX()

void Sleak::Math::Vector3D::AddX ( float val)
inline

Definition at line 372 of file Vector.hpp.

◆ AddY()

void Sleak::Math::Vector3D::AddY ( float val)
inline

Definition at line 373 of file Vector.hpp.

◆ AddZ()

void Sleak::Math::Vector3D::AddZ ( float val)
inline

Definition at line 374 of file Vector.hpp.

◆ Backward()

Vector3D Sleak::Math::Vector3D::Backward ( )
inlinestatic

Definition at line 502 of file Vector.hpp.

◆ BaseVector()

Vector< float, 3 > Sleak::Math::Vector3D::BaseVector ( )
inline

Definition at line 476 of file Vector.hpp.

◆ Cross()

Vector3D Sleak::Math::Vector3D::Cross ( const Vector3D & other) const
inline

Definition at line 421 of file Vector.hpp.

◆ Dot()

float Sleak::Math::Vector3D::Dot ( const Vector3D & other) const
inline

Definition at line 417 of file Vector.hpp.

◆ Down()

Vector3D Sleak::Math::Vector3D::Down ( )
inlinestatic

Definition at line 498 of file Vector.hpp.

◆ Forward()

Vector3D Sleak::Math::Vector3D::Forward ( )
inlinestatic

Definition at line 501 of file Vector.hpp.

◆ GetX()

float Sleak::Math::Vector3D::GetX ( ) const
inline

Definition at line 360 of file Vector.hpp.

◆ GetY()

float Sleak::Math::Vector3D::GetY ( ) const
inline

Definition at line 361 of file Vector.hpp.

◆ GetZ()

float Sleak::Math::Vector3D::GetZ ( ) const
inline

Definition at line 362 of file Vector.hpp.

◆ Identity()

Vector3D Sleak::Math::Vector3D::Identity ( )
inlinestatic

Definition at line 496 of file Vector.hpp.

◆ Left()

Vector3D Sleak::Math::Vector3D::Left ( )
inlinestatic

Definition at line 500 of file Vector.hpp.

◆ Magnitude()

float Sleak::Math::Vector3D::Magnitude ( ) const
inline

Definition at line 430 of file Vector.hpp.

◆ Normalize()

Vector3D & Sleak::Math::Vector3D::Normalize ( )
inline

Definition at line 435 of file Vector.hpp.

◆ Normalized()

Vector3D Sleak::Math::Vector3D::Normalized ( ) const
inline

Definition at line 454 of file Vector.hpp.

◆ operator!=()

bool Sleak::Math::Vector3D::operator!= ( const Vector3D & other) const
inline

Definition at line 467 of file Vector.hpp.

◆ operator*() [1/2]

Vector3D Sleak::Math::Vector3D::operator* ( const Vector3D & other) const
inline

Definition at line 407 of file Vector.hpp.

◆ operator*() [2/2]

Vector3D Sleak::Math::Vector3D::operator* ( float scalar) const
inline

Definition at line 403 of file Vector.hpp.

◆ operator+()

Vector3D Sleak::Math::Vector3D::operator+ ( const Vector3D & other) const
inline

Definition at line 380 of file Vector.hpp.

◆ operator+=()

Vector3D & Sleak::Math::Vector3D::operator+= ( const Vector3D & other)
inline

Definition at line 388 of file Vector.hpp.

◆ operator-()

Vector3D Sleak::Math::Vector3D::operator- ( const Vector3D & other) const
inline

Definition at line 384 of file Vector.hpp.

◆ operator-=()

Vector3D & Sleak::Math::Vector3D::operator-= ( const Vector3D & other)
inline

Definition at line 395 of file Vector.hpp.

◆ operator/()

Vector3D Sleak::Math::Vector3D::operator/ ( float scalar) const
inline

Definition at line 411 of file Vector.hpp.

◆ operator==()

bool Sleak::Math::Vector3D::operator== ( const Vector3D & other) const
inline

Definition at line 461 of file Vector.hpp.

◆ Right()

Vector3D Sleak::Math::Vector3D::Right ( )
inlinestatic

Definition at line 499 of file Vector.hpp.

◆ Set()

void Sleak::Math::Vector3D::Set ( float x,
float y,
float z )
inline

Definition at line 368 of file Vector.hpp.

◆ SetX()

void Sleak::Math::Vector3D::SetX ( float val)
inline

Definition at line 365 of file Vector.hpp.

◆ SetY()

void Sleak::Math::Vector3D::SetY ( float val)
inline

Definition at line 366 of file Vector.hpp.

◆ SetZ()

void Sleak::Math::Vector3D::SetZ ( float val)
inline

Definition at line 367 of file Vector.hpp.

◆ ToArray()

float * Sleak::Math::Vector3D::ToArray ( )
inline

Definition at line 491 of file Vector.hpp.

◆ ToString() [1/2]

std::string Sleak::Math::Vector3D::ToString ( ) const
inline

Definition at line 480 of file Vector.hpp.

◆ ToString() [2/2]

std::string Sleak::Math::Vector3D::ToString ( uint8_t precision) const
inline

Definition at line 484 of file Vector.hpp.

◆ Up()

Vector3D Sleak::Math::Vector3D::Up ( )
inlinestatic

Definition at line 497 of file Vector.hpp.

◆ Zero()

Vector3D Sleak::Math::Vector3D::Zero ( )
inlinestatic

Definition at line 495 of file Vector.hpp.

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const Vector3D & vec )
friend

Definition at line 471 of file Vector.hpp.