| TGX 1.0.8 A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.

Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
tgx::Vec4< T > Struct Template Reference

Geenric 4D vector [specializations iVec4, fVec4, dVec4]. More...

`#include <Vec4.h>`

Inheritance diagram for tgx::Vec4< T >:

## Public Member Functions
| Vec4 ()
| default constructor: the vector content is undefined.
constexpr | Vec4 (T X, T Y, T Z, T W)
| Constructor with explicit initialization.
| Vec4 (const Vec4 &V)=default
| Default copy constructor.
constexpr | Vec4 (Vec2< T > V, T Z, T W)
| Constructor from a Vec2.
constexpr | Vec4 (Vec3< T > V, T W)
| Constructor from a Vec3.
Vec4 & | operator= (const Vec4 &V)=default
| Default assignment operator.
template<typename U >
| operator Vec4< U > () const
| Explicit conversion to another vector with different integral type. More...
| operator Vec4< typename DefaultFPType< T >::fptype > () const
| Implicit conversion to floating point type vector.
bool | operator== (const Vec4 V) const
| Equality comparator. More...
bool | operator!= (const Vec4 V) const
| Inequality operator.
bool | operator< (const Vec4 V) const
| Less-than comparison operator. More...
bool | operator<= (const Vec4 V) const
| Less-than-or-equal comparison operator. More...
bool | operator> (const Vec4 V) const
| Greater-than comparison operator. More...
bool | operator>= (const Vec4 V) const
| Greater-than-or-equal comparison operator. More...
void | operator+= (const Vec4 V)
| Add another vector to this one.
void | operator-= (const Vec4 V)
| Substract another vector from this one.
void | operator*= (const Vec4 V)
| Multiply this vector by another one (coordinate by coordinate multiplication).
void | operator/= (const Vec4 V)
| Divide this vector by another one (coordinate by coordinate division).
void | operator+= (const T v)
| Scalar addition. More...
void | operator-= (const T v)
| Scalar substraction. More...
void | operator*= (const T v)
| Scalar multiplication. More...
void | operator/= (const T v)
| Scalar division. More...
T | norm2 () const
| Compute the squared euclidian norm of the vector. More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat | norm () const
| Compute the euclidian norm of the vector. More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat | norm_fast () const
| Compute the euclidian norm of the vector. More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat | invnorm () const
| Compute the inverse of the euclidian norm of the vector. More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat | invnorm_fast () const
| Compute the inverse of the euclidian norm of the vector. More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
void | normalize ()
| Normalise the vector so that its norm is 1 (do nothing if the vector is 0). More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
void | normalize_fast ()
| Normalise the vector so that its norm is 1 (do nothing if the vector is 0). More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Vec4< T > | getNormalize () const
| Return the vector normalized to have unit norm (do nothing if the vector is 0). More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Vec4< T > | getNormalize_fast () const
| Return the vector normalized to have unit norm (do nothing if the vector is 0). More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
void | zdivide ()
| Performs the 'z-divide' operation. More...
Public Member Functions inherited from tgx::Vec3< T >
| Vec3 ()
| default constructor: the vector content is undefined.
constexpr | Vec3 (T X, T Y, T Z)
| Constructor with explicit initialization.
| Vec3 (const Vec3 &V)=default
| Default copy constructor.
constexpr | Vec3 (Vec2< T > V, T Z)
| Constructor from a Vec2.
Vec3 & | operator= (const Vec3 &V)=default
| Default assignment operator.
template<typename U >
| operator Vec3< U > () const
| Explicit conversion to another vector with different integral type. More...
| operator Vec3< typename DefaultFPType< T >::fptype > () const
| Implicit conversion to floating point type vector.
bool | operator== (const Vec3 V) const
| Equality comparator. More...
bool | operator!= (const Vec3 V) const
| Inequality operator.
bool | operator< (const Vec3 V) const
| Less-than comparison operator. More...
bool | operator<= (const Vec3 V) const
| Less-than-or-equal comparison operator. More...
bool | operator> (const Vec3 V) const
| Greater-than comparison operator. More...
bool | operator>= (const Vec3 V) const
| Greater-than-or-equal comparison operator. More...
void | operator+= (const Vec3 V)
| Add another vector to this one.
void | operator-= (const Vec3 V)
| Substract another vector from this one.
void | operator*= (const Vec3 V)
| Multiply this vector by another one (coordinate by coordinate multiplication).
void | operator/= (const Vec3 V)
| Divide this vector by another one (coordinate by coordinate division).
void | operator+= (const T v)
| scalar addition. More...
void | operator-= (const T v)
| scalar substraction. More...
void | operator*= (const T v)
| scalar multiplication. More...
void | operator/= (const T v)
| scalar division. More...
Vec3 | operator- () const
| unary negation operator
T | norm2 () const
| Compute the squared euclidian norm of the vector. More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat | norm () const
| Compute the euclidian norm of the vector. More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat | norm_fast () const
| Compute the euclidian norm of the vector. More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat | invnorm () const
| Compute the inverse of the euclidian norm of the vector. More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat | invnorm_fast () const
| Compute the inverse of the euclidian norm of the vector. More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
void | normalize ()
| Normalise the vector so that its norm is 1 (do nothing if the vector is 0). More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
void | normalize_fast ()
| Normalise the vector so that its norm is 1 (do nothing if the vector is 0). More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Vec3< T > | getNormalize () const
| Return the vector normalized to have unit norm (do nothing if the vector is 0). More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Vec3< T > | getNormalize_fast () const
| Return the vector normalized to have unit norm (do nothing if the vector is 0). More...
Public Member Functions inherited from tgx::Vec2< T >
| Vec2 ()
| default constructor: the vector content is undefined.
constexpr | Vec2 (T X, T Y)
| Constructor with explicit initialization.
| Vec2 (const Vec2 &v)=default
| Default copy constructor.
Vec2 & | operator= (const Vec2 &V)=default
| Default assignment operator.
template<typename U >
| operator Vec2< U > () const
| Explicit conversion to another vector with different integral type. More...
| operator Vec2< typename DefaultFPType< T >::fptype > () const
| Implicit conversion to floating-point type vector.
bool | operator== (const Vec2 V) const
| Equality comparator. More...
bool | operator!= (const Vec2 V) const
| Inequality operator.
bool | operator< (const Vec2 V) const
| Less-than comparison operator. More...
bool | operator<= (const Vec2 V) const
| Less-than-or-equal comparison operator. More...
bool | operator> (const Vec2 V) const
| Greater-than comparison operator. More...
bool | operator>= (const Vec2 V) const
| Greater-than-or-equal comparison operator. More...
void | operator+= (const Vec2 V)
| Add another vector to this one.
void | operator-= (const Vec2 V)
| Substract another vector from this one.
void | operator*= (const Vec2 V)
| Multiply this vector by another one (coordinate by coordinate multiplication).
void | operator/= (const Vec2 V)
| Divide this vector by another one (coordinate by coordinate division).
void | operator+= (const T &v)
| scalar addition. More...
void | operator-= (const T &v)
| scalar substraction. More...
void | operator*= (const T &v)
| scalar multiplication. More...
void | operator/= (const T &v)
| scalar division. More...
Vec2 | operator- () const
| unary negation operator
T | norm2 () const
| Compute the squared euclidian norm of the vector. More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat | norm () const
| Compute the euclidian norm of the vector. More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat | norm_fast () const
| Compute the euclidian norm of the vector. More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat | invnorm () const
| Compute the inverse of the euclidian norm of the vector. More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat | invnorm_fast () const
| Compute the inverse of the euclidian norm of the vector. More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
void | normalize ()
| Normalise the vector so that its norm is 1 (do nothing if the vector is 0). More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
void | normalize_fast ()
| Normalise the vector so that its norm is 1 (do nothing if the vector is 0). More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Vec2< T > | getNormalize () const
| Return the vector normalized to have unit norm (do nothing if the vector is 0). More...
template<typename Tfloat = typename DefaultFPType<T>::fptype>
Vec2< T > | getNormalize_fast () const
| Return the vector normalized to have unit norm (do nothing if the vector is 0). More...
void | rotate90 ()
| Rotate this vector by +90 degree (anti-clockise).
Vec2< T > | getRotate90 () const
| Return the vector obtained after rotation by +90 degree (anti-clockise).
int | leftOf (Vec2< T > LA, Vec2< T > LB) const
| Determine which half-space delimited by the line (LA,LB) the point represented by this vector belongs. More...
bool | setAsIntersection (Vec2< T > LA1, Vec2< T > LA2, Vec2< T > LB1, Vec2< T > LB2)
| Set this vector as the intersection of the two lines (LA1,LA2) and (LB1,LB2). More...

