Libprimis
Imprimis' 3D destroyable world engine
Loading...
Searching...
No Matches
vec4< T > Struct Template Reference

A four dimensional Cartesian-space vector template. More...

#include <geom.h>

Public Member Functions

 vec4 (const vec &p, T w=0)
 
 vec4 (const vec2 &p, T z=0, T w=0)
 
 vec4 (T x, T y=0, T z=0, T w=0)
 
 vec4 (bvec v, uchar c)
 
 vec4 (bvec v)
 
 vec4 (const T *v)
 
template<class U >
 vec4 (const vec4< U > &p)
 
template<class U >
 operator vec4< U > ()
 
T & operator[] (int i)
 
operator[] (int i) const
 
bool operator== (const vec4 &o) const
 
bool operator!= (const vec4 &o) const
 
dot3 (const vec4 &o) const
 Returns the 3 dimensional dot product between two 4-vecs.
 
dot3 (const vec &o) const
 Returns the 3 dimensional dot product between this and a 3D vec.
 
dot (const vec4 &o) const
 Returns the scalar product with another vec4.
 
dot (const vec &o) const
 Returns the dot product of this and a vec3, assuming o.w = 1.
 
squaredlen () const
 Returns the square of the magnitude of the vector.
 
magnitude () const
 Returns the magnitude of the vector.
 
magnitude3 () const
 Returns the magnitude of the vector, ignoring the w dimension.
 
vec4normalize ()
 Scales the vector to have a magnitude of 1.
 
vec4safenormalize ()
 Scales the vector to have a magnitude of 1.
 
void lerp (const vec4< uchar > &a, const vec4< uchar > &b, float t)
 
void lerp (const vec4< uchar > &a, const vec4< uchar > &b, int ka, int kb, int d)
 
void lerp (const vec4< uchar > &a, const vec4< uchar > &b, const vec4< uchar > &c, float ta, float tb, float tc)
 
void flip ()
 Flips a vec4<uchar> by using the mask type pun.
 
vec4lerp (const vec4 &b, T t)
 
vec4lerp (const vec4 &a, const vec4 &b, T t)
 
vec4avg (const vec4 &b)
 Calculates the elementwise arithmetic mean.
 
template<class B >
vec4madd (const vec4 &a, const B &b)
 
template<class B >
vec4msub (const vec4 &a, const B &b)
 
vec4mul3 (T f)
 Calculates the elementwise product.
 
vec4mul (T f)
 Calculates the elementwise product.
 
vec4mul (const vec4 &o)
 Calculates the elementwise product.
 
vec4mul (const vec &o)
 Calculates the elementwise product.
 
vec4square ()
 Calculates the elementwise square.
 
vec4div3 (T f)
 Calculates the elementwise quotient.
 
vec4div (T f)
 Calculates the elementwise quotient.
 
vec4div (const vec4 &o)
 Calculates the elementwise quotient.
 
vec4div (const vec &o)
 Calculates the elementwise quotient.
 
vec4recip ()
 Calculates the elementwise reciprocal.
 
vec4add (const vec4 &o)
 Calculates the elementwise sum.
 
vec4add (const vec &o)
 Calculates the elementwise sum.
 
vec4add3 (T f)
 Calculates the elementwise sum.
 
vec4add (T f)
 Calculates the elementwise sum.
 
vec4addw (T f)
 Adds to the fourth value of the vector (w/a).
 
vec4sub (const vec4 &o)
 Subtracts from this the vec4 passed.
 
vec4sub (const vec &o)
 Subtracts from this the vec passed.
 
vec4sub3 (T f)
 Subtracts from the first three entries this the svalue passed.
 
vec4sub (T f)
 
vec4subw (T f)
 
vec4neg3 ()
 
vec4neg ()
 
vec4clamp (T l, T h)
 
vec4 operator+ (const vec4 &v2) const
 
vec4 operator- (const vec4 &v2) const
 
