PURE API 0.5
PR00F's Ultimate Rendering Engine full documentation
Loading...
Searching...
No Matches
PureVector Class Reference

Pure 3D-vector class. More...

Detailed Description

Pure 3D-vector class.

Pure uses the left-handed Cartesian coordinate system. This means the XZ plane is horizontal, the XY and and YZ planes are vertical, a positive X value means right, a positive Y value means up, and a positive Z value means forward.

Definition at line 23 of file PureVector.h.

#include <PureVector.h>

Public Member Functions

 PureVector ()
 Creates a vector containing zeros.
 
 PureVector (const PureVector &vec)
 Creates a nullvector.
 
 PureVector (const TPureFloat &x, const TPureFloat &y, const TPureFloat &z)
 Creates a vector containing the specified values.
 
virtual ~PureVector ()
 
TPureFloat getX () const
 Gets the X-coordinate.
 
TPureFloat getY () const
 Gets the Y-coordinate.
 
TPureFloat getZ () const
 Gets the Z-coordinate.
 
TPureFloat getW () const
 Gets the W-coordinate.
 
const TPURE_XYZWgetXYZW () const
 Gets all the coordinates.
 
TPureFloat get (TPureByte index) const
 Gets the value at the given index.
 
void SetX (TPureFloat x)
 Sets the X-coordinate.
 
void SetY (TPureFloat y)
 Sets the Y-coordinate.
 
void SetZ (TPureFloat z)
 Sets the Z-coordinate.
 
void Set (TPureByte index, TPureFloat value)
 Sets the value at the given index.
 
void Set (TPureFloat x, TPureFloat y, TPureFloat z)
 Sets the given values.
 
TPureBool isZero () const
 Gets if the vector is nullvector.
 
void SetZero ()
 Sets the vector to be a nullvector.
 
TPureFloat getLength () const
 Gets the length.
 
void Normalize ()
 Normalizes the coordinates.
 
TPureFloat getDotProduct (const PureVector &vec) const
 Dot product.
 
PureVector getCrossProduct (const PureVector &vec) const
 Cross product.
 
TPureBool operator== (const PureVector &vec) const
 Equals to operator.
 
TPureBool operator!= (const PureVector &vec) const
 Not equals to operator.
 
PureVectoroperator= (const PureVector &vec)
 Assignment operator.
 
PureVector operator+ (const PureVector &vec) const
 Addition operator.
 
PureVectoroperator+= (const PureVector &vec)
 Addition assignment operator.
 
PureVector operator- (const PureVector &vec) const
 Subtraction operator.
 
PureVectoroperator-= (const PureVector &vec)
 Subtraction assignment operator.
 
PureVector operator* (const TPureFloat &scalar) const
 Multiplication by scalar operator.
 
PureVectoroperator*= (const TPureFloat &scalar)
 Multiplication assignment operator.
 
PureVector operator/ (const TPureFloat &scalar) const
 Division by scalar operator.
 
PureVectoroperator/= (const TPureFloat &scalar)
 Division assignment operator.
 
TPureFloat operator* (const PureVector &vec) const
 Dot product operator.
 
PureVector operator^ (const PureVector &vec) const
 Cross product operator.
 
PureVectoroperator^= (const PureVector &vec)
 Cross product assignment operator.
 
TPureFloatoperator() (const TPureByte &index)
 Access element operator.
 
const TPureFloatoperator() (const TPureByte &index) const
 Access element operator.
 
TPureFloatoperator[] (const TPureByte &index)
 Access element operator.
 
const TPureFloatoperator[] (const TPureByte &index) const
 Access element operator.
 
TPureBool operator< (const PureVector &r) const
 Comparison operator "less than".
 
TPureBool operator> (const PureVector &r) const
 Comparison operator "greater than".
 
TPureBool operator<= (const PureVector &r) const
 Comparison operator "less than or equal".
 
TPureBool operator>= (const PureVector &r) const
 Comparison operator "greater than or equal".
 

Static Private Member Functions

static bool correctIndex (int index)
 

Private Attributes

TPURE_XYZW pos
 Coordinates.
 

Constructor & Destructor Documentation

◆ PureVector() [1/3]

PureVector::PureVector ( )

Creates a vector containing zeros.

The 4th component of the vector (w) is initialized to 1.0f.

Definition at line 23 of file PureVector.cpp.

◆ PureVector() [2/3]

PureVector::PureVector ( const PureVector & vec)

Creates a nullvector.

Definition at line 32 of file PureVector.cpp.

◆ PureVector() [3/3]

PureVector::PureVector ( const TPureFloat & x,
const TPureFloat & y,
const TPureFloat & z )

Creates a vector containing the specified values.

Creates a nullvector.

The 4th component of the vector (w) is initialized to 1.0f.

Definition at line 41 of file PureVector.cpp.

◆ ~PureVector()

