XII Release 0.1.0
Loading...
Searching...
No Matches
xiiVec4Template< Type > Class Template Reference

Copyright (c) Theophilus Eriata. All Rights Reserved. More...

#include <Vec4.h>

Public Types

using ComponentType = Type

Public Member Functions

 XII_DECLARE_POD_TYPE ()
 xiiVec4Template ()
 Default-constructed vector is uninitialized (for speed).
 xiiVec4Template (Type x, Type y, Type z, Type w)
 Initializes the vector with x,y,z,w.
 xiiVec4Template (xiiVec3Template< Type > vXyz, Type w)
 Initializes the vector from a vec3 and a float.
 xiiVec4Template (Type v)
 Initializes all 4 components with xyzw.
const xiiVec2Template< Type > GetAsVec2 () const
 Returns a xiiVec2Template with x and y from this vector.
const xiiVec3Template< Type > GetAsVec3 () const
 Returns a xiiVec3Template 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.
XII_DECLARE_IF_FLOAT_TYPE Type GetLength () const
 Returns the length of the vector.
Type GetLengthSquared () const
XII_DECLARE_IF_FLOAT_TYPE Type GetLengthAndNormalize ()
XII_DECLARE_IF_FLOAT_TYPE const xiiVec4Template< Type > GetNormalized () const
 Returns a normalized version of this vector, leaves the vector itself unchanged.
XII_DECLARE_IF_FLOAT_TYPE void Normalize ()
 Normalizes this vector.
XII_DECLARE_IF_FLOAT_TYPE xiiResult NormalizeIfNotZero (const xiiVec4Template< Type > &vFallback=xiiVec4Template< Type >(1, 0, 0, 0), Type fEpsilon=xiiMath::SmallEpsilon< Type >())
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).
XII_DECLARE_IF_FLOAT_TYPE bool IsNormalized (Type fEpsilon=xiiMath::HugeEpsilon< Type >()) const
 Returns, whether the squared length of this vector is between 0.999f and 1.001f.
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.
XII_DECLARE_IF_FLOAT_TYPE Type GetDistanceTo (const xiiVec4Template< Type > &rhs) const
 Returns the distance between two this position and rhs.
XII_DECLARE_IF_FLOAT_TYPE Type GetSquaredDistanceTo (const xiiVec4Template< Type > &rhs) const
 Returns the squared distance between this position and rhs.
const xiiVec4Template< Type > operator- () const
 Returns the negation of this vector.
void operator+= (const xiiVec4Template< Type > &vCc)
 Adds cc component-wise to this vector.
void operator-= (const xiiVec4Template< 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 xiiVec4Template< Type > &rhs) const
 Equality Check (bitwise).
bool IsEqual (const xiiVec4Template< Type > &rhs, Type fEpsilon) const
 Equality Check with epsilon.
Type Dot (const xiiVec4Template< Type > &rhs) const
 Returns the dot-product of the two vectors (commutative, order does not matter).
const xiiVec4Template< Type > CompMin (const xiiVec4Template< Type > &rhs) const
 Returns the component-wise minimum of *this and rhs.
const xiiVec4Template< Type > CompMax (const xiiVec4Template< Type > &rhs) const
 Returns the component-wise maximum of *this and rhs.
const xiiVec4Template< Type > CompClamp (const xiiVec4Template< Type > &vLow, const xiiVec4Template< Type > &vHigh) const
 Returns the component-wise clamped value of *this between low and high.
const xiiVec4Template< Type > CompMul (const xiiVec4Template< Type > &rhs) const
 Returns the component-wise multiplication of *this and rhs.
const xiiVec4Template< Type > CompDiv (const xiiVec4Template< Type > &rhs) const
 Returns the component-wise division of *this and rhs.
const xiiVec4Template< Type > Abs () const
 brief Returns the component-wise absolute of *this.

Static Public Member Functions

static XII_DECLARE_IF_FLOAT_TYPE constexpr xiiVec4Template< Type > MakeNaN ()
 Returns a vector with all components set to Not-a-Number (NaN).
static constexpr xiiVec4Template< 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 xiiVec4Template< Type >

Copyright (c) Theophilus Eriata. All Rights Reserved.

A 4-component vector class.

Member Function Documentation

◆ GetLengthAndNormalize()

template<typename Type>
XII_IMPLEMENT_IF_FLOAT_TYPE XII_FORCE_INLINE Type xiiVec4Template< Type >::GetLengthAndNormalize ( )

Normalizes this vector and returns its previous length in one operation. More efficient than calling GetLength and then Normalize.

◆ GetLengthSquared()

template<typename Type>
XII_FORCE_INLINE Type xiiVec4Template< 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.

◆ IsNormalized()

template<typename Type>
XII_IMPLEMENT_IF_FLOAT_TYPE bool xiiVec4Template< Type >::IsNormalized ( Type fEpsilon = xiiMath::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.

◆ NormalizeIfNotZero()

template<typename Type>
XII_IMPLEMENT_IF_FLOAT_TYPE xiiResult xiiVec4Template< Type >::NormalizeIfNotZero ( const xiiVec4Template< Type > & vFallback = xiiVec4Template<Type>(1, 0, 0, 0),
Type fEpsilon = xiiMath::SmallEpsilon<Type>() )
inline

Tries to normalize this vector. If the vector is too close to zero, XII_FAILURE is returned and the vector is set to the given fallback value.


The documentation for this class was generated from the following files:
  • /home/runner/work/XII/XII/Source/Engine/Foundation/Math/Declarations.h
  • /home/runner/work/XII/XII/Source/Engine/Foundation/Math/Vec4.h
  • /home/runner/work/XII/XII/Source/Engine/Foundation/Math/Implementation/Vec4_inl.h