29 struct { T
x; T
y; T
z; T
w;};
30 struct { T
r; T
g; T
b; T
a;};
55 e{other.
x, other.
y, other.
z, other.
w}
64 e{other.
x, other.
y, other.
z,
w}
74 e{other.
x, other.
y,
z,
w}
84 e{other.
x, other.
y, other.
z, other.
w}
95 e{other.
x, other.
y, other.
z}
105 template <
typename U>
107 e{other.
x, other.
y,
z,
w}
116 s <<
"[" <<
e[0] <<
", " <<
e[1] <<
", " <<
e[2] <<
", " <<
e[3] <<
"]";
126 return {
e[0]+val.
e[0],
138 return {
e[0]-val.
e[0],
150 return {
e[0]*val.
e[0],
162 return {
e[0]/val.
e[0],
174 return {
e[0]*val,
e[1]*val,
e[2]*val,
e[3]*val};
183 return {
e[0]/val,
e[1]/val,
e[2]/val,
e[3]/val};
192 return {
e[0]+val,
e[1]+val,
e[2]+val,
e[3]+val};
201 return {
e[0]-val,
e[1]-val,
e[2]-val,
e[3]-val};
210 return e[0] == other.
e[0] &&
211 e[1] == other.
e[1] &&
212 e[2] == other.
e[2] &&
222 return e[0] != other.
e[0] ||
223 e[1] != other.
e[1] ||
224 e[2] != other.
e[2] ||
241 return e[0]*
e[0]+
e[1]*
e[1]+
e[2]*
e[2]+
e[3]*
e[3];
249 return {
e[0],
e[1],
e[2]};
257 operator T*(void) {
return e.data();}
263 operator const T*(void)
const {
return e.data();}
272 return a.e[0]*
b.e[0]+
a.e[1]*
b.e[1]+
a.e[2]*
b.e[2]+
a.e[3]*
b.e[3];
303 return { std::clamp(val.
x, minVal, maxVal),
304 std::clamp(val.
y, minVal, maxVal),
305 std::clamp(val.
z, minVal, maxVal),
306 std::clamp(val.
w, minVal, maxVal)
Random staticRand
Global PRNG instance for convenience functions.
Definition Rand.cpp:52
2D vector template with arithmetic, length utilities, and helpers.
3D vector template with arithmetic, geometry helpers, and RNG utilities.
Vec4t< int32_t > Vec4i
4D 32-bit signed integer vector (x,y,z,w).
Definition Vec4.h:339
Vec4t< T > operator*(float scalar, const Vec4t< T > &vec)
Scalar multiplication with scalar on the left.
Definition Vec4.h:332
Vec4t< float > Vec4
4D float vector (x,y,z,w).
Definition Vec4.h:337
std::ostream & operator<<(std::ostream &os, const Vec4t< T > &v)
Stream insertion for string representation of a vector.
Definition Vec4.h:319
Vec4t< uint32_t > Vec4ui
4D 32-bit unsigned integer vector (x,y,z,w).
Definition Vec4.h:341
Vec4t(T x, T y, T z, T w)
Construct from four component values.
Definition Vec4.h:46
T length() const
Euclidean length (magnitude).
Definition Vec4.h:232
const std::string toString() const
String representation "[x, y, z, w]".
Definition Vec4.h:114
Vec3t< float > xyz
Definition Vec4.h:32
Vec4t(const Vec3t< U > &other, T w)
Explicitly convert from a 3D vector of a different type and a w value.
Definition Vec4.h:94
Vec4t operator/(const Vec4t &val) const
Component-wise division.
Definition Vec4.h:161
T sqlength() const
Squared length (avoids sqrt).
Definition Vec4.h:240
static T dot(const Vec4t &a, const Vec4t &b)
Dot product of two 4D vectors.
Definition Vec4.h:271
Vec3t< T > vec3() const
Drop the last component and return a 3D vector (x,y,z).
Definition Vec4.h:248
Vec4t operator-(const T &val) const
Subtract scalar from all components.
Definition Vec4.h:200
float z
Definition Vec4.h:29
float w
Definition Vec4.h:29
Vec4t(const Vec4t &other)
Copy-construct from the same type.
Definition Vec4.h:54
Vec4t(const Vec2t< T > &other, T z, T w)
Construct from a 2D vector and z, w values.
Definition Vec4.h:73
static Vec4t< float > random()
Create a vector with components sampled from [0,1).
Definition Vec4.h:291
float y
Definition Vec4.h:29
float g
Definition Vec4.h:30
Vec4t operator*(const T &val) const
Scalar multiplication.
Definition Vec4.h:173
Vec4t operator/(const T &val) const
Scalar division.
Definition Vec4.h:182
Vec4t operator+(const T &val) const
Add scalar to all components.
Definition Vec4.h:191
Vec4t operator+(const Vec4t &val) const
Component-wise addition.
Definition Vec4.h:125
bool operator==(const Vec4t &other) const
Equality comparison (component-wise equality).
Definition Vec4.h:209
bool operator!=(const Vec4t &other) const
Inequality comparison (component-wise inequality).
Definition Vec4.h:221
Vec4t operator-(const Vec4t &val) const
Component-wise subtraction.
Definition Vec4.h:137
float a
Definition Vec4.h:30
float r
Definition Vec4.h:30
std::array< float, 4 > e
Definition Vec4.h:28
Vec4t(const Vec2t< U > &other, T z, T w)
Explicitly convert from a 2D vector of a different type and z, w values.
Definition Vec4.h:106
Vec4t(const Vec3t< T > &other, T w)
Construct from a 3D vector and a w value.
Definition Vec4.h:63
Vec4t operator*(const Vec4t &val) const
Component-wise multiplication.
Definition Vec4.h:149
float b
Definition Vec4.h:30
static Vec4t< float > clamp(const Vec4t &val, float minVal, float maxVal)
Clamp each component to [minVal, maxVal].
Definition Vec4.h:302
Vec4t(const Vec4t< U > &other)
Explicitly convert from another Vec4t with different component type.
Definition Vec4.h:83
Vec2t< float > xy
Definition Vec4.h:31
static Vec4t normalize(const Vec4t &a)
Return the normalized (unit-length) version of a vector.
Definition Vec4.h:281
Vec4t()
Default-construct to (0,0,0,0).
Definition Vec4.h:35
float x
Definition Vec4.h:29