![]() |
PURE API 0.5
PR00F's Ultimate Rendering Engine full documentation
|
Pure 3D-vector class. More...
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_XYZW & | getXYZW () 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. | |
PureVector & | operator= (const PureVector &vec) |
Assignment operator. | |
PureVector | operator+ (const PureVector &vec) const |
Addition operator. | |
PureVector & | operator+= (const PureVector &vec) |
Addition assignment operator. | |
PureVector | operator- (const PureVector &vec) const |
Subtraction operator. | |
PureVector & | operator-= (const PureVector &vec) |
Subtraction assignment operator. | |
PureVector | operator* (const TPureFloat &scalar) const |
Multiplication by scalar operator. | |
PureVector & | operator*= (const TPureFloat &scalar) |
Multiplication assignment operator. | |
PureVector | operator/ (const TPureFloat &scalar) const |
Division by scalar operator. | |
PureVector & | operator/= (const TPureFloat &scalar) |
Division assignment operator. | |
TPureFloat | operator* (const PureVector &vec) const |
Dot product operator. | |
PureVector | operator^ (const PureVector &vec) const |
Cross product operator. | |
PureVector & | operator^= (const PureVector &vec) |
Cross product assignment operator. | |
TPureFloat & | operator() (const TPureByte &index) |
Access element operator. | |
const TPureFloat & | operator() (const TPureByte &index) const |
Access element operator. | |
TPureFloat & | operator[] (const TPureByte &index) |
Access element operator. | |
const TPureFloat & | operator[] (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. | |
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::PureVector | ( | const PureVector & | vec | ) |
Creates a nullvector.
Definition at line 32 of file PureVector.cpp.
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.
|
virtual |
Definition at line 50 of file PureVector.cpp.
|
staticprivate |
Definition at line 603 of file PureVector.cpp.
TPureFloat PureVector::get | ( | TPureByte | index | ) | const |
Gets the value at the given index.
index | 0 means X, 1 means Y, 2 means Z, 3 means W coordinate of the vector. |
Definition at line 117 of file PureVector.cpp.
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.
vec | The other vector used for the calculation with this vector. |
Definition at line 292 of file PureVector.cpp.
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':
vec | The other vector used for the calculation with this vector. |
Definition at line 276 of file PureVector.cpp.
TPureFloat PureVector::getLength | ( | ) | const |
TPureFloat PureVector::getW | ( | ) | const |
Gets the W-coordinate.
Definition at line 94 of file PureVector.cpp.
TPureFloat PureVector::getX | ( | ) | const |
Gets the X-coordinate.
Definition at line 61 of file PureVector.cpp.
const TPURE_XYZW & PureVector::getXYZW | ( | ) | const |
Gets all the coordinates.
Definition at line 105 of file PureVector.cpp.
TPureFloat PureVector::getY | ( | ) | const |
Gets the Y-coordinate.
Definition at line 72 of file PureVector.cpp.
TPureFloat PureVector::getZ | ( | ) | const |
Gets the Z-coordinate.
Definition at line 83 of file PureVector.cpp.
TPureBool PureVector::isZero | ( | ) | const |
Gets if the vector is nullvector.
Nullvector is a vector having its XYZ coordinates all zero.
Definition at line 209 of file PureVector.cpp.
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.
TPureBool PureVector::operator!= | ( | const PureVector & | vec | ) | const |
Not equals to operator.
Definition at line 316 of file PureVector.cpp.
TPureFloat & PureVector::operator() | ( | const TPureByte & | index | ) |
Access element operator.
index | 0 means X, 1 means Y, 2 means Z, 3 means W coordinate of the vector. |
Definition at line 457 of file PureVector.cpp.
const TPureFloat & PureVector::operator() | ( | const TPureByte & | index | ) | const |
Access element operator.
index | 0 means X, 1 means Y, 2 means Z, 3 means W coordinate of the vector. |
Definition at line 478 of file PureVector.cpp.
TPureFloat PureVector::operator* | ( | const PureVector & | vec | ) | const |
Dot product operator.
See details at getDotProduct().
Definition at line 422 of file PureVector.cpp.
PureVector PureVector::operator* | ( | const TPureFloat & | scalar | ) | const |
Multiplication by scalar operator.
Definition at line 377 of file PureVector.cpp.
PureVector & PureVector::operator*= | ( | const TPureFloat & | scalar | ) |
Multiplication assignment operator.
Definition at line 387 of file PureVector.cpp.
PureVector PureVector::operator+ | ( | const PureVector & | vec | ) | const |
Addition operator.
Definition at line 335 of file PureVector.cpp.
PureVector & PureVector::operator+= | ( | const PureVector & | vec | ) |
Addition assignment operator.
Definition at line 344 of file PureVector.cpp.
PureVector PureVector::operator- | ( | const PureVector & | vec | ) | const |
Subtraction operator.
Definition at line 356 of file PureVector.cpp.
PureVector & PureVector::operator-= | ( | const PureVector & | vec | ) |
Subtraction assignment operator.
Definition at line 365 of file PureVector.cpp.
PureVector PureVector::operator/ | ( | const TPureFloat & | scalar | ) | const |
Division by scalar operator.
Definition at line 399 of file PureVector.cpp.
PureVector & PureVector::operator/= | ( | const TPureFloat & | scalar | ) |
Division assignment operator.
Definition at line 409 of file PureVector.cpp.
TPureBool PureVector::operator< | ( | const PureVector & | r | ) | const |
Comparison operator "less than".
Definition at line 519 of file PureVector.cpp.
TPureBool PureVector::operator<= | ( | const PureVector & | r | ) | const |
Comparison operator "less than or equal".
Definition at line 555 of file PureVector.cpp.
PureVector & PureVector::operator= | ( | const PureVector & | vec | ) |
Assignment operator.
Definition at line 325 of file PureVector.cpp.
TPureBool PureVector::operator== | ( | const PureVector & | vec | ) | const |
Equals to operator.
Definition at line 303 of file PureVector.cpp.
TPureBool PureVector::operator> | ( | const PureVector & | r | ) | const |
Comparison operator "greater than".
Definition at line 546 of file PureVector.cpp.
TPureBool PureVector::operator>= | ( | const PureVector & | r | ) | const |
Comparison operator "greater than or equal".
Definition at line 564 of file PureVector.cpp.
TPureFloat & PureVector::operator[] | ( | const TPureByte & | index | ) |
Access element operator.
index | 0 means X, 1 means Y, 2 means Z, 3 means W coordinate of the vector. |
Definition at line 499 of file PureVector.cpp.
const TPureFloat & PureVector::operator[] | ( | const TPureByte & | index | ) | const |
Access element operator.
index | 0 means X, 1 means Y, 2 means Z, 3 means W coordinate of the vector. |
Definition at line 510 of file PureVector.cpp.
PureVector PureVector::operator^ | ( | const PureVector & | vec | ) | const |
Cross product operator.
See details at getCrossProduct().
Definition at line 432 of file PureVector.cpp.
PureVector & PureVector::operator^= | ( | const PureVector & | vec | ) |
Cross product assignment operator.
Definition at line 441 of file PureVector.cpp.
void PureVector::Set | ( | TPureByte | index, |
TPureFloat | value ) |
Sets the value at the given index.
No effect when specifying invalid index.
index | 0 means X, 1 means Y, 2 means Z, 3 means W coordinate of the vector. |
value | Coordinate value to be set. |
Definition at line 173 of file PureVector.cpp.
void PureVector::Set | ( | TPureFloat | x, |
TPureFloat | y, | ||
TPureFloat | z ) |
Sets the given values.
x | What X-coordinate to be set. |
y | What Y-coordinate to be set. |
z | What Z-coordinate to be set. |
Definition at line 195 of file PureVector.cpp.
void PureVector::SetX | ( | TPureFloat | x | ) |
Sets the X-coordinate.
x | What X-coordinate to be set. |
Definition at line 138 of file PureVector.cpp.
void PureVector::SetY | ( | TPureFloat | y | ) |
Sets the Y-coordinate.
y | What Y-coordinate to be set. |
Definition at line 149 of file PureVector.cpp.
void PureVector::SetZ | ( | TPureFloat | z | ) |
Sets the Z-coordinate.
z | What Z-coordinate to be set. |
Definition at line 160 of file PureVector.cpp.
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.
|
private |
Coordinates.
Definition at line 98 of file PureVector.h.