SleakEngine 0.1.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
Vector3D & Normalize ()
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
Vector3D & operator+= (const Vector3D &other)
Vector3D operator- (const Vector3D &other) const
Vector3D & operator-= (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:418
Vector3D Normalized() const
Definition Vector.hpp:455
Vector3D Cross(const Vector3D &other) const
Definition Vector.hpp:422
float Magnitude() const
Definition Vector.hpp:431
static Vector3D Up()
Definition Vector.hpp:498
See also
Vector2D, Vector4D, Vector, Quaternion

Definition at line 354 of file Vector.hpp.

Constructor & Destructor Documentation

◆ Vector3D() [1/2]

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

Definition at line 357 of file Vector.hpp.

◆ Vector3D() [2/2]

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

Definition at line 358 of file Vector.hpp.

Member Function Documentation

◆ Add()

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

Definition at line 376 of file Vector.hpp.

◆ AddX()

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

Definition at line 373 of file Vector.hpp.

◆ AddY()

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

Definition at line 374 of file Vector.hpp.

◆ AddZ()

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

Definition at line 375 of file Vector.hpp.

◆ Backward()

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

Definition at line 503 of file Vector.hpp.

◆ BaseVector()

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

Definition at line 477 of file Vector.hpp.

◆ Cross()

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

Definition at line 422 of file Vector.hpp.

◆ Dot()

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

Definition at line 418 of file Vector.hpp.

◆ Down()

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

Definition at line 499 of file Vector.hpp.

◆ Forward()

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

Definition at line 502 of file Vector.hpp.

◆ GetX()

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

Definition at line 361 of file Vector.hpp.

◆ GetY()

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

Definition at line 362 of file Vector.hpp.

◆ GetZ()

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

Definition at line 363 of file Vector.hpp.

◆ Identity()

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

Definition at line 497 of file Vector.hpp.

◆ Left()

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

Definition at line 501 of file Vector.hpp.

◆ Magnitude()

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

Definition at line 431 of file Vector.hpp.

◆ Normalize()

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

Definition at line 436 of file Vector.hpp.

◆ Normalized()

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

Definition at line 455 of file Vector.hpp.

◆ operator!=()

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

Definition at line 468 of file Vector.hpp.

◆ operator*() [1/2]

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

Definition at line 408 of file Vector.hpp.

◆ operator*() [2/2]

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

Definition at line 404 of file Vector.hpp.

◆ operator+()

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

Definition at line 381 of file Vector.hpp.

◆ operator+=()

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

Definition at line 389 of file Vector.hpp.

◆ operator-()

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

Definition at line 385 of file Vector.hpp.

◆ operator-=()

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

Definition at line 396 of file Vector.hpp.

◆ operator/()

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

Definition at line 412 of file Vector.hpp.

◆ operator==()

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

Definition at line 462 of file Vector.hpp.

◆ Right()

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

Definition at line 500 of file Vector.hpp.

◆ Set()

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

Definition at line 369 of file Vector.hpp.

◆ SetX()

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

Definition at line 366 of file Vector.hpp.

◆ SetY()

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

Definition at line 367 of file Vector.hpp.

◆ SetZ()

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

Definition at line 368 of file Vector.hpp.

◆ ToArray()

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

Definition at line 492 of file Vector.hpp.

◆ ToString() [1/2]

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

Definition at line 481 of file Vector.hpp.

◆ ToString() [2/2]

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

Definition at line 485 of file Vector.hpp.

◆ Up()

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

Definition at line 498 of file Vector.hpp.

◆ Zero()

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

Definition at line 496 of file Vector.hpp.

◆ operator<<

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

Definition at line 472 of file Vector.hpp.