## Public Attributes
T | w
| 'w' coordinate (fourth dimension)
Public Attributes inherited from tgx::Vec3< T >
T | z
| 'z' coordinate (third dimension)
Public Attributes inherited from tgx::Vec2< T >
T | x
| 'x' coordinate (first dimension)
T | y
| 'y' coordinate (second dimension)

## Detailed Description

template<typename T>
struct tgx::Vec4< T >

Geenric 4D vector [specializations iVec4, fVec4, dVec4].

The class contains four public member variables `x`, `y`, `z` and `w` which define the 3D vector `(x,y,z,w)`.

Template Parameters

  `T` | arithmetic type of the vector (`int`, `float`...)

See also
  `Vec2`,`Vec3`

## Member Function Documentation

## ◆ operator Vec4< U >()

template<typename T >
template<typename U >

tgx::Vec4< T >::operator Vec4< U > | ( |  | ) | const
| inline explicit

Explicit conversion to another vector with different integral type.

Warning
  The conversion of the vectors components values from type `T` to type `U` is performed with a simple C-style cast.

## ◆ operator==()

template<typename T >

bool tgx::Vec4< T >::operator== | ( | const Vec4< T > | V | ) | const
| inline

Equality comparator.

Return true if all components compare equal.

## ◆ operator<()

