43 template<
typename T>
struct Vec2;
45 template<
typename T>
struct Vec3;
47 template<
typename T>
struct Vec4;
70 template<
typename T>
struct Vec4 :
public Vec3<T>
74 #if (MTOOLS_TGX_EXTENSIONS)
75 #include <mtools/extensions/tgx/tgx_ext_Vec4.inl>
97 constexpr Vec4(T X, T Y, T Z, T W) :
Vec3<T>(X,Y,Z),
w(W)
151 return ((
x == V.
x) && (
y == V.
y) && (
z == V.
z) && (
w == V.
w));
160 return(!(
operator==(V)));
169 if (
x < V.
x)
return true;
172 if (
y < V.
y)
return true;
175 if (
z < V.
z)
return true;
176 if (
z == V.
z)
return true;
178 if (
w < V.
w)
return true;
191 if (
x < V.
x)
return true;
194 if (
y < V.
y)
return true;
197 if (
z < V.
z)
return true;
198 if (
z == V.
z)
return true;
200 if (
w <= V.
w)
return true;
213 return(!(
operator<=(V)));
222 return(!(
operator<(V)));
348 template<typename Tfloat = typename DefaultFPType<T>::fptype >
inline Tfloat
norm()
const
363 template<typename Tfloat = typename DefaultFPType<T>::fptype >
inline Tfloat
norm_fast()
const
377 template<typename Tfloat = typename DefaultFPType<T>::fptype >
inline Tfloat
invnorm()
const
392 template<typename Tfloat = typename DefaultFPType<T>::fptype >
inline Tfloat
invnorm_fast()
const
406 template<typename Tfloat = typename DefaultFPType<T>::fptype >
inline void normalize()
408 Tfloat a = invnorm<Tfloat>();
425 template<typename Tfloat = typename DefaultFPType<T>::fptype >
inline void normalize_fast()
427 Tfloat a = invnorm_fast<Tfloat>();
478 template<typename Tfloat = typename DefaultFPType<T>::fptype >
inline void zdivide()
495 inline void print(Stream & outputStream = Serial)
const
497 outputStream.printf(
"[%.3f \t %.3f \t %.3f \t %.3f]\n",
x,
y,
z,
w);
514 V.template normalize<Tfloat>();
528 V.template normalize_fast<Tfloat>();
538 const T xx = V1.
x - V2.
y;
539 const T yy = V1.
y - V2.
y;
540 const T zz = V1.
z - V2.
z;
541 const T ww = V1.
w - V2.
w;
542 return xx * xx + yy * yy + zz * zz + ww * ww;
552 template<typename T, typename Tfloat = typename DefaultFPType<T>::fptype > Tfloat
dist(
Vec4<T> V1,
const Vec4<T> V2)
554 const T xx = V1.
x - V2.
y;
555 const T yy = V1.
y - V2.
y;
556 const T zz = V1.
z - V2.
z;
557 const T ww = V1.
w - V2.
w;
558 return (Tfloat)
tgx::precise_sqrt((Tfloat)(xx * xx + yy * yy + zz * zz + ww * ww));
571 const T xx = V1.
x - V2.
y;
572 const T yy = V1.
y - V2.
y;
573 const T zz = V1.
z - V2.
z;
574 const T ww = V1.
w - V2.
w;
575 return (Tfloat)
tgx::fast_sqrt((Tfloat)(xx * xx + yy * yy + zz * zz + ww * ww));
621 return U.
x * V.
x + U.
y * V.
y + U.
z * V.
z + U.
w * V.
w;
631 U.
z* V.
x - U.
x * V.
z,
632 U.
x* V.
y - U.
y * V.
x,
643 return Vec4<T>{ (T)(V1.
x + alpha * (V2.
x - V1.
x)),
644 (T)(V1.
y + alpha * (V2.
y - V1.
y)),
645 (T)(V1.
z + alpha * (V2.
z - V1.
z)),
646 (T)(V1.
w + alpha * (V2.
w - V1.
w)) };
Mat4< T > operator*(const Mat4< T > &A, const Mat4< T > &B)
Matrix-matrix multiplication.
Definition: Mat4.h:633
Utility/miscellaneous functions used throughout the library.
TGX_INLINE float fast_invsqrt(float x)
Compute a fast approximation of the inverse square root of a float.
Definition: Misc.h:326
TGX_INLINE float precise_sqrt(float x)
Compute the square root of a float (exact computation).
Definition: Misc.h:254
TGX_INLINE float precise_invsqrt(float x)
Compute the inverse square root of a float (exact computation).
Definition: Misc.h:306
TGX_INLINE float fast_sqrt(float x)
Compute a fast approximation of the square root of a float.
Definition: Misc.h:272
TGX_INLINE float fast_inv(float x)
Fast (approximate) computation of 1/x.
Definition: Misc.h:219
T crossProduct(const Vec2< T > &U, const Vec2< T > &V)
Return the cross product UxV (i.e.
Definition: Vec2.h:569
T dotProduct(const Vec2< T > U, const Vec2< T > V)
Return the dot product U.V between two vectors.
Definition: Vec2.h:560
Tfloat dist_fast(Vec2< T > V1, const Vec2< T > V2)
Compute the euclidian distance between two vectors.
Definition: Vec2.h:512
Vec2< T > normalize(Vec2< T > V)
Return the vector normalized to have unit norm (do nothing if the vector is 0).
Definition: Vec2.h:459
Vec2< T > lerp(Tfloat alpha, Vec2< T > V1, Vec2< T > V2)
Return the linear interpolation: V1 + alpha(V2 - V1).
Definition: Vec2.h:578
Vec2< T > operator+(Vec2< T > V1, const Vec2< T > V2)
Addition operator.
Definition: Vec2.h:521
Vec2< T > operator/(Vec2< T > V1, const Vec2< T > V2)
Division operator.
Definition: Vec2.h:530
Tfloat dist(Vec2< T > V1, const Vec2< T > V2)
Compute the euclidian distance between two vectors.
Definition: Vec2.h:497
T dist2(const Vec2< T > V1, const Vec2< T > V2)
Compute the squared euclidian distance between two vectors.
Definition: Vec2.h:483
Vec2< T > operator-(Vec2< T > V1, const Vec2< T > V2)
Substraction operator.
Definition: Vec2.h:524
Vec2< T > normalize_fast(Vec2< T > V)
Return the vector normalized to have unit norm (do nothing if the vector is 0).
Definition: Vec2.h:473
Generic 2D vector [specializations iVec2, fVec2, dVec2].
Definition: Vec2.h:64
T x
'x' coordinate (first dimension)
Definition: Vec2.h:72
T y
'y' coordinate (second dimension)
Definition: Vec2.h:73
Generic 3D vector [specializations iVec3, fVec3, dVec3].
Definition: Vec3.h:70
T z
'z' coordinate (third dimension)
Definition: Vec3.h:83
Geenric 4D vector [specializations iVec4, fVec4, dVec4].
Definition: Vec4.h:71
void operator*=(const T v)
Scalar multiplication.
Definition: Vec4.h:300
bool operator!=(const Vec4 V) const
Inequality operator.
Definition: Vec4.h:158
void operator*=(const Vec4 V)
Multiply this vector by another one (coordinate by coordinate multiplication).
Definition: Vec4.h:253
T w
'w' coordinate (fourth dimension)
Definition: Vec4.h:85
Vec4(const Vec4 &V)=default
Default copy constructor.
void operator-=(const T v)
Scalar substraction.
Definition: Vec4.h:289
void normalize_fast()
Normalise the vector so that its norm is 1 (do nothing if the vector is 0).
Definition: Vec4.h:425
bool operator<(const Vec4 V) const
Less-than comparison operator.
Definition: Vec4.h:167
Tfloat invnorm_fast() const
Compute the inverse of the euclidian norm of the vector.
Definition: Vec4.h:392
bool operator>=(const Vec4 V) const
Greater-than-or-equal comparison operator.
Definition: Vec4.h:220
void operator/=(const T v)
Scalar division.
Definition: Vec4.h:311
constexpr Vec4(Vec3< T > V, T W)
Constructor from a Vec3.
Definition: Vec4.h:119
bool operator>(const Vec4 V) const
Greater-than comparison operator.
Definition: Vec4.h:211
void operator/=(const Vec4 V)
Divide this vector by another one (coordinate by coordinate division).
Definition: Vec4.h:265
Vec4< T > getNormalize() const
Return the vector normalized to have unit norm (do nothing if the vector is 0).
Definition: Vec4.h:443
bool operator==(const Vec4 V) const
Equality comparator.
Definition: Vec4.h:149
constexpr Vec4(Vec2< T > V, T Z, T W)
Constructor from a Vec2.
Definition: Vec4.h:111
void operator+=(const T v)
Scalar addition.
Definition: Vec4.h:277
void operator-=(const Vec4 V)
Substract another vector from this one.
Definition: Vec4.h:241
bool operator<=(const Vec4 V) const
Less-than-or-equal comparison operator.
Definition: Vec4.h:189
constexpr Vec4(T X, T Y, T Z, T W)
Constructor with explicit initialization.
Definition: Vec4.h:97
void operator+=(const Vec4 V)
Add another vector to this one.
Definition: Vec4.h:229
void zdivide()
Performs the 'z-divide' operation.
Definition: Vec4.h:478
Vec4 & operator=(const Vec4 &V)=default
Default assignment operator.
void normalize()
Normalise the vector so that its norm is 1 (do nothing if the vector is 0).
Definition: Vec4.h:406
Tfloat norm_fast() const
Compute the euclidian norm of the vector.
Definition: Vec4.h:363
void print(Stream &outputStream=Serial) const
Print a representation of the vector using a given stream object.
Definition: Vec4.h:495
Tfloat invnorm() const
Compute the inverse of the euclidian norm of the vector.
Definition: Vec4.h:377
Tfloat norm() const
Compute the euclidian norm of the vector.
Definition: Vec4.h:348
Vec4< T > getNormalize_fast() const
Return the vector normalized to have unit norm (do nothing if the vector is 0).
Definition: Vec4.h:460
Vec4()
default constructor: the vector content is undefined.
Definition: Vec4.h:91
T norm2() const
Compute the squared euclidian norm of the vector.
Definition: Vec4.h:334