PureVector::~PureVector ( )
virtual

Definition at line 50 of file PureVector.cpp.

Member Function Documentation

◆ correctIndex()

bool PureVector::correctIndex ( int index)
staticprivate

Definition at line 603 of file PureVector.cpp.

◆ get()

TPureFloat PureVector::get ( TPureByte index) const

Gets the value at the given index.

Parameters
index0 means X, 1 means Y, 2 means Z, 3 means W coordinate of the vector.
Returns
Coordinate at the given index. 0.0f when specifying wrong index.

Definition at line 117 of file PureVector.cpp.

◆ getCrossProduct()

PureVector PureVector::getCrossProduct ( const PureVector & vec) const

Cross product.

Cross product is a vector which is perpendicular to both input vectors. It means this is a normalvector to the plane containing both input vectors.

Parameters
vecThe other vector used for the calculation with this vector.
Returns
Cross product of the 2 vectors. Zero when the 2 vectors are parallel or antiparallel to each other, or one of the vectors is nullvector.

Definition at line 292 of file PureVector.cpp.

◆ getDotProduct()

TPureFloat PureVector::getDotProduct ( const PureVector & vec) const

Dot product.

The dot product between two unit vectors is the cosine of the angle between those two vectors. So it is useful to tell if 2 vectors are looking into same or similar direction, or opposite direction, etc.

It is also useful when we need to sort objects in front-to-back or back-to-front order relative to camera position, because we can calculate the scalar projection of vector 'a' on vector 'b' if we have the dot product of vector 'a' and a unit vector in the direction of vector 'b':

  • vector 'a' can be calculated by subtracting camera position vector from object position vector;
  • vector 'b' can be calculated by subtracting camera position vector from camera target vector, its normalized form then will be a unit vector in the direction of where camera is looking at. Then the only task to do is to sort based on the calculated scalar projections.
Parameters
vecThe other vector used for the calculation with this vector.
Returns
Dot product of the 2 vectors. 1 if they look into exactly same direction, 0 when the 2 vectors are perpendicular to each other, -1 if they look into opposite direction.

Definition at line 276 of file PureVector.cpp.

◆ getLength()

TPureFloat PureVector::getLength ( ) const

Gets the length.

Returns
Length of the vector.

Definition at line 233 of file PureVector.cpp.

◆ getW()

TPureFloat PureVector::getW ( ) const

Gets the W-coordinate.

Returns
W-coordinate of the vector.

Definition at line 94 of file PureVector.cpp.

◆ getX()

TPureFloat PureVector::getX ( ) const

Gets the X-coordinate.

Returns
X-coordinate of the vector.

Definition at line 61 of file PureVector.cpp.

◆ getXYZW()

const TPURE_XYZW & PureVector::getXYZW ( ) const

Gets all the coordinates.

Returns
XYZW-coordinates of the vector.

Definition at line 105 of file PureVector.cpp.

◆ getY()

TPureFloat PureVector::getY ( ) const

Gets the Y-coordinate.

Returns
Y-coordinate of the vector.

Definition at line 72 of file PureVector.cpp.

◆ getZ()

TPureFloat PureVector::getZ ( ) const

Gets the Z-coordinate.

Returns
Z-coordinate of the vector.

Definition at line 83 of file PureVector.cpp.

◆ isZero()

TPureBool PureVector::isZero ( ) const

Gets if the vector is nullvector.

Nullvector is a vector having its XYZ coordinates all zero.

Returns
True if vector is nullvector, false otherwise.

Definition at line 209 of file PureVector.cpp.

◆ Normalize()

void PureVector::Normalize ( )

Normalizes the coordinates.

Normalizing a vector means we keep the vector's direction but it will be a unit vector so its length/magnitude becomes 1. By normalizing 2 vectors looking at the exactly same direction but with different coordinates/length/magnitude, they become equal.

Definition at line 244 of file PureVector.cpp.

◆ operator!=()

TPureBool PureVector::operator!= ( const PureVector & vec) const

Not equals to operator.

Definition at line 316 of file PureVector.cpp.

◆ operator()() [1/2]

TPureFloat & PureVector::operator() ( const TPureByte & index)

Access element operator.

Parameters
index0 means X, 1 means Y, 2 means Z, 3 means W coordinate of the vector.

Definition at line 457 of file PureVector.cpp.

◆ operator()() [2/2]

const TPureFloat & PureVector::operator() ( const TPureByte & index) const

Access element operator.

Parameters
index0 means X, 1 means Y, 2 means Z, 3 means W coordinate of the vector.

Definition at line 478 of file PureVector.cpp.

◆ operator*() [1/2]

TPureFloat PureVector::operator* ( const PureVector & vec) const

Dot product operator.

See details at getDotProduct().

Definition at line 422 of file PureVector.cpp.

◆ operator*() [2/2]