template<typename T >

bool tgx::Vec4< T >::operator< | ( | const Vec4< T > | V | ) | const
| inline

Less-than comparison operator.

Use lexicographical order.

## ◆ operator<=()

template<typename T >

bool tgx::Vec4< T >::operator<= | ( | const Vec4< T > | V | ) | const
| inline

Less-than-or-equal comparison operator.

Use lexicographical order.

## ◆ operator>()

template<typename T >

bool tgx::Vec4< T >::operator> | ( | const Vec4< T > | V | ) | const
| inline

Greater-than comparison operator.

Use lexicographical order.

## ◆ operator>=()

template<typename T >

bool tgx::Vec4< T >::operator>= | ( | const Vec4< T > | V | ) | const
| inline

Greater-than-or-equal comparison operator.

Use lexicographical order.

## ◆ operator+=()

template<typename T >

void tgx::Vec4< T >::operator+= | ( | const T | v | ) |
| inline

Scalar addition.

Add v to each of the vector components.

## ◆ operator-=()

template<typename T >

void tgx::Vec4< T >::operator-= | ( | const T | v | ) |
| inline

Scalar substraction.

Add v to each of the vector components.

## ◆ operator*=()

template<typename T >

void tgx::Vec4< T >::operator*= | ( | const T | v | ) |
| inline

Scalar multiplication.

Multiply each of the vector components by v.

## ◆ operator/=()

template<typename T >

void tgx::Vec4< T >::operator/= | ( | const T | v | ) |
| inline

Scalar division.

Divde each of the vector components by v.

## ◆ norm2()

