1#include "math/Vector3.hpp"
8#define m matrix4.elements
35 Vector4(
double _x,
double _y,
double _z,
double _w)
36 :
x(_x),
y(_y),
z(_z),
w(_w) {}
79 Vector4 &
set(
double _x,
double _y,
double _z,
double _w) {
138 return Vector4(std::abs(
x), std::abs(
y), std::abs(
z), std::abs(
w));
167 x = std::clamp(
x, min.
x, max.
x);
168 y = std::clamp(
y, min.
y, max.
y);
169 z = std::clamp(
z, min.
z, max.
z);
170 w = std::clamp(
w, min.
w, max.
w);
184 x = std::clamp(
x, min, max);
185 y = std::clamp(
y, min, max);
186 z = std::clamp(
z, min, max);
187 w = std::clamp(
w, min, max);
210 throw std::invalid_argument(
"Index to Vector4 must be 0, 1, 2, or 3.");
369 return Vector4(a.
x + s, a.
y + s, a.
z + s, a.
w + s);
401 return Vector4(a.
x - s, a.
y - s, a.
z - s, a.
w - s);
415 return Vector4(s - a.
x, s - a.
y, s - a.
z, s - a.
w);
440 return Vector4(a.
x * s, a.
y * s, a.
z * s, a.
w * s);
472 return Vector4(a.
x / s, a.
y / s, a.
z / s, a.
w / s);
485 return Vector4(s / a.
x, s / a.
y, s / a.
z, s / a.
w);
The 3D vector class.
Definition Vector3.hpp:20
The 4D vector class.
Definition Vector4.hpp:20
double y
The y component of this 4D vector.
Definition Vector4.hpp:23
Vector4(double _x, double _y, double _z, double _w)
Creates a new 4D vector with the specified components.
Definition Vector4.hpp:35
Vector4 & operator*=(const Vector4 &v)
Multiplies the components of this vector with the corresponding components of the specified 4D vector...
Definition Vector4.hpp:281
Vector4 & operator-=(double s)
Subtracts the specified constant from all components in this 4D vector.
Definition Vector4.hpp:265
Vector4 & operator/=(const Vector4 &v)
Divides the components of this vector by the corresponding components of another 4D vector.
Definition Vector4.hpp:312
friend Vector4 operator/(const Vector4 &a, double s)
Divides the components of a 4D vector by a constant.
Definition Vector4.hpp:471
Vector4 & abs()
Sets the components of this 4D vector to their absolute values.
Definition Vector4.hpp:149
friend Vector4 operator+(double s, const Vector4 &a)
Adds a constant to all components of a 4D vector.
Definition Vector4.hpp:379
Vector4 & copy(const Vector4 &source)
Copies the components of the specified 4D vector to this 4D vector.
Definition Vector4.hpp:61
double operator[](std::size_t index) const
Returns the component at the specified index of this 4D vector.
Definition Vector4.hpp:199
Vector4 & operator/=(double s)
Divides the components of this 4D vector by the specified constant.
Definition Vector4.hpp:327
friend Vector4 operator*(const Vector4 &a, const Vector4 &b)
Returns the element-wise product of two 4D vectors, also known as the Hadamard product.
Definition Vector4.hpp:427
Vector4 unit() const
Returns the unit vector of this 4D vector.
Definition Vector4.hpp:115
Vector4 clone() const
Returns a copy of this 4D vector.
Definition Vector4.hpp:53
Vector4 & normalize()
Normalizes this 4D vector.
Definition Vector4.hpp:125
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 speci...
Definition Vector4.hpp:45
double x
The x component of this 4D vector.
Definition Vector4.hpp:22
Vector4 & clamp(const Vector4 &min, const Vector4 &max)
Clamps the components of this 4D vector to the specified minimum and maximum 4D vectors component-wis...
Definition Vector4.hpp:166
friend Vector4 operator-(const Vector4 &a, double s)
Subtracts a constant from all components of a 4D vector.
Definition Vector4.hpp:400
friend bool operator==(const Vector4 &a, const Vector4 &b)=default
Returns whether if two 4D vectors are equal.
Vector4 & operator*=(double s)
Multiplies all components of this 4D vector with the specified constant.
Definition Vector4.hpp:296
Vector4 absolute() const
Returns a new 4D vector with the absolute values of the components of this 4D vector.
Definition Vector4.hpp:137
friend Vector4 operator-(const Vector4 &a, const Vector4 &b)
Subtracts two 4D vectors.
Definition Vector4.hpp:388
Vector4 & operator+=(const Vector4 &v)
Adds the specified 4D vector to this vector.
Definition Vector4.hpp:220
friend Vector4 operator/(double s, const Vector4 &a)
Returns the element-wise division of a constant 4D vector and a 4D vector.
Definition Vector4.hpp:484
double z
The w component of this 4D vector.
Definition Vector4.hpp:24
friend Vector4 operator-(const Vector4 &a)
Returns the negation of this 4D vector.
Definition Vector4.hpp:348
friend Vector4 operator*(double s, const Vector4 &a)
Multiplies all components of a 4D vector with a constant.
Definition Vector4.hpp:451
Vector4 & set(double _x, double _y, double _z, double _w)
Sets the components of this 4D vector.
Definition Vector4.hpp:79
friend Vector4 operator-(double s, const Vector4 &a)
Subtracts a 4D vector from a constant 4D vector.
Definition Vector4.hpp:414
friend Vector4 operator/(const Vector4 &a, const Vector4 &b)
Returns the element-wise division of two 4D vectors.
Definition Vector4.hpp:460
Vector4 & operator-=(const Vector4 &v)
Subtracts the specified 4D vector from this vector.
Definition Vector4.hpp:250
Vector4 & clamp(double min, double max)
Clamps the components of this 4D vector to the specified minimum and maximum values.
Definition Vector4.hpp:183
Vector3 toVector3() const
Returns the 3D vector represented by the x, y, and z components of this 4D vector with perspective di...
Definition Vector4.hpp:98
friend Vector4 operator+(const Vector4 &a, double s)
Adds a constant to all components of a 4D vector.
Definition Vector4.hpp:368
friend Vector4 operator+(const Vector4 &a, const Vector4 &b)
Adds two 4D vectors.
Definition Vector4.hpp:357
Vector4 & operator+=(double s)
Adds the specified constant to all components in this 4D vector.
Definition Vector4.hpp:235
double length() const
Returns the length of this 4D vector.
Definition Vector4.hpp:108
friend Vector4 operator*(const Vector4 &a, double s)
Multiplies all components of a 4D vector with a constant.
Definition Vector4.hpp:439
double w
The z component of this 4D vector.
Definition Vector4.hpp:25
The t software 3D graphics library namespace.
Definition algorithms.hpp:12