TGX 1.0.3
A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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>
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>
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::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>
Tfloat tgx::dist (Vec4< T > V1, const Vec4< T > V2)
 Compute the euclidian distance between two vectors. More...
 
template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat tgx::dist_fast (Vec4< T > V1, const Vec4< T > V2)
 Compute the euclidian distance between two vectors. More...
 
template<typename T >
Vec4< T > tgx::operator+ (Vec4< T > V1, const Vec4< T > V2)
 Addition operator. More...
 
template<typename T >
Vec4< T > tgx::operator- (Vec4< T > V1, const Vec4< T > V2)
 Substraction operator. More...
 
template<typename T >
Vec4< T > tgx::operator* (Vec4< T > V1, const Vec4< T > V2)
 Multiplication operator. More...
 
template<typename T >
Vec4< T > tgx::operator/ (Vec4< T > V1, const Vec4< T > V2)
 Division operator. More...
 
template<typename T >
Vec4< T > tgx::operator+ (const T a, Vec4< T > V)
 Scalar addition operator.
 
template<typename T >
Vec4< T > tgx::operator+ (Vec4< T > V, const T a)
 Scalar addition operator.
 
template<typename T >
Vec4< T > tgx::operator- (const T a, Vec4< T > V)
 Scalar substraction operator.
 
template<typename T >
Vec4< T > tgx::operator- (Vec4< T > V, const T a)
 Scalar substraction operator.
 
template<typename T >
Vec4< T > tgx::operator* (const T a, Vec4< T > V)
 Scalar multiplication operator.
 
template<typename T >
Vec4< T > tgx::operator* (Vec4< T > V, const T a)
 Scalar multiplication operator.
 
template<typename T >
Vec4< T > tgx::operator/ (const T a, Vec4< T > V)
 Scalar division operator.
 
template<typename T >
Vec4< T > tgx::operator/ (Vec4< T > V, const T a)
 Scalar division operator.
 
template<typename T >
tgx::dotProduct (const Vec4< T > U, const Vec4< T > V)
 Return the dot product U.V between two vectors.
 
template<typename T >
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>
Vec4< T > tgx::lerp (Tfloat alpha, Vec4< T > V1, 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>
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>
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>
Tfloat tgx::dist ( Vec4< T >  V1,
const Vec4< T >  V2 
)

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>
Tfloat tgx::dist_fast ( Vec4< T >  V1,
const Vec4< T >  V2 
)

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 >
Vec4< T > tgx::operator+ ( Vec4< T >  V1,
const Vec4< T >  V2 
)
inline

Addition operator.

Coordinates by coordinates

◆ operator-()

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

Substraction operator.

Coordinates by coordinates

◆ operator*()

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

Multiplication operator.

Coordinates by coordinates

◆ operator/()

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

Division operator.

Coordinates by coordinates