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.
y;
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 > Tfloat
dist(
Vec3<T> V1,
const Vec3<T> V2)
508 const T xx = V1.
x - V2.
y;
509 const T yy = V1.
y - V2.
y;
510 const T zz = V1.
z - V2.
z;
524 const T xx = V1.
x - V2.
y;
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));
573 return U.
x * V.
x + U.
y * V.
y + U.
z * V.
z;
583 U.
z* V.
x - U.
x * V.
z,
584 U.
x* V.
y - U.
y * V.
x };
593 return Vec3<T>{ (T)(V1.
x + alpha * (V2.
x - V1.
x)),
594 (T)(V1.
y + alpha * (V2.
y - V1.
y)),
595 (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: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
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
void operator+=(const Vec3 V)
Add another vector to this one.
Definition: Vec3.h:212
Vec3< T > getNormalize() const
Return the vector normalized to have unit norm (do nothing if the vector is 0).
Definition: Vec3.h:417
Vec3< T > getNormalize_fast() const
Return the vector normalized to have unit norm (do nothing if the vector is 0).
Definition: Vec3.h:434
void operator/=(const Vec3 V)
Divide this vector by another one (coordinate by coordinate division).
Definition: Vec3.h:245
void print(Stream &outputStream=Serial) const
Print a representation of the vector using a given stream object.
Definition: Vec3.h:450
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
void operator/=(const T v)
scalar division.
Definition: Vec3.h:287
void operator*=(const T v)
scalar multiplication.
Definition: Vec3.h:277
Vec3(const Vec3 &V)=default
Default copy constructor.
T norm2() const
Compute the squared euclidian norm of the vector.
Definition: Vec3.h:310
Vec3 & operator=(const Vec3 &V)=default
Default assignment operator.
void operator+=(const T v)
scalar addition.
Definition: Vec3.h:256
bool operator<(const Vec3 V) const
Less-than comparison operator.
Definition: Vec3.h:158
bool operator>(const Vec3 V) const
Greater-than comparison operator.
Definition: Vec3.h:194
bool operator<=(const Vec3 V) const
Less-than-or-equal comparison operator.
Definition: Vec3.h:176
void operator*=(const Vec3 V)
Multiply this vector by another one (coordinate by coordinate multiplication).
Definition: Vec3.h:234
Vec3()
default constructor: the vector content is undefined.
Definition: Vec3.h:89
bool operator==(const Vec3 V) const
Equality comparator.
Definition: Vec3.h:140
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
bool operator!=(const Vec3 V) const
Inequality operator.
Definition: Vec3.h:149
void operator-=(const T v)
scalar substraction.
Definition: Vec3.h:267
void normalize_fast()
Normalise the vector so that its norm is 1 (do nothing if the vector is 0).
Definition: Vec3.h:400
void normalize()
Normalise the vector so that its norm is 1 (do nothing if the vector is 0).
Definition: Vec3.h:382
Tfloat norm() const
Compute the euclidian norm of the vector.
Definition: Vec3.h:324
bool operator>=(const Vec3 V) const
Greater-than-or-equal comparison operator.
Definition: Vec3.h:203
void operator-=(const Vec3 V)
Substract another vector from this one.
Definition: Vec3.h:223
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