vec4 operator- () const
 
template<typename U >
vec4 operator* (const U &n) const
 
vec4 operator* (const vec4 &v2) const
 
template<typename U >
vec4 operator/ (const U &n) const
 
vec4 operator/ (const vec4 &v2) const
 
template<class A , class B >
vec4cross (const A &a, const B &b)
 
vec4cross (const vec &o, const vec &a, const vec &b)
 
void setxyz (const vec &v)
 
vec4rotate_around_z (T c, T s)
 Rotates the given 3-vector around the z-axis.
 
vec4rotate_around_x (T c, T s)
 Rotates the given 3-vector around the x-axis.
 
vec4rotate_around_y (T c, T s)
 Rotates the given 3-vector around the y-axis.
 
vec4rotate_around_z (T angle)
 
vec4rotate_around_x (T angle)
 
vec4rotate_around_y (T angle)
 
vec4rotate_around_z (const vec2 &sc)
 
vec4rotate_around_x (const vec2 &sc)
 
vec4rotate_around_y (const vec2 &sc)
 
vec tonormal () const
 

Public Attributes

union { 
 
   struct { 
 
      T   x 
 
      T   y 
 
      T   z 
 
      T   w 
 
   }  
 
   struct { 
 
      T   r 
 
      T   g 
 
      T   b 
 
      T   a 
 
   }  
 
   T   v [4] 
 
   uint   mask 
 
};  
 

Detailed Description

template<typename T>
struct vec4< T >

A four dimensional Cartesian-space vector template.