template<typename T >

T tgx::Vec4< T >::norm2 | ( |  | ) | const
| inline

Compute the squared euclidian norm of the vector.

See also
  norm(), norm_fast()

## ◆ norm()

template<typename T >
template<typename Tfloat = typename DefaultFPType<T>::fptype>

Tfloat tgx::Vec4< T >::norm | ( |  | ) | const
| inline

Compute the euclidian norm of the vector.

Template Parameters

  Tfloat | Return type also used by computation. If left unspecified, the default floating type is used.

See also
  norm_fast()

## ◆ norm_fast()

template<typename T >
template<typename Tfloat = typename DefaultFPType<T>::fptype>

Tfloat tgx::Vec4< T >::norm_fast | ( |  | ) | const
| inline

Compute the euclidian norm of the vector.

Use the tgx::fast_sqrt() approximation to speedup computations.

Template Parameters

  Tfloat | Return type also used by computation. If left unspecified, the default floating type is used.

See also
  norm()

## ◆ invnorm()

template<typename T >
template<typename Tfloat = typename DefaultFPType<T>::fptype>

Tfloat tgx::Vec4< T >::invnorm | ( |  | ) | const
| inline

Compute the inverse of the euclidian norm of the vector.

Template Parameters

  Tfloat | Return type also used by computation. If left unspecified, the default floating type is used.

See also
  invnorm_fast()

## ◆ invnorm_fast()

template<typename T >
template<typename Tfloat = typename DefaultFPType<T>::fptype>

Tfloat tgx::Vec4< T >::invnorm_fast | ( |  | ) | const
| inline

Compute the inverse of the euclidian norm of the vector.

Use the tgx::fast_invsqrt() approximation to speedup computations.

Template Parameters

  Tfloat | Return type also used by computation. If left unspecified, the default floating type is used.

See also
  invnorm()

## ◆ normalize()

template<typename T >
template<typename Tfloat = typename DefaultFPType<T>::fptype>

void tgx::Vec4< T >::normalize | ( |  | ) |
| inline

Normalise the vector so that its norm is 1 (do nothing if the vector is 0).

Template Parameters

  Tfloat | Floating point type used for computation (use default floating point type if unspecified).

See also
  normalize_fast()

## ◆ normalize_fast()

template<typename T >
template<typename Tfloat = typename DefaultFPType<T>::fptype>

void tgx::Vec4< T >::normalize_fast | ( |  | ) |
| inline

Normalise the vector so that its norm is 1 (do nothing if the vector is 0).

Use fast_invsqrt() approxiamtion to speedup computations.

Template Parameters

  Tfloat | Floating point type used for computation (use default floating point type if unspecified).

See also
  normalize()

## ◆ getNormalize()

template<typename T >
template<typename Tfloat = typename DefaultFPType<T>::fptype>

Vec4< T > tgx::Vec4< T >::getNormalize | ( |  | ) | const
| inline

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

Template Parameters

  Tfloat | Floating point type used for computation (use default floating point type if unspecified).

See also
  getNormalize_fast()

## ◆ getNormalize_fast()

template<typename T >
template<typename Tfloat = typename DefaultFPType<T>::fptype>

Vec4< T > tgx::Vec4< T >::getNormalize_fast | ( |  | ) | const
| inline

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

Use fast_invsqrt() approxiamtion to speedup computations.

Template Parameters

  Tfloat | Floating point type used for computation (use default floating point type if unspecified).

See also
  getNormalize()

## ◆ zdivide()

template<typename T >
template<typename Tfloat = typename DefaultFPType<T>::fptype>

void tgx::Vec4< T >::zdivide | ( |  | ) |
| inline

Performs the 'z-divide' operation.

Perform the following operation on the components using tgx::fast_inv to speed-up computation:

- x = x/w
- y = y/w
- z = z/w
- w = 1/w

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

- src/Mat4.h
- src/Vec4.h