TGX 1.1.2
A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.
Loading...
Searching...
No Matches
Vec4.h File Reference

4D vector. More...

#include <stdint.h>
#include "Misc.h"
#include "Vec2.h"
#include "Vec3.h"

Go to the source code of this file.

Classes

struct  tgx::Vec4< T >
 Geenric 4D vector [specializations iVec4, fVec4, dVec4]. More...
 

Typedefs

typedef Vec4< int > tgx::iVec4
 Integer-valued 4D vector.
 
typedef Vec4< float > tgx::fVec4
 Floating point valued 4D vector with single (float) precision.
 
typedef Vec4< double > tgx::dVec4
 Floating point valued 4D vector with double precision.
 

Functions

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
TGX_INLINE Vec4< T > tgx::normalize (Vec4< T > V)
 Return the vector normalized to have unit norm (do nothing if the vector is 0). More...
 
template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
TGX_INLINE Vec4< T > tgx::normalize_fast (Vec4< T > V)
 Return the vector normalized to have unit norm (do nothing if the vector is 0). More...
 
template<typename T >
TGX_INLINE T tgx::dist2 (const Vec4< T > &V1, const Vec4< T > &V2)
 Compute the squared euclidian distance between two vectors.
 
template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
TGX_INLINE Tfloat tgx::dist (const Vec4< T > &V1, const Vec4< T > &V2)
 Compute the euclidian distance between two vectors. More...
 
template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
TGX_INLINE Tfloat tgx::dist_fast (const Vec4< T > &V1, const Vec4< T > &V2)
 Compute the euclidian distance between two vectors. More...
 
template<typename T >
TGX_INLINE Vec4< T > tgx::operator+ (Vec4< T > V1, const Vec4< T > &V2)
 Addition operator. More...
 
template<typename T >
TGX_INLINE Vec4< T > tgx::operator- (Vec4< T > V1, const Vec4< T > &V2)
 Substraction operator. More...
 
template<typename T >
TGX_INLINE Vec4< T > tgx::operator* (Vec4< T > V1, const Vec4< T > &V2)
 Multiplication operator. More...
 
template<typename T >
TGX_INLINE Vec4< T > tgx::operator/ (Vec4< T > V1, const Vec4< T > &V2)
 Division operator. More...
 
template<typename T >
TGX_INLINE Vec4< T > tgx::operator+ (const T a, Vec4< T > V)
 Scalar addition operator.
 
template<typename T >
TGX_INLINE Vec4< T > tgx::operator+ (Vec4< T > V, const T a)
 Scalar addition operator.
 
template<typename T >
TGX_INLINE Vec4< T > tgx::operator- (Vec4< T > V, const T a)
 Scalar substraction operator.
 
template<typename T >
TGX_INLINE Vec4< T > tgx::operator* (const T a, Vec4< T > V)
 Scalar multiplication operator.
 
template<typename T >
TGX_INLINE Vec4< T > tgx::operator* (Vec4< T > V, const T a)
 Scalar multiplication operator.
 
template<typename T >
TGX_INLINE Vec4< T > tgx::operator/ (Vec4< T > V, const T a)
 Scalar division operator. More...
 
template<typename T >
TGX_INLINE T tgx::dotProduct (const Vec4< T > &U, const Vec4< T > &V)
 Return the dot product U.V between two vectors.
 
TGX_INLINE float tgx::dotProduct (const Vec4< float > &U, const Vec4< float > &V)
 Return the dot product U.V between two float vectors using fused multiply-add operations when enabled for the target architecture.
 
template<typename T >
TGX_INLINE Vec4< T > tgx::crossProduct (const Vec4< T > &U, const Vec4< T > &V)
 Return the cross product of u x v as 3-dim vector (and set w = 0).
 
template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
TGX_INLINE Vec4< T > tgx::lerp (const Tfloat alpha, const Vec4< T > &V1, const Vec4< T > &V2)
 Linear interpolation: V1 + alpha(V2 - V1).
 

Detailed Description

4D vector.

Function Documentation

◆ normalize()

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
TGX_INLINE Vec4< T > tgx::normalize ( Vec4< T >  V)
inline

Return the vector normalized to have unit norm (do nothing if the vector is 0).

Template Parameters
TfloatFloating point type used for computation (use default floating point type if unspecified).

◆ normalize_fast()

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
TGX_INLINE Vec4< T > tgx::normalize_fast ( Vec4< T >  V)
inline

Return the vector normalized to have unit norm (do nothing if the vector is 0).

Use fast_invsqrt() approximation to speedup computations.

Template Parameters
TfloatFloating point type used for computation (use default floating point type if unspecified).

◆ dist()

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
TGX_INLINE Tfloat tgx::dist ( const Vec4< T > &  V1,
const Vec4< T > &  V2 
)
inline

Compute the euclidian distance between two vectors.

Template Parameters
TfloatFloating point type used for computation (use default floating point type if unspecified).

◆ dist_fast()

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
TGX_INLINE Tfloat tgx::dist_fast ( const Vec4< T > &  V1,
const Vec4< T > &  V2 
)
inline

Compute the euclidian distance between two vectors.

Use fast_sqrt() approximation to speedup computations.

Template Parameters
TfloatFloating point type used for computation (use default floating point type if unspecified).

◆ operator+()

template<typename T >
TGX_INLINE Vec4< T > tgx::operator+ ( Vec4< T >  V1,
const Vec4< T > &  V2 
)
inline

Addition operator.

Coordinates by coordinates

◆ operator-()

template<typename T >
TGX_INLINE Vec4< T > tgx::operator- ( Vec4< T >  V1,
const Vec4< T > &  V2 
)
inline

Substraction operator.

Coordinates by coordinates

◆ operator*()

template<typename T >
TGX_INLINE Vec4< T > tgx::operator* ( Vec4< T >  V1,
const Vec4< T > &  V2 
)
inline

Multiplication operator.

Coordinates by coordinates

◆ operator/() [1/2]

template<typename T >
TGX_INLINE Vec4< T > tgx::operator/ ( Vec4< T >  V1,
const Vec4< T > &  V2 
)
inline

Division operator.

Coordinates by coordinates

◆ operator/() [2/2]

template<typename T >
TGX_INLINE Vec4< T > tgx::operator/ ( Vec4< T >  V,
const T  a 
)
inline

Scalar division operator.

Scalar division operator