All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Nimble::Vector4T< T > Class Template Reference

A four-dimensional homogenic vector class for 3D graphics. More...

#include <Nimble/Vector4.hpp>

Public Types

enum  { ELEMENTS = 4 }
 
typedef T type
 Data type of the vector.
 

Public Member Functions

template<typename S >
Nimble::Vector4T< S > cast () const
 Cast the vector to another type.
 
Vector4Tclamp (T low, T high)
 Clamps both components to the range [low, high].
 
Vector4TclampUnit (void)
 Clamps both components to the range [0,1].
 
void clear (void)
 Fills the vector with zeroes.
 
T * data ()
 Returns a pointer to the first component.
 
const T * data () const
 Returns a pointer to the first component.
 
Vector4Tdescale (const Vector4T &v)
 Divides the vector component-wise.
 
T & get (size_t i)
 Returns the ith component.
 
const T & get (size_t i) const
 Returns the ith component.
 
bool isOne (void) const
 Checks if all components are one.
 
bool isZero (void) const
 Checks if all components are zero.
 
Decltype< T, float >::mul length () const
 Returns the length of the vector.
 
Decltype< T, float >::mul lengthSqr () const
 Returns the squared length of the vector.
 
Nimble::Vector4T< T > & make (const Vector2T< T > &v, T cz, T cw)
 Sets the vector to given values.
 
Nimble::Vector4T< T > & make (const Vector3T< T > &v, T cw)
 Sets the vector to given values.
 
Nimble::Vector4T< T > & make (T cx, T cy, T cz, T cw)
 Sets the vector to given values.
 
maximum () const
 Returns the largest component.
 
minimum () const
 Returns the smallest component.
 
Vector4Tnormalize (double len=1.0)
 Normalizes the vector to the given length. More...
 
Vector4T normalized (double len=1.0) const
 Get a vector normalized to given length. More...
 
bool operator!= (const Vector4T &src) const
 Compares if two vectors differ.
 
Vector4T operator* (T s) const
 Multiplies a vector with a scalar.
 
Vector4Toperator*= (T s)
 Multiplies a vector by scalar.
 
Vector4T operator+ (const Vector4T &v) const
 Adds two vectors.
 
Vector4Toperator+= (const Vector4T &v)
 Adds two vectors.
 
Vector4T operator- (const Vector4T &v) const
 Subtract two vectors.
 
Vector4T operator- () const
 Returns the negation of the vector.
 
Vector4Toperator-= (const Vector4T &v)
 Subtracts two vectors.
 
Vector4T operator/ (T s) const
 Divides a vector with a scalar.
 
Vector4Toperator/= (T s)
 Divides a vector by scalar.
 
bool operator== (const Vector4T &src) const
 Compares if two vectors are equal.
 
const T & operator[] (size_t i) const
 Returns the ith component.
 
T & operator[] (size_t i)
 Returns the ith component.
 
Vector4Tscale (const Vector4T &v)
 Multiplies the vector component-wise.
 
void set (size_t i, T v)
 Sets the ith component.
 
Vector4T shuffle (int i1, int i2, int i3, int i4) const
 Returns a vector with components reordered.
 
sum () const
 Sum of all components.
 
Vector2T< T > vector2 () const
 Returns a copy of the first two components as a Vector2. More...
 
Vector2T< T > vector2 (size_t i0, size_t i1) const
 Makes a new Nimble::Vector2f of two freely selected components of vector4. More...
 
Vector3T< T > vector3 () const
 Returns a copy of the first three components as a Vector3. More...
 
Vector3T< T > vector3 (size_t i0, size_t i1, size_t i2) const
 Makes a new vector3 of two freely selected components of vector4. More...
 
 Vector4T (const Vector2T< T > &v, T cz, T cw)
 Constructs a vector and initializes it with the given values.
 
 Vector4T (const Vector3T< T > &v, T cw)
 Constructs a vector and initializes it with the given values.
 
 Vector4T (T cx, T cy, T cz, T cw)
 Constructs a vector and initializes it with the given values.
 

Static Public Member Functions

static Vector4T< T > null ()
 Zero vector. More...
 

Public Attributes

w
 The w-component.
 
x
 The x-component.
 
y
 The y-component.
 
z
 The z-component.
 

Detailed Description

template<typename T>
class Nimble::Vector4T< T >

A four-dimensional homogenic vector class for 3D graphics.

This class is used to represent homogenic coordinates for 3D calculations.

Vector4T is also widely used to carry RGBA color values.

Member Function Documentation

template<typename T>
Vector4T& Nimble::Vector4T< T >::normalize ( double  len = 1.0)
inline

Normalizes the vector to the given length.

Parameters
lenlength to normalize to
Returns
reference to this
template<typename T>
Vector4T Nimble::Vector4T< T >::normalized ( double  len = 1.0) const
inline

Get a vector normalized to given length.

Parameters
lenlength to normalize to
Returns
normalized vector
template<typename T>
static Vector4T<T> Nimble::Vector4T< T >::null ( )
inlinestatic

Zero vector.

Returns
a zero vector
template<typename T>
Vector2T<T> Nimble::Vector4T< T >::vector2 ( ) const
inline

Returns a copy of the first two components as a Vector2.

Returns
New vector2
template<typename T>
Vector2T<T> Nimble::Vector4T< T >::vector2 ( size_t  i0,
size_t  i1 
) const
inline

Makes a new Nimble::Vector2f of two freely selected components of vector4.

Parameters
i0Index of the first component, vec2.x = vec4[i0], 0..3
i1Index of the second component, vec2.y = vec4[i1], 0..3
Returns
New vector2
template<typename T>
Vector3T<T> Nimble::Vector4T< T >::vector3 ( ) const
inline

Returns a copy of the first three components as a Vector3.

Returns
New vector3
template<typename T>
Vector3T<T> Nimble::Vector4T< T >::vector3 ( size_t  i0,
size_t  i1,
size_t  i2 
) const
inline

Makes a new vector3 of two freely selected components of vector4.

Parameters
i0Index of the first component, vec3.x = vec4[i0], 0..3
i1Index of the second component, vec3.y = vec4[i1], 0..3
i2Index of the third component, vec3.z = vec4[i2], 0..3
Returns
New vector2