3#include <Foundation/Math/Vec2.h>
4#include <Foundation/Math/Vec3.h>
9template <
typename Type>
17template <
typename Type>
25template <
typename Type>
34template <
typename Type>
42template <
typename Type>
51template <
typename Type>
62template <
typename Type>
65#if PL_ENABLED(PL_MATH_CHECK_FOR_NAN)
75template <
typename Type>
84template <
typename Type>
93template <
typename Type>
102template <
typename Type>
111template <
typename Type>
120template <
typename Type>
129template <
typename Type>
138template <
typename Type>
144template <
typename Type>
150template <
typename Type>
155 return (x * x + y * y + z * z + w * w);
158template <
typename Type>
161 const Type fLength = GetLength();
166template <
typename Type>
169 const Type fLen = GetLength();
175template <
typename Type>
178 *
this /= GetLength();
181template <
typename Type>
184 PL_NAN_ASSERT(&vFallback);
186 const Type fLength = GetLength();
188 if (!plMath::IsFinite(fLength) ||
plMath::IsZero(fLength, fEpsilon))
201template <
typename Type>
204 const Type t = GetLengthSquared();
208template <
typename Type>
213 return ((x == 0.0f) && (y == 0.0f) && (z == 0.0f) && (w == 0.0f));
216template <
typename Type>
224template <
typename Type>
227 if (plMath::IsNaN(x))
229 if (plMath::IsNaN(y))
231 if (plMath::IsNaN(z))
233 if (plMath::IsNaN(w))
239template <
typename Type>
242 if (!plMath::IsFinite(x))
244 if (!plMath::IsFinite(y))
246 if (!plMath::IsFinite(z))
248 if (!plMath::IsFinite(w))
254template <
typename Type>
262template <
typename Type>
273template <
typename Type>
284template <
typename Type>
295template <
typename Type>
298 if constexpr (std::is_floating_point_v<Type>)
317template <
typename Type>
323 return ((x * rhs.x) + (y * rhs.y) + (z * rhs.z) + (w * rhs.w));
326template <
typename Type>
335template <
typename Type>
344template <
typename Type>
348 PL_NAN_ASSERT(&vLow);
349 PL_NAN_ASSERT(&vHigh);
351 return plVec4Template<Type>(
plMath::Clamp(x, vLow.x, vHigh.x),
plMath::Clamp(y, vLow.y, vHigh.y),
plMath::Clamp(z, vLow.z, vHigh.z),
plMath::Clamp(w, vLow.w, vHigh.w));
354template <
typename Type>
363PL_MSVC_ANALYSIS_WARNING_PUSH
364PL_MSVC_ANALYSIS_WARNING_DISABLE(4723)
365template <typename Type>
373PL_MSVC_ANALYSIS_WARNING_POP
375template <
typename Type>
383template <
typename Type>
392template <
typename Type>
401template <
typename Type>
409template <
typename Type>
417template <
typename Type>
422 if constexpr (std::is_floating_point_v<Type>)
434template <
typename Type>
440 return ((x == rhs.x) && (y == rhs.y) && (z == rhs.z) && (w == rhs.w));
443template <
typename Type>
452template <
typename Type>
458template <
typename Type>
464template <
typename Type>
483 return (v1.w < v2.w);
A 2-component vector class.
Definition Vec2.h:14
const plVec3Template< Type > GetAsVec3(Type z) const
Returns an plVec3Template with x,y from this vector and z set by the parameter.
Definition Vec4_inl.h:10
const plVec4Template< Type > GetAsVec4(Type z, Type w) const
Returns an plVec4Template with x,y from this vector and z and w set by the parameters.
Definition Vec4_inl.h:18
A 3-component vector class.
Definition Vec3.h:9
const plVec4Template< Type > GetAsVec4(Type w) const
Returns an plVec4Template with x,y,z from this vector and w set to the parameter.
Definition Vec4_inl.h:35
const plVec4Template< Type > GetAsPositionVec4() const
Returns an plVec4Template with x,y,z from this vector and w set 1.
Definition Vec4_inl.h:43
const plVec4Template< Type > GetAsDirectionVec4() const
Returns an plVec4Template with x,y,z from this vector and w set 0.
Definition Vec4_inl.h:52
const plVec2Template< Type > GetAsVec2() const
Returns an plVec2Template with x and y from this vector.
Definition Vec4_inl.h:26
A 4-component vector class.
Definition Vec4.h:9
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 Vec4_inl.h:202
PL_DECLARE_IF_FLOAT_TYPE plResult NormalizeIfNotZero(const plVec4Template< Type > &vFallback=plVec4Template< Type >(1, 0, 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 Vec4_inl.h:182
plVec4Template()
Default-constructed vector is uninitialized (for speed)
Definition Vec4_inl.h:63
const plVec4Template< Type > CompMin(const plVec4Template< Type > &rhs) const
Returns the component-wise minimum of *this and rhs.
Definition Vec4_inl.h:327
bool IsZero() const
Returns, whether this vector is (0, 0, 0, 0).
Definition Vec4_inl.h:209
bool IsEqual(const plVec4Template< Type > &rhs, Type fEpsilon) const
Equality Check with epsilon.
Definition Vec4_inl.h:444
void SetZero()
Sets the vector to all zero.
Definition Vec4_inl.h:139
PL_DECLARE_IF_FLOAT_TYPE Type GetLengthAndNormalize()
Normalizes this vector and returns its previous length in one operation. More efficient than calling ...
Definition Vec4_inl.h:159
const plVec3Template< Type > GetAsVec3() const
Returns an plVec3Template with x,y and z from this vector.
Definition Vec4_inl.h:112
void operator-=(const plVec4Template< Type > &vCc)
Subtracts cc component-wise from this vector.
Definition Vec4_inl.h:274
bool IsNaN() const
Returns true, if any of x, y, z or w is NaN.
Definition Vec4_inl.h:225
const plVec4Template< Type > CompClamp(const plVec4Template< Type > &vLow, const plVec4Template< Type > &vHigh) const
Returns the component-wise clamped value of *this between low and high.
Definition Vec4_inl.h:345
PL_DECLARE_IF_FLOAT_TYPE void Normalize()
Normalizes this vector.
Definition Vec4_inl.h:176
const plVec4Template< Type > operator-() const
Returns the negation of this vector.
Definition Vec4_inl.h:255
void operator/=(Type f)
Divides all components of this vector by f.
Definition Vec4_inl.h:296
const plVec4Template< Type > Abs() const
brief Returns the component-wise absolute of *this.
Definition Vec4_inl.h:376
PL_DECLARE_IF_FLOAT_TYPE const plVec4Template< Type > GetNormalized() const
Returns a normalized version of this vector, leaves the vector itself unchanged.
Definition Vec4_inl.h:167
Type Dot(const plVec4Template< Type > &rhs) const
Returns the dot-product of the two vectors (commutative, order does not matter).
Definition Vec4_inl.h:318
void operator*=(Type f)
Multiplies all components of this vector with f.
Definition Vec4_inl.h:285
void Set(Type xyzw)
Sets all 4 components to this value.
Definition Vec4_inl.h:121
const plVec4Template< Type > CompMul(const plVec4Template< Type > &rhs) const
Returns the component-wise multiplication of *this and rhs.
Definition Vec4_inl.h:355
void operator+=(const plVec4Template< Type > &vCc)
Adds cc component-wise to this vector.
Definition Vec4_inl.h:263
bool IsIdentical(const plVec4Template< Type > &rhs) const
Equality Check (bitwise).
Definition Vec4_inl.h:435
const plVec4Template< Type > CompMax(const plVec4Template< Type > &rhs) const
Returns the component-wise maximum of *this and rhs.
Definition Vec4_inl.h:336
const plVec2Template< Type > GetAsVec2() const
Returns an plVec2Template with x and y from this vector.
Definition Vec4_inl.h:103
bool IsValid() const
Checks that all components are finite numbers.
Definition Vec4_inl.h:240
Type GetLengthSquared() const
Returns the squared length. Faster, since no square-root is taken. Useful, if one only wants to compa...
Definition Vec4_inl.h:151
PL_DECLARE_IF_FLOAT_TYPE Type GetLength() const
Returns the length of the vector.
Definition Vec4_inl.h:145
constexpr PL_ALWAYS_INLINE T Min(T f1, T f2)
Returns the smaller value, f1 or f2.
Definition Math_inl.h:27
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
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54