PureVector PureVector::operator* ( const TPureFloat & scalar) const

Multiplication by scalar operator.

Definition at line 377 of file PureVector.cpp.

◆ operator*=()

PureVector & PureVector::operator*= ( const TPureFloat & scalar)

Multiplication assignment operator.

Definition at line 387 of file PureVector.cpp.

◆ operator+()

PureVector PureVector::operator+ ( const PureVector & vec) const

Addition operator.

Definition at line 335 of file PureVector.cpp.

◆ operator+=()

PureVector & PureVector::operator+= ( const PureVector & vec)

Addition assignment operator.

Definition at line 344 of file PureVector.cpp.

◆ operator-()

PureVector PureVector::operator- ( const PureVector & vec) const

Subtraction operator.

Definition at line 356 of file PureVector.cpp.

◆ operator-=()

PureVector & PureVector::operator-= ( const PureVector & vec)

Subtraction assignment operator.

Definition at line 365 of file PureVector.cpp.

◆ operator/()

PureVector PureVector::operator/ ( const TPureFloat & scalar) const

Division by scalar operator.

Definition at line 399 of file PureVector.cpp.

◆ operator/=()

PureVector & PureVector::operator/= ( const TPureFloat & scalar)

Division assignment operator.

Definition at line 409 of file PureVector.cpp.

◆ operator<()

TPureBool PureVector::operator< ( const PureVector & r) const

Comparison operator "less than".

Definition at line 519 of file PureVector.cpp.

◆ operator<=()

TPureBool PureVector::operator<= ( const PureVector & r) const

Comparison operator "less than or equal".

Definition at line 555 of file PureVector.cpp.

◆ operator=()

PureVector & PureVector::operator= ( const PureVector & vec)

Assignment operator.

Definition at line 325 of file PureVector.cpp.

◆ operator==()

TPureBool PureVector::operator== ( const PureVector & vec) const

Equals to operator.

Definition at line 303 of file PureVector.cpp.

◆ operator>()

TPureBool PureVector::operator> ( const PureVector & r) const

Comparison operator "greater than".

Definition at line 546 of file PureVector.cpp.

◆ operator>=()

TPureBool PureVector::operator>= ( const PureVector & r) const

Comparison operator "greater than or equal".

Definition at line 564 of file PureVector.cpp.

◆ operator[]() [1/2]

TPureFloat & PureVector::operator[] ( const TPureByte & index)

Access element operator.

Parameters
index0 means X, 1 means Y, 2 means Z, 3 means W coordinate of the vector.

Definition at line 499 of file PureVector.cpp.

◆ operator[]() [2/2]

const TPureFloat & PureVector::operator[] ( const TPureByte & index) const

Access element operator.

Parameters
index0 means X, 1 means Y, 2 means Z, 3 means W coordinate of the vector.

Definition at line 510 of file PureVector.cpp.

◆ operator^()

PureVector PureVector::operator^ ( const PureVector & vec) const

Cross product operator.

See details at getCrossProduct().

Definition at line 432 of file PureVector.cpp.

◆ operator^=()

PureVector & PureVector::operator^= ( const PureVector & vec)

Cross product assignment operator.

Definition at line 441 of file PureVector.cpp.

◆ Set() [1/2]

void PureVector::Set ( TPureByte index,
TPureFloat value )

Sets the value at the given index.

No effect when specifying invalid index.

Parameters
index0 means X, 1 means Y, 2 means Z, 3 means W coordinate of the vector.
valueCoordinate value to be set.

Definition at line 173 of file PureVector.cpp.

◆ Set() [2/2]

void PureVector::Set ( TPureFloat x,
TPureFloat y,
TPureFloat z )

Sets the given values.

Parameters
xWhat X-coordinate to be set.
yWhat Y-coordinate to be set.
zWhat Z-coordinate to be set.

Definition at line 195 of file PureVector.cpp.

◆ SetX()

void PureVector::SetX ( TPureFloat x)

Sets the X-coordinate.

Parameters
xWhat X-coordinate to be set.

Definition at line 138 of file PureVector.cpp.

◆ SetY()

void PureVector::SetY ( TPureFloat y)

Sets the Y-coordinate.

Parameters
yWhat Y-coordinate to be set.

Definition at line 149 of file PureVector.cpp.

◆ SetZ()

void PureVector::SetZ ( TPureFloat z)

Sets the Z-coordinate.

Parameters
zWhat Z-coordinate to be set.

Definition at line 160 of file PureVector.cpp.

◆ SetZero()

void PureVector::SetZero ( )

Sets the vector to be a nullvector.

Nullvector is a vector having its XYZ coordinates all zero.

Definition at line 219 of file PureVector.cpp.

Member Data Documentation

◆ pos

TPURE_XYZW PureVector::pos
private

Coordinates.

Definition at line 98 of file PureVector.h.


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