t
|
The 4D vector class. More...
#include <Vector4.hpp>
Public Member Functions | |
Vector4 (double _x, double _y, double _z, double _w) | |
Creates a new 4D vector with the specified components. | |
Vector4 (const Vector3 &vector3, double w) | |
Creates a new 4D vector with the same x, y, and z components as the specified 3D vector and the specified w component. | |
Vector4 | clone () const |
Returns a copy of this 4D vector. | |
Vector4 & | copy (const Vector4 &source) |
Copies the components of the specified 4D vector to this 4D vector. | |
Vector4 & | set (double _x, double _y, double _z, double _w) |
Sets the components of this 4D vector. | |
Vector3 | toVector3 () const |
Returns the 3D vector represented by the x, y, and z components of this 4D vector with perspective division. | |
double | length () const |
Returns the length of this 4D vector. | |
Vector4 | unit () const |
Returns the unit vector of this 4D vector. | |
Vector4 & | normalize () |
Normalizes this 4D vector. | |
Vector4 | absolute () const |
Returns a new 4D vector with the absolute values of the components of this 4D vector. | |
Vector4 & | abs () |
Sets the components of this 4D vector to their absolute values. | |
Vector4 & | clamp (const Vector4 &min, const Vector4 &max) |
Clamps the components of this 4D vector to the specified minimum and maximum 4D vectors component-wise. | |
Vector4 & | clamp (double min, double max) |
Clamps the components of this 4D vector to the specified minimum and maximum values. | |
double | operator[] (std::size_t index) const |
Returns the component at the specified index of this 4D vector. | |
Vector4 & | operator+= (const Vector4 &v) |
Adds the specified 4D vector to this vector. | |
Vector4 & | operator+= (double s) |
Adds the specified constant to all components in this 4D vector. | |
Vector4 & | operator-= (const Vector4 &v) |
Subtracts the specified 4D vector from this vector. | |
Vector4 & | operator-= (double s) |
Subtracts the specified constant from all components in this 4D vector. | |
Vector4 & | operator*= (const Vector4 &v) |
Multiplies the components of this vector with the corresponding components of the specified 4D vector. | |
Vector4 & | operator*= (double s) |
Multiplies all components of this 4D vector with the specified constant. | |
Vector4 & | operator/= (const Vector4 &v) |
Divides the components of this vector by the corresponding components of another 4D vector. | |
Vector4 & | operator/= (double s) |
Divides the components of this 4D vector by the specified constant. | |
Public Attributes | |
double | x |
The x component of this 4D vector. | |
double | y |
The y component of this 4D vector. | |
double | z |
The w component of this 4D vector. | |
double | w |
The z component of this 4D vector. | |
Friends | |
bool | operator== (const Vector4 &a, const Vector4 &b)=default |
Returns whether if two 4D vectors are equal. | |
Vector4 | operator- (const Vector4 &a) |
Returns the negation of this 4D vector. | |
Vector4 | operator+ (const Vector4 &a, const Vector4 &b) |
Adds two 4D vectors. | |
Vector4 | operator+ (const Vector4 &a, double s) |
Adds a constant to all components of a 4D vector. | |
Vector4 | operator+ (double s, const Vector4 &a) |
Adds a constant to all components of a 4D vector. | |
Vector4 | operator- (const Vector4 &a, const Vector4 &b) |
Subtracts two 4D vectors. | |
Vector4 | operator- (const Vector4 &a, double s) |
Subtracts a constant from all components of a 4D vector. | |
Vector4 | operator- (double s, const Vector4 &a) |
Subtracts a 4D vector from a constant 4D vector. | |
Vector4 | operator* (const Vector4 &a, const Vector4 &b) |
Returns the element-wise product of two 4D vectors, also known as the Hadamard product. | |
Vector4 | operator* (const Vector4 &a, double s) |
Multiplies all components of a 4D vector with a constant. | |
Vector4 | operator* (double s, const Vector4 &a) |
Multiplies all components of a 4D vector with a constant. | |
Vector4 | operator/ (const Vector4 &a, const Vector4 &b) |
Returns the element-wise division of two 4D vectors. | |
Vector4 | operator/ (const Vector4 &a, double s) |
Divides the components of a 4D vector by a constant. | |
Vector4 | operator/ (double s, const Vector4 &a) |
Returns the element-wise division of a constant 4D vector and a 4D vector. | |
The 4D vector class.
A 4D vector is a triplet of numbers labeled x, y, z, and w which can be used to represent a number of things e.g. 4D homogeneous coordinates, RGBA colors, etc.
|
inline |
Creates a new 4D vector with the specified components.
_x | The x component of the new 4D vector. |
_y | The y component of the new 4D vector. |
_z | The z component of the new 4D vector. |
_w | The w component of the new 4D vector. |
|
inline |
Creates a new 4D vector with the same x, y, and z components as the specified 3D vector and the specified w component.
vector3 | A 3D vector to copy the x, y, and z components from. |
w | The w component of the new 4D vector. |
|
inline |
Sets the components of this 4D vector to their absolute values.
Note that this method modifies this instance. If you want to avoid modification, use absolute
instead.
|
inline |
Returns a new 4D vector with the absolute values of the components of this 4D vector.
Clamps the components of this 4D vector to the specified minimum and maximum 4D vectors component-wise.
min | The minimum 4D vector. |
max | The maximum 4D vector. |
|
inline |
Clamps the components of this 4D vector to the specified minimum and maximum values.
min | The minimum value. |
max | The maximum value. |
|
inline |
Returns a copy of this 4D vector.
Copies the components of the specified 4D vector to this 4D vector.
source | A 4D vector to copy the components from. |
|
inline |
Returns the length of this 4D vector.
Specifically, returns the Euclidean length.
|
inline |
Normalizes this 4D vector.
Note that this method modifies this instance. If you want to avoid modification, use unit
instead.
Multiplies the components of this vector with the corresponding components of the specified 4D vector.
v | A 4D vector. |
|
inline |
Multiplies all components of this 4D vector with the specified constant.
s | A constant. |
Adds the specified 4D vector to this vector.
v | A 4D vector. |
|
inline |
Adds the specified constant to all components in this 4D vector.
s | A constant. |
Subtracts the specified 4D vector from this vector.
v | A 4D vector. |
|
inline |
Subtracts the specified constant from all components in this 4D vector.
s | A constant. |
Divides the components of this vector by the corresponding components of another 4D vector.
v | A 4D vector. |
|
inline |
Divides the components of this 4D vector by the specified constant.
s | A constant. |
|
inline |
Returns the component at the specified index of this 4D vector.
index | A 0-based index. Must be 0, 1, 2, or 3. |
index
. std::invalid_argument | if index is not 0, 1, 2, or 3. |
|
inline |
Sets the components of this 4D vector.
_x | The new x component. |
_y | The new y component. |
_z | The new z component. |
_w | The new w component. |
|
inline |
Returns the 3D vector represented by the x, y, and z components of this 4D vector with perspective division.
That is, if this 4D vector is \((x, y, z, w)\), then return the 3D vector \((x/w, y/w, z/w)\).
|
inline |
Returns the unit vector of this 4D vector.
Returns the element-wise product of two 4D vectors, also known as the Hadamard product.
a | A 4D vector. |
b | Another 4D vector. |
a
and b
. Multiplies all components of a 4D vector with a constant.
a | A 4D vector. |
s | A constant. |
a
with s
. Multiplies all components of a 4D vector with a constant.
s | A constant. |
a | A 4D vector. |
a
with s
. Adds two 4D vectors.
a | A 4D vector. |
b | Another 4D vector. |
a
and b
. Adds a constant to all components of a 4D vector.
a | A 4D vector. |
s | A constant. |
s
to the components of a
. Adds a constant to all components of a 4D vector.
s | A constant. |
a | A 4D vector. |
s
to the components of a
. Returns the negation of this 4D vector.
Subtracts two 4D vectors.
a | A 4D vector. |
b | Another 4D vector. |
a
and b
. Subtracts a constant from all components of a 4D vector.
a | A 4D vector. |
s | A constant. |
s
from the components of a
. Subtracts a 4D vector from a constant 4D vector.
A constant vector is a vector whose components are all the same.
s | A constant for the constant 4D vector. |
a | A 4D vector. |
a
from the constant vector of s
. Returns the element-wise division of two 4D vectors.
a | A 4D vector. |
b | Another 4D vector. |
a
and b
. Divides the components of a 4D vector by a constant.
a | A 4D vector. |
s | A constant. |
a
by s
. Returns the element-wise division of a constant 4D vector and a 4D vector.
A constant vector is a vector whose components are all the same.
s | A constant for the constant 4D vector. |
a | A 4D vector. |
a
. Returns whether if two 4D vectors are equal.
true
if the two vectors are equal, false
otherwise.