This object defines a location in four dimensional Cartesian space, in whatever arithmetic type it is specialized to be. All four values are of the type T specialized, and all operators (unless explicitly specified, require types trivially convertable to T (or preferably of type T).

Member Function Documentation

◆ add() [1/3]

template<typename T >
vec4 & vec4< T >::add ( const vec & o)
inline

Calculates the elementwise sum.

Calculates the sum of the first three elements in this with the first three values in o, element-by-element. This means that the original vector is not preserved.

Parameters
othe vector to add with
Returns
a reference to this object following the operation

◆ add() [2/3]

template<typename T >
vec4 & vec4< T >::add ( const vec4< T > & o)
inline

Calculates the elementwise sum.

Calculates the sum of the four elements in this with the four values in o, element-by-element. This means that the original vector is not preserved.

Parameters
othe vector to add with
Returns
a reference to this object following the operation

◆ add() [3/3]

template<typename T >
vec4 & vec4< T >::add ( T f)
inline

Calculates the elementwise sum.

Calculates the sum of the four elements in this with the four elements comprising f. This means that the original vector is not preserved.

Parameters
fthe value to add with
Returns
a reference to this object following the operation

◆ add3()

template<typename T >
vec4 & vec4< T >::add3 ( T f)
inline

Calculates the elementwise sum.

Calculates the sum of the first three elements in this with the value passed to f. This means that the original vector is not preserved.

Parameters
fthe value to add with
Returns
a reference to this object following the operation

◆ addw()

template<typename T >
vec4 & vec4< T >::addw ( T f)
inline

Adds to the fourth value of the vector (w/a).

Calculates the sum of the passed value and the fourth element of the vec4, modifying the original vector to equal this sum.

Parameters
fthe value to add with
Returns
a reference to this object following the operation

◆ avg()

template<typename T >
vec4 & vec4< T >::avg ( const vec4< T > & b)
inline

Calculates the elementwise arithmetic mean.

Sets this to the elementwise arithmetic mean of this object and the passed object. The original vector is not preserved, but the passed one is.

Parameters
bthe vec4 to average with
Returns
a reference to this object following the operation

◆ div() [1/3]

template<typename T >
vec4 & vec4< T >::div ( const vec & o)
inline

Calculates the elementwise quotient.

Calculates the quotient of the three values in this with the four values in o, element-by-element. This means that the original vector is not preserved.

Parameters
othe vector to divide by
Returns
a reference to this object following the operation

◆ div() [2/3]

template<typename T >
vec4 & vec4< T >::div ( const vec4< T > & o)
inline

Calculates the elementwise quotient.

Calculates the quotient of the four values in this with the four values in o, element-by-element. This means that the original vector is not preserved.

Parameters
othe vector to divide by
Returns
a reference to this object following the operation

◆ div() [3/3]

template<typename T >
vec4 & vec4< T >::div ( T f)
inline

Calculates the elementwise quotient.

Calculates the quotient of the four values in this with the value passed to f. This means that the original vector is not preserved.

Parameters
fthe value to divide by
Returns
a reference to this object following the operation

◆ div3()

template<typename T >
vec4 & vec4< T >::div3 ( T f)
inline

Calculates the elementwise quotient.

Calculates the quotient of the first three values in this with the value passed to f. This means that the original vector is not preserved.

Parameters
fthe value to divide by
Returns
a reference to this object following the operation

◆ dot() [1/2]

template<typename T >
T vec4< T >::dot ( const vec & o) const
inline

Returns the dot product of this and a vec3, assuming o.w = 1.

Calculates the dot product with a vec3, with o.w implied to equal 1.

Parameters
othe vec3 to multiply by
Returns
the dot product of the two vectors

◆ dot() [2/2]

template<typename T >
T vec4< T >::dot ( const vec4< T > & o) const
inline

Returns the scalar product with another vec4.

Returns the scalar (dot) product of two 4D vecs, this and the passed vec4 o.

Parameters
othe vector to multiply with
Returns
the dot product of the two vectors

◆ dot3() [1/2]

template<typename T >
T vec4< T >::dot3 ( const vec & o) const
inline

Returns the 3 dimensional dot product between this and a 3D vec.

Returns the scalar (dot) product of a 3D and 4D vec, this and the passed 3D vec, by ignoring the fourth term in the 4D vec.

Parameters
othe vec3 to multiply by
Returns
the dot product of the first three elements of each vector

◆ dot3() [2/2]

template<typename T >
T vec4< T >::dot3 ( const vec4< T > & o) const
inline

Returns the 3 dimensional dot product between two 4-vecs.

Returns the scalar (dot) product of two 4D vecs, this and the passed one, as if they are 3D vecs, by ignoring the fourth term in each vector.

Parameters
othe vec4 to multiply by
Returns
the dot product of the first three elements of each vector

◆ flip()

template<typename T >
void vec4< T >::flip ( )
inline

Flips a vec4<uchar> by using the mask type pun.

Not for use with non-char vec4<> objects.

◆ magnitude()

template<typename T >
T vec4< T >::magnitude ( ) const
inline

Returns the magnitude of the vector.

Calculates the magnitude (length) of the vector, by taking the square root of the dot product of the vector with itself.

Returns
the maginitude of this

◆ magnitude3()

template<typename T >
T vec4< T >::magnitude3 ( ) const
inline

Returns the magnitude of the vector, ignoring the w dimension.

Calculates the D magnitude (length) of the vector, by taking the square root of the 3D dot product of the vector with itself.

Returns
the maginitude of this

◆ mul() [1/3]

template<typename T >
vec4 & vec4< T >::mul ( const vec & o)
inline

Calculates the elementwise product.

Calculates the elementwise product of the first three parameters in this with the three parameters in o. This means that the original vector is not preserved.

Parameters
othe vec3 to multiply by
Returns
a reference to this object following the operation

◆ mul() [2/3]

template<typename T >
vec4 & vec4< T >::mul ( const vec4< T > & o)
inline

Calculates the elementwise product.

Calculates the elementwise product of the four parameters in this with the four parameters in o. This measn that the original vector is not preserved.

Parameters
othe vec4 to multiply by
Returns
a reference to this object following the operation

◆ mul() [3/3]

template<typename T >
vec4 & vec4< T >::mul ( T f)
inline

Calculates the elementwise product.

Calculates the elementwise product of f with all four entries in this. This means that the original vector is not preserved.

Parameters
fthe value to multiply by
Returns
a reference to this object following the operation

◆ mul3()

template<typename T >
vec4 & vec4< T >::mul3 ( T f)
inline

Calculates the elementwise product.

Calculates the elementwise product of f with the first three entries in this. This means that the original vector is not preserved.

Parameters
fthe value to multiply by
Returns
a reference to this object following the operation

◆ normalize()

template<typename T >
vec4 & vec4< T >::normalize ( )
inline

Scales the vector to have a magnitude of 1.

Will cause a divide-by-zero if the vector is (0,0,0,0).

Returns
a reference to this vector

◆ recip()

template<typename T >
vec4 & vec4< T >::recip ( )
inline

Calculates the elementwise reciprocal.

Calculates the value 1/x for each of the four values in the vector, and assigns them to this. This means that the original vector is not preserved

Returns
a reference to this object following the operation

◆ rotate_around_x()

template<typename T >
vec4 & vec4< T >::rotate_around_x ( T c,
T s )
inline

Rotates the given 3-vector around the x-axis.

The w parameter is ignored. The positive direction of rotation is counterclockwise.

Parameters
cthe raw cosine value to rotate by
sthe raw sine value to rotate by

◆ rotate_around_y()

template<typename T >
vec4 & vec4< T >::rotate_around_y ( T c,
T s )
inline

Rotates the given 3-vector around the y-axis.

The w parameter is ignored. The positive direction of rotation is counterclockwise.

Parameters
cthe raw cosine value to rotate by
sthe raw sine value to rotate by

◆ rotate_around_z()

template<typename T >
vec4 & vec4< T >::rotate_around_z ( T c,
T s )
inline

Rotates the given 3-vector around the z-axis.

The w parameter is ignored. The positive direction of rotation is counterclockwise.

Parameters
cthe raw cosine value to rotate by
sthe raw sine value to rotate by

◆ safenormalize()

template<typename T >
vec4 & vec4< T >::safenormalize ( )
inline

Scales the vector to have a magnitude of 1.

Will return (0,0,0,0) if the vector passed (0,0,0,0).

Returns
a reference to this vector

◆ square()

template<typename T >
vec4 & vec4< T >::square ( )
inline

Calculates the elementwise square.

Calculates the elementwise product of this with itself. This means that the original vector is not preserved.

Returns
a reference to this object following the operation

◆ squaredlen()

template<typename T >
T vec4< T >::squaredlen ( ) const
inline

Returns the square of the magnitude of the vector.

Calculates the dot product of the vector with itself, yielding the square of the magnitude of the vec4.

Returns
the magnitude of this squared

◆ sub() [1/2]

template<typename T >
vec4 & vec4< T >::sub ( const vec & o)
inline

Subtracts from this the vec passed.

Calculates the difference between the four elements in this and the three elements of o, modifying the original vector to equal this difference.

Parameters
othe vec to subtract
Returns
a reference to this object following the operation

◆ sub() [2/2]

template<typename T >
vec4 & vec4< T >::sub ( const vec4< T > & o)
inline

Subtracts from this the vec4 passed.

Calculates the difference between the four elements in this and the four elements of o, modifying the original vector to equal this difference.

Parameters
othe vec4 to subtract
Returns
a reference to this object following the operation

◆ sub3()

template<typename T >
vec4 & vec4< T >::sub3 ( T f)
inline

Subtracts from the first three entries this the svalue passed.

Calculates the difference between the first three elements in this and the value passed, modifying the original vector to equal this difference.

Parameters
fthe value to subtract
Returns
a return to this object following the operation

Member Data Documentation

◆ mask

template<typename T >
uint vec4< T >::mask

four-entry array representation

◆ v

template<typename T >
T vec4< T >::v[4]

color space representation (red, green, blue, alpha)


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