ezEngine  Release 25.03
ezVec4Template< Type > Class Template Reference

A 4-component vector class. More...

#include <Vec4.h>

Public Types

using ComponentType = Type
 

Public Member Functions

 EZ_DECLARE_POD_TYPE ()
 
 ezVec4Template ()
 Default-constructed vector is uninitialized (for speed)
 
 ezVec4Template (Type x, Type y, Type z, Type w)
 Initializes the vector with x,y,z,w.
 
 ezVec4Template (ezVec3Template< Type > vXyz, Type w)
 Initializes the vector from a vec3 and a float.
 
 ezVec4Template (Type v)
 Initializes all 4 components with xyzw.
 
const ezVec2Template< Type > GetAsVec2 () const
 Returns an ezVec2Template with x and y from this vector.
 
const ezVec3Template< Type > GetAsVec3 () const
 Returns an ezVec3Template with x,y and z from this vector.
 
const Type * GetData () const
 Returns the data as an array.
 
Type * GetData ()
 Returns the data as an array.
 
void Set (Type xyzw)
 Sets all 4 components to this value.
 
void Set (Type x, Type y, Type z, Type w)
 Sets the vector to these values.
 
void SetZero ()
 Sets the vector to all zero.
 
EZ_DECLARE_IF_FLOAT_TYPE Type GetLength () const
 Returns the length of the vector.
 
Type GetLengthSquared () const
 Returns the squared length. Faster, since no square-root is taken. Useful, if one only wants to compare the lengths of two vectors.
 
EZ_DECLARE_IF_FLOAT_TYPE Type GetLengthAndNormalize ()
 Normalizes this vector and returns its previous length in one operation. More efficient than calling GetLength and then Normalize.
 
const EZ_DECLARE_IF_FLOAT_TYPE ezVec4Template< Type > GetNormalized () const
 Returns a normalized version of this vector, leaves the vector itself unchanged.
 
EZ_DECLARE_IF_FLOAT_TYPE void Normalize ()
 Normalizes this vector.
 
EZ_DECLARE_IF_FLOAT_TYPE ezResult NormalizeIfNotZero (const ezVec4Template< Type > &vFallback=ezVec4Template< Type >(1, 0, 0, 0), Type fEpsilon=ezMath::SmallEpsilon< Type >())
 Tries to normalize this vector. If the vector is too close to zero, EZ_FAILURE is returned and the vector is set to the given fallback value.
 
bool IsZero () const
 Returns, whether this vector is (0, 0, 0, 0).
 
bool IsZero (Type fEpsilon) const
 Returns, whether this vector is (0, 0, 0, 0).
 
EZ_DECLARE_IF_FLOAT_TYPE bool IsNormalized (Type fEpsilon=ezMath::HugeEpsilon< Type >()) const
 Returns, whether the squared length of this vector is between 0.999f and 1.001f. More...
 
bool IsNaN () const
 Returns true, if any of x, y, z or w is NaN.
 
bool IsValid () const
 Checks that all components are finite numbers.
 
const ezVec4Template< Type > operator- () const
 Returns the negation of this vector.
 
void operator+= (const ezVec4Template< Type > &vCc)
 Adds cc component-wise to this vector.
 
void operator-= (const ezVec4Template< Type > &vCc)
 Subtracts cc component-wise from this vector.
 
void operator*= (Type f)
 Multiplies all components of this vector with f.
 
void operator/= (Type f)
 Divides all components of this vector by f.
 
bool IsIdentical (const ezVec4Template< Type > &rhs) const
 Equality Check (bitwise).
 
bool IsEqual (const ezVec4Template< Type > &rhs, Type fEpsilon) const
 Equality Check with epsilon.
 
Type Dot (const ezVec4Template< Type > &rhs) const
 Returns the dot-product of the two vectors (commutative, order does not matter).
 
const ezVec4Template< Type > CompMin (const ezVec4Template< Type > &rhs) const
 Returns the component-wise minimum of *this and rhs.
 
const ezVec4Template< Type > CompMax (const ezVec4Template< Type > &rhs) const
 Returns the component-wise maximum of *this and rhs.
 
const ezVec4Template< Type > CompClamp (const ezVec4Template< Type > &vLow, const ezVec4Template< Type > &vHigh) const
 Returns the component-wise clamped value of *this between low and high.
 
const ezVec4Template< Type > CompMul (const ezVec4Template< Type > &rhs) const
 Returns the component-wise multiplication of *this and rhs.
 
const ezVec4Template< Type > CompDiv (const ezVec4Template< Type > &rhs) const
 Returns the component-wise division of *this and rhs.
 
const ezVec4Template< Type > Abs () const
 brief Returns the component-wise absolute of *this.
 

Static Public Member Functions

static EZ_DECLARE_IF_FLOAT_TYPE ezVec4Template< Type > MakeNaN ()
 Returns a vector with all components set to Not-a-Number (NaN).
 
static ezVec4Template< Type > MakeZero ()
 Returns a vector with all components set to zero.
 

Public Attributes

Type x
 
Type y
 
Type z
 
Type w
 

Detailed Description

template<typename Type>
class ezVec4Template< Type >

A 4-component vector class.

Member Function Documentation

◆ IsNormalized()

template<typename Type >
EZ_IMPLEMENT_IF_FLOAT_TYPE bool ezVec4Template< Type >::IsNormalized ( Type  fEpsilon = ezMath::HugeEpsilon<Type>()) const
inline

Returns, whether the squared length of this vector is between 0.999f and 1.001f.

Note
Normalization, especially with SSE is not very precise. So this function checks whether the (squared) length is between a lower and upper limit.

The documentation for this class was generated from the following files: