41 template<
typename T>
struct Vec2;
43 template<
typename T>
struct Vec3;
45 template<
typename T>
struct Vec4;
69 template<
typename T>
struct Vec3 :
public Vec2<T>
73 #if (MTOOLS_TGX_EXTENSIONS)
74 #include <mtools/extensions/tgx/tgx_ext_Vec3.inl>
142 return ((
x == V.
x) && (
y == V.
y) && (
z == V.
z));
151 return(!(
operator==(V)));
160 if (
x < V.
x)
return true;
163 if (
y < V.
y)
return true;
166 if (
z < V.
z)
return true;
178 if (
x < V.
x)
return true;
181 if (
y < V.
y)
return true;
184 if (
z <= V.
z)
return true;
196 return(!(
operator<=(V)));
205 return(!(
operator<(V)));
324 template<typename Tfloat = typename DefaultFPType<T>::fptype >
inline Tfloat
norm()
const
339 template<typename Tfloat = typename DefaultFPType<T>::fptype >
inline Tfloat
norm_fast()
const
353 template<typename Tfloat = typename DefaultFPType<T>::fptype >
inline Tfloat
invnorm()
const
368 template<typename Tfloat = typename DefaultFPType<T>::fptype >
inline Tfloat
invnorm_fast()
const
382 template<typename Tfloat = typename DefaultFPType<T>::fptype >
inline void normalize()
384 Tfloat a = invnorm<Tfloat>();
400 template<typename Tfloat = typename DefaultFPType<T>::fptype >
inline void normalize_fast()
402 Tfloat a = invnorm_fast<Tfloat>();
450 inline void print(Stream & outputStream = Serial)
const
452 outputStream.printf(
"[%.3f \t %.3f \t %.3f]\n",
x,
y,
z);
469 V.template normalize<Tfloat>();
483 V.template normalize_fast<Tfloat>();
493 const T xx = V1.
x - V2.
x;
494 const T yy = V1.
y - V2.
y;
495 const T zz = V1.
z - V2.
z;
496 return xx * xx + yy * yy + zz * zz;
506 template<typename T, typename Tfloat = typename DefaultFPType<T>::fptype > TGX_INLINE
inline Tfloat
dist(
const Vec3<T> & V1,
const Vec3<T> & V2)
508 const T xx = V1.
x - V2.
x;
509 const T yy = V1.
y - V2.
y;
510 const T zz = V1.
z - V2.
z;
522 template<typename T, typename Tfloat = typename DefaultFPType<T>::fptype > TGX_INLINE
inline Tfloat
dist_fast(
const Vec3<T> & V1,
const Vec3<T> & V2)
524 const T xx = V1.
x - V2.
x;
525 const T yy = V1.
y - V2.
y;
526 const T zz = V1.
z - V2.
z;
527 return (Tfloat)
tgx::fast_sqrt((Tfloat)(xx * xx + yy * yy + zz * zz));
567 return U.
x * V.
x + U.
y * V.
y + U.
z * V.
z;
577 return fmaf(U.
x, V.
x, fmaf(U.
y, V.
y, U.
z * V.
z));
588 U.
z* V.
x - U.
x * V.
z,
589 U.
x* V.
y - U.
y * V.
x };
596 template<typename T, typename Tfloat = typename DefaultFPType<T>::fptype > TGX_INLINE
inline Vec3<T> lerp(
const Tfloat alpha,
const Vec3<T> & V1,
const Vec3<T> & V2)
598 return Vec3<T>{ (T)(V1.
x + alpha * (V2.
x - V1.
x)),
599 (T)(V1.
y + alpha * (V2.
y - V1.
y)),
600 (T)(V1.
z + alpha * (V2.
z - V1.
z)) };
Mat4< T > operator*(const Mat4< T > &A, const Mat4< T > &B)
Matrix-matrix multiplication.
Definition: Mat4.h:689
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:378
TGX_INLINE float precise_sqrt(float x)
Compute the square root of a float (exact computation).
Definition: Misc.h:282
TGX_INLINE float precise_invsqrt(float x)
Compute the inverse square root of a float (exact computation).
Definition: Misc.h:330
TGX_INLINE float fast_sqrt(float x)
Compute a fast approximation of the square root of a float.
Definition: Misc.h:302
TGX_INLINE Tfloat dist(const Vec2< T > &V1, const Vec2< T > &V2)
Compute the euclidian distance between two vectors.
Definition: Vec2.h:497
TGX_INLINE Vec2< T > operator+(Vec2< T > V1, const Vec2< T > &V2)
Addition operator.
Definition: Vec2.h:521
TGX_INLINE T dist2(const Vec2< T > &V1, const Vec2< T > &V2)
Compute the squared euclidian distance between two vectors.
Definition: Vec2.h:483
TGX_INLINE 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
TGX_INLINE Vec2< T > operator-(Vec2< T > V1, const Vec2< T > &V2)
Substraction operator.
Definition: Vec2.h:524
TGX_INLINE T dotProduct(const Vec2< T > &U, const Vec2< T > &V)
Return the dot product U.V between two vectors.
Definition: Vec2.h:554
TGX_INLINE 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
TGX_INLINE Vec2< T > operator/(Vec2< T > V1, const Vec2< T > &V2)
Division operator.
Definition: Vec2.h:530
TGX_INLINE Tfloat dist_fast(const Vec2< T > &V1, const Vec2< T > &V2)
Compute the euclidian distance between two vectors.
Definition: Vec2.h:512
TGX_INLINE Vec2< T > lerp(Tfloat alpha, const Vec2< T > &V1, const Vec2< T > &V2)
Return the linear interpolation: V1 + alpha(V2 - V1).
Definition: Vec2.h:583
TGX_INLINE T crossProduct(const Vec2< T > &U, const Vec2< T > &V)
Return the cross product UxV (i.e.
Definition: Vec2.h:574
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
TGX_INLINE void operator-=(const Vec3 &V)
Substract another vector from this one.
Definition: Vec3.h:223
TGX_INLINE void operator-=(T v)
scalar substraction.
Definition: Vec3.h:267
bool operator<(const Vec3 &V) const
Less-than comparison operator.
Definition: Vec3.h:158
Vec3< T > getNormalize() const
Return the vector normalized to have unit norm (do nothing if the vector is 0).
Definition: Vec3.h:417
TGX_INLINE void operator*=(T v)
scalar multiplication.
Definition: Vec3.h:277
Vec3< T > getNormalize_fast() const
Return the vector normalized to have unit norm (do nothing if the vector is 0).
Definition: Vec3.h:434
bool operator>=(const Vec3 &V) const
Greater-than-or-equal comparison operator.
Definition: Vec3.h:203
bool operator<=(const Vec3 &V) const
Less-than-or-equal comparison operator.
Definition: Vec3.h:176
Vec3 operator-() const
unary negation operator
Definition: Vec3.h:298
T z
'z' coordinate (third dimension)
Definition: Vec3.h:83
constexpr Vec3(Vec2< T > V, T Z)
Constructor from a Vec2.
Definition: Vec3.h:109
bool operator!=(const Vec3 &V) const
Inequality operator.
Definition: Vec3.h:149
Vec3(const Vec3 &V)=default
Default copy constructor.
TGX_INLINE void operator/=(T v)
scalar division.
Definition: Vec3.h:287
T norm2() const
Compute the squared euclidian norm of the vector.
Definition: Vec3.h:310
Vec3 & operator=(const Vec3 &V)=default
Default assignment operator.
bool operator>(const Vec3 &V) const
Greater-than comparison operator.
Definition: Vec3.h:194
TGX_INLINE void operator+=(const Vec3 &V)
Add another vector to this one.
Definition: Vec3.h:212
TGX_INLINE void operator*=(const Vec3 &V)
Multiply this vector by another one (coordinate by coordinate multiplication).
Definition: Vec3.h:234
bool operator==(const Vec3 &V) const
Equality comparator.
Definition: Vec3.h:140
Vec3()
default constructor: the vector content is undefined.
Definition: Vec3.h:89
Tfloat invnorm_fast() const
Compute the inverse of the euclidian norm of the vector.
Definition: Vec3.h:368
Tfloat invnorm() const
Compute the inverse of the euclidian norm of the vector.
Definition: Vec3.h:353
void normalize_fast()
Normalise the vector so that its norm is 1 (do nothing if the vector is 0).
Definition: Vec3.h:400
TGX_INLINE void operator/=(const Vec3 &V)
Divide this vector by another one (coordinate by coordinate division).
Definition: Vec3.h:245
void normalize()
Normalise the vector so that its norm is 1 (do nothing if the vector is 0).
Definition: Vec3.h:382
TGX_INLINE void operator+=(T v)
scalar addition.
Definition: Vec3.h:256
Tfloat norm() const
Compute the euclidian norm of the vector.
Definition: Vec3.h:324
Tfloat norm_fast() const
Compute the euclidian norm of the vector.
Definition: Vec3.h:339
constexpr Vec3(T X, T Y, T Z)
Constructor with explicit initialization.
Definition: Vec3.h:95