3template <
typename Type>
6#if PL_ENABLED(PL_MATH_CHECK_FOR_NAN)
15template <
typename Type>
23template <
typename Type>
31template <
typename Type>
39template <
typename Type>
47template <
typename Type>
53template <
typename Type>
59template <
typename Type>
69template <
typename Type>
74 return (x * x + y * y + z * z);
77template <
typename Type>
80 const Type fLength = GetLength();
85template <
typename Type>
88 const Type fLen = GetLength();
94template <
typename Type>
100template <
typename Type>
103 PL_NAN_ASSERT(&vFallback);
105 const Type fLength = GetLength();
107 if (!plMath::IsFinite(fLength) ||
plMath::IsZero(fLength, fEpsilon))
120template <
typename Type>
123 const Type t = GetLengthSquared();
127template <
typename Type>
132 return ((x == 0.0f) && (y == 0.0f) && (z == 0.0f));
135template <
typename Type>
143template <
typename Type>
146 if (plMath::IsNaN(x))
148 if (plMath::IsNaN(y))
150 if (plMath::IsNaN(z))
156template <
typename Type>
159 if (!plMath::IsFinite(x))
161 if (!plMath::IsFinite(y))
163 if (!plMath::IsFinite(z))
169template <
typename Type>
177template <
typename Type>
187template <
typename Type>
197template <
typename Type>
209template <
typename Type>
221template <
typename Type>
231template <
typename Type>
234 if constexpr (std::is_floating_point_v<Type>)
252template <
typename Type>
255 *
this = (v3 - v2).CrossRH(v1 - v2);
256 return NormalizeIfNotZero();
259template <
typename Type>
263 vNormal.
IsNormalized(),
"The vector to make this vector orthogonal to, must be normalized. It's length is {0}",
plArgF(vNormal.
GetLength(), 3));
266 *
this = vOrtho.
CrossRH(vNormal);
269template <
typename Type>
272 PL_ASSERT_DEBUG(!IsZero(plMath::SmallEpsilon<Type>()),
"The vector must not be zero to be able to compute an orthogonal vector.");
281template <
typename Type>
284 PL_ASSERT_DEBUG(vNormal.
IsNormalized(),
"vNormal must be normalized.");
286 return ((*
this) - ((Type)2 * this->Dot(vNormal) * vNormal));
289template <
typename Type>
295 return ((x * rhs.x) + (y * rhs.y) + (z * rhs.z));
298template <
typename Type>
304 return plVec3Template<Type>(y * rhs.z - z * rhs.y, z * rhs.x - x * rhs.z, x * rhs.y - y * rhs.x);
307template <
typename Type>
310 PL_ASSERT_DEBUG(this->IsNormalized(),
"This vector must be normalized.");
311 PL_ASSERT_DEBUG(rhs.
IsNormalized(),
"The other vector must be normalized.");
316template <
typename Type>
325template <
typename Type>
334template <
typename Type>
338 PL_NAN_ASSERT(&vLow);
339 PL_NAN_ASSERT(&vHigh);
344template <
typename Type>
353template <
typename Type>
362template <
typename Type>
370template <
typename Type>
379template <
typename Type>
388template <
typename Type>
396template <
typename Type>
404template <
typename Type>
409 if constexpr (std::is_floating_point_v<Type>)
421template <
typename Type>
427 return ((x == rhs.x) && (y == rhs.y) && (z == rhs.z));
430template <
typename Type>
439template <
typename Type>
445template <
typename Type>
451template <
typename Type>
466 return (v1.z < v2.z);
469template <
typename Type>
472 PL_ASSERT_DEBUG(vNormal.
IsNormalized(),
"vNormal must be normalized.");
474 const Type n = fRefIndex1 / fRefIndex2;
475 const Type cosI = this->Dot(vNormal);
476 const Type sinT2 = n * n * (1.0f - (cosI * cosI));
482 return ((n * (*
this)) - (n +
plMath::Sqrt(1.0f - sinT2)) * vNormal);
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
A 3-component vector class.
Definition Vec3.h:9
void Set(Type xyz)
Sets all 3 components to this value.
Definition Vec3_inl.h:32
PL_DECLARE_IF_FLOAT_TYPE Type GetLength() const
Returns the length of the vector.
Definition Vec3_inl.h:54
const plVec3Template< Type > CompClamp(const plVec3Template< Type > &vLow, const plVec3Template< Type > &vHigh) const
Returns the component-wise clamped value of *this between low and high.
Definition Vec3_inl.h:335
bool IsNaN() const
Returns true, if any of x, y or z is NaN.
Definition Vec3_inl.h:144
const plVec3Template< Type > CompDiv(const plVec3Template< Type > &rhs) const
Returns the component-wise division of *this and rhs.
Definition Vec3_inl.h:354
const plVec3Template< Type > CompMin(const plVec3Template< Type > &rhs) const
Returns the component-wise minimum of *this and rhs.
Definition Vec3_inl.h:317
const plVec3Template< Type > CrossRH(const plVec3Template< Type > &rhs) const
Returns the Cross-product of the two vectors (NOT commutative, order DOES matter)
Definition Vec3_inl.h:299
bool IsIdentical(const plVec3Template< Type > &rhs) const
Equality Check (bitwise)
Definition Vec3_inl.h:422
void operator+=(const plVec3Template< Type > &rhs)
Adds rhs component-wise to this vector.
Definition Vec3_inl.h:178
const plVec3Template< Type > Abs() const
brief Returns the component-wise absolute of *this.
Definition Vec3_inl.h:363
bool IsValid() const
Checks that all components are finite numbers.
Definition Vec3_inl.h:157
PL_DECLARE_IF_FLOAT_TYPE bool IsNormalized(Type fEpsilon=plMath::HugeEpsilon< Type >()) const
Returns, whether the squared length of this vector is between 0.999f and 1.001f.
Definition Vec3_inl.h:121
void operator*=(const plVec3Template< Type > &rhs)
Multiplies rhs component-wise to this vector.
Definition Vec3_inl.h:198
Type GetLengthSquared() const
Returns the squared length. Faster, since no square-root is taken. Useful, if one only wants to compa...
Definition Vec3_inl.h:70
PL_DECLARE_IF_FLOAT_TYPE const plVec3Template< Type > GetReflectedVector(const plVec3Template< Type > &vNormal) const
Returns this vector reflected at vNormal.
Definition Vec3_inl.h:282
bool IsEqual(const plVec3Template< Type > &rhs, Type fEpsilon) const
Equality Check with epsilon.
Definition Vec3_inl.h:431
const plVec3Template< Type > CompMax(const plVec3Template< Type > &rhs) const
Returns the component-wise maximum of *this and rhs.
Definition Vec3_inl.h:326
PL_DECLARE_IF_FLOAT_TYPE Type GetLengthAndNormalize()
Normalizes this vector and returns its previous length in one operation. More efficient than calling ...
Definition Vec3_inl.h:78
PL_DECLARE_IF_FLOAT_TYPE void Normalize()
Normalizes this vector.
Definition Vec3_inl.h:95
void SetZero()
Sets the vector to all zero.
Definition Vec3_inl.h:48
PL_DECLARE_IF_FLOAT_TYPE const plVec3Template< Type > GetNormalized() const
Returns a normalized version of this vector, leaves the vector itself unchanged.
Definition Vec3_inl.h:86
PL_DECLARE_IF_FLOAT_TYPE plResult NormalizeIfNotZero(const plVec3Template< Type > &vFallback=plVec3Template< Type >(1, 0, 0), Type fEpsilon=plMath::SmallEpsilon< Type >())
Tries to normalize this vector. If the vector is too close to zero, PL_FAILURE is returned and the ve...
Definition Vec3_inl.h:101
void operator/=(const plVec3Template< Type > &rhs)
Divides this vector component-wise by rhs.
Definition Vec3_inl.h:210
Type Dot(const plVec3Template< Type > &rhs) const
Returns the Dot-product of the two vectors (commutative, order does not matter)
Definition Vec3_inl.h:290
void operator-=(const plVec3Template< Type > &rhs)
Subtracts rhs component-wise from this vector.
Definition Vec3_inl.h:188
const plVec3Template< Type > CompMul(const plVec3Template< Type > &rhs) const
Returns the component-wise multiplication of *this and rhs.
Definition Vec3_inl.h:345
bool IsZero() const
Returns, whether this vector is (0, 0, 0).
Definition Vec3_inl.h:128
plVec3Template()
default-constructed vector is uninitialized (for speed)
Definition Vec3_inl.h:4
PL_DECLARE_IF_FLOAT_TYPE const plVec3Template< Type > GetOrthogonalVector() const
Returns some arbitrary vector orthogonal to this one. The vector is NOT normalized.
Definition Vec3_inl.h:270
PL_DECLARE_IF_FLOAT_TYPE const plVec3Template< Type > GetRefractedVector(const plVec3Template< Type > &vNormal, Type fRefIndex1, Type fRefIndex2) const
Returns this vector, refracted at vNormal, using the refraction index of the current medium and the m...
Definition Vec3_inl.h:470
PL_DECLARE_IF_FLOAT_TYPE void MakeOrthogonalTo(const plVec3Template< Type > &vNormal)
Modifies this direction vector to be orthogonal to the given (normalized) direction vector....
Definition Vec3_inl.h:260
const plVec3Template< Type > operator-() const
Returns the negation of this vector.
Definition Vec3_inl.h:170
PL_DECLARE_IF_FLOAT_TYPE plResult CalculateNormal(const plVec3Template< Type > &v1, const plVec3Template< Type > &v2, const plVec3Template< Type > &v3)
Calculates the normal of the triangle defined by the three vertices. Vertices are assumed to be order...
Definition Vec3_inl.h:253
plAngle GetAngleBetween(const plVec3Template< Type > &rhs) const
Returns the positive angle between *this and rhs. Both this and rhs must be normalized.
Definition Vec3_inl.h:308
PL_DECLARE_IF_FLOAT_TYPE plResult SetLength(Type fNewLength, Type fEpsilon=plMath::DefaultEpsilon< Type >())
Tries to rescale the vector to the given length. If the vector is too close to zero,...
Definition Vec3_inl.h:60
constexpr PL_ALWAYS_INLINE T Min(T f1, T f2)
Returns the smaller value, f1 or f2.
Definition Math_inl.h:27
PL_ALWAYS_INLINE plAngle ACos(float f)
Returns the arcus cosinus of f.
Definition MathFloat_inl.h:82
constexpr Type Invert(Type f)
Returns 1 / f.
Definition Math_inl.h:63
constexpr PL_ALWAYS_INLINE T Clamp(T value, T min_val, T max_val)
Clamps "value" to the range [min; max]. Returns "value", if it is inside the range already.
Definition Math_inl.h:51
constexpr TYPE NaN()
Returns the value for NaN as the template type. Returns zero, if the type does not support NaN.
Definition Constants_inl.h:58
PL_ALWAYS_INLINE double Sqrt(double f)
Returns the square root of f.
Definition MathDouble_inl.h:99
bool IsZero(Type f, Type fEpsilon)
Checks whether the given number is close to zero.
Definition Math_inl.h:288
constexpr bool IsEqual(Type lhs, Type rhs, Type fEpsilon)
Checks, whether fValue is in the range [fDesired - fMaxImprecision; fDesired + fMaxImprecision].
Definition Math_inl.h:276
constexpr PL_ALWAYS_INLINE T Abs(T f)
Returns the absolute value of f.
Definition Math_inl.h:21
constexpr PL_ALWAYS_INLINE T Max(T f1, T f2)
Returns the greater value, f1 or f2.
Definition Math_inl.h:39
Definition FormatStringArgs.h:48
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54