Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::Vector4< T > Class Template Reference

Math class that represents an element of the three dimensional vector space with the notion of projectivity. When the fourth component is 1, it describes an 'usual' point and when it is 0, it represents the point at infinity. More...

Public Member Functions

 Vector4 (T X, T Y, T Z, T W=1.0)
 Constructs a Vector4 object from its coordinates. More...
 
 Vector4 (T X, T Y, const Vector2< T > &vec)
 Constructs a Vector4 object from two components and a Vector2<T> More...
 
 Vector4 (T X, const Vector2< T > &vec, T W)
 Constructs a Vector4 object from one component, a Vector2<T> and one component. More...
 
 Vector4 (T X, const Vector3< T > &vec)
 Constructs a Vector4 object from one component and a Vector3<T> More...
 
 Vector4 (T scale)
 Constructs explicitely a Vector4 object from its "scale". More...
 
 Vector4 (const T vec[4])
 Constructs a Vector4 object from an array of four elements. More...
 
 Vector4 (const Vector2< T > &vec, T Z=0.0, T W=1.0)
 Constructs a Vector4 object from a Vector2<T> and two components. More...
 
 Vector4 (const Vector3< T > &vec, T W=1.0)
 Constructs a Vector4 object from one component and a Vector3<T> More...
 
template<typename U >
 Vector4 (const Vector4< U > &vec)
 Constructs a Vector4 object from another type of Vector4. More...
 
 Vector4 (const Vector4 &vec)=default
 
AbsDotProduct (const Vector4 &vec) const
 Calculates the absolute dot (scalar) product with two vectors. More...
 
DotProduct (const Vector4 &vec) const
 Calculates the dot (scalar) product with two vectors. More...
 
Vector4 GetNormal (T *length=nullptr) const
 Gets a copy normalized of the vector. More...
 
Vector4MakeUnitX ()
 Makes the vector (1, 0, 0, 1) More...
 
Vector4MakeUnitY ()
 Makes the vector (0, 1, 0, 1) More...
 
Vector4MakeUnitZ ()
 Makes the vector (0, 0, 1, 1) More...
 
Vector4MakeZero ()
 Makes the vector (0, 0, 0, 1) More...
 
Vector4Maximize (const Vector4 &vec)
 Sets this vector's components to the maximum of its own and other components. More...
 
Vector4Minimize (const Vector4 &vec)
 Sets this vector's components to the minimum of its own and other components. More...
 
Vector4Normalize (T *length=nullptr)
 Gives the normalized vector. More...
 
Vector4Set (T X, T Y, T Z, T W=1.0)
 Sets the components of the vector. More...
 
Vector4Set (T X, T Y, const Vector2< T > &vec)
 Sets the components of the vector from two components and a Vector2. More...
 
Vector4Set (T X, const Vector2< T > &vec, T W)
 Sets the components of the vector from one component, a Vector2 and one component. More...
 
Vector4Set (T X, const Vector3< T > &vec)
 Sets the components of the vector from one component and a Vector3. More...
 
Vector4Set (T scale)
 Sets the components of the vector from a "scale". More...
 
Vector4Set (const T vec[4])
 Sets the components of the vector from an array of four elements. More...
 
Vector4Set (const Vector2< T > &vec, T Z=0.0, T W=1.0)
 Sets the components of the vector from a Vector2 and two components. More...
 
Vector4Set (const Vector3< T > &vec, T W=1.0)
 Sets the components of the vector from a Vector3 and one components. More...
 
Vector4Set (const Vector4< T > &vec)
 Sets the components of the vector from another vector. More...
 
template<typename U >
Vector4Set (const Vector4< U > &vec)
 
String ToString () const
 Gives a string representation. More...
 
 operator T* ()
 Converts vector to pointer to its own data. More...
 
 operator const T * () const
 Converts vector to const pointer to its own data. More...
 
const Vector4operator+ () const
 Helps to represent the sign of the vector. More...
 
Vector4 operator- () const
 Negates the components of the vector. More...
 
Vector4 operator+ (const Vector4 &vec) const
 Adds the components of the vector with other vector. More...
 
Vector4 operator- (const Vector4 &vec) const
 Substracts the components of the vector with other vector. More...
 
Vector4 operator* (const Vector4 &vec) const
 Multiplies the components of the vector with other vector. More...
 
Vector4 operator* (T scale) const
 Multiplies the components of the vector with a scalar. More...
 
Vector4 operator/ (const Vector4 &vec) const
 Divides the components of the vector with other vector. More...
 
Vector4 operator/ (T scale) const
 Divides the components of the vector with a scalar. More...
 
Vector4operator= (const Vector4 &other)=default
 
Vector4operator+= (const Vector4 &vec)
 Adds the components of other vector to this vector. More...
 
Vector4operator-= (const Vector4 &vec)
 Substracts the components of other vector to this vector. More...
 
Vector4operator*= (const Vector4 &vec)
 Multiplies the components of other vector to this vector. More...
 
Vector4operator*= (T scale)
 Multiplies the components of other vector with a scalar. More...
 
Vector4operator/= (const Vector4 &vec)
 Multiplies the components of other vector to this vector. More...
 
Vector4operator/= (T scale)
 Divides the components of other vector with a scalar. More...
 
bool operator== (const Vector4 &vec) const
 Compares the vector to other one. More...
 
bool operator!= (const Vector4 &vec) const
 Compares the vector to other one. More...
 
bool operator< (const Vector4 &vec) const
 Compares the vector to other one. More...
 
bool operator<= (const Vector4 &vec) const
 Compares the vector to other one. More...
 
bool operator> (const Vector4 &vec) const
 Compares the vector to other one. More...
 
bool operator>= (const Vector4 &vec) const
 Compares the vector to other one. More...
 
template<typename U >
Vector4< T > & Set (const Vector4< U > &vec)
 Sets the components of the vector from another type of Vector4. More...
 

Static Public Member Functions

static T DotProduct (const Vector4 &vec1, const Vector4 &vec2)
 
static Vector4 Lerp (const Vector4 &from, const Vector4 &to, T interpolation)
 Interpolates the vector to other one with a factor of interpolation. More...
 
static Vector4 Normalize (const Vector4 &vec)
 Gives the normalized vector. More...
 
static Vector4 UnitX ()
 Shorthand for the vector (1, 0, 0, 1) More...
 
static Vector4 UnitY ()
 Shorthand for the vector (0, 1, 0, 1) More...
 
static Vector4 UnitZ ()
 Shorthand for the vector (0, 0, 1, 1) More...
 
static Vector4 Zero ()
 Shorthand for the vector (0, 0, 0, 1) More...
 

Public Attributes

x
 
y
 
z
 
w
 

Detailed Description

template<typename T>
class Nz::Vector4< T >

Math class that represents an element of the three dimensional vector space with the notion of projectivity. When the fourth component is 1, it describes an 'usual' point and when it is 0, it represents the point at infinity.

Constructor & Destructor Documentation

◆ Vector4() [1/9]

template<typename T>
Nz::Vector4< T >::Vector4 ( X,
Y,
Z,
W = 1.0 
)

Constructs a Vector4 object from its coordinates.

Parameters
XX component
YY component
ZZ component
WW component

◆ Vector4() [2/9]

template<typename T>
Nz::Vector4< T >::Vector4 ( X,
Y,
const Vector2< T > &  vec 
)

Constructs a Vector4 object from two components and a Vector2<T>

Parameters
XX component
YY component
vecvec.X = Z component and vec.y = W component

◆ Vector4() [3/9]

template<typename T>
Nz::Vector4< T >::Vector4 ( X,
const Vector2< T > &  vec,
W 
)

Constructs a Vector4 object from one component, a Vector2<T> and one component.

Parameters
XX component
vecvec.X = Y component and vec.y = Z component
WW component

◆ Vector4() [4/9]

template<typename T>
Nz::Vector4< T >::Vector4 ( X,
const Vector3< T > &  vec 
)

Constructs a Vector4 object from one component and a Vector3<T>

Parameters
XX component
vecvec.X = Y component, vec.y = Z component and vec.z = W component

◆ Vector4() [5/9]

template<typename T>
Nz::Vector4< T >::Vector4 ( scale)
explicit

Constructs explicitely a Vector4 object from its "scale".

Parameters
scaleX component = Y component = Z component = W component

◆ Vector4() [6/9]

template<typename T>
Nz::Vector4< T >::Vector4 ( const T  vec[4])

Constructs a Vector4 object from an array of four elements.

Parameters
vec[4]vec[0] is X component, vec[1] is Y component, vec[2] is Z component and vec[3] is W component

◆ Vector4() [7/9]

template<typename T>
Nz::Vector4< T >::Vector4 ( const Vector2< T > &  vec,
Z = 0.0,
W = 1.0 
)

Constructs a Vector4 object from a Vector2<T> and two components.

Parameters
vecvec.X = X component and vec.y = Y component
ZZ component
WW component

◆ Vector4() [8/9]

template<typename T>
Nz::Vector4< T >::Vector4 ( const Vector3< T > &  vec,
W = 1.0 
)

Constructs a Vector4 object from one component and a Vector3<T>

Parameters
vecvec.X = X component, vec.y = Y component and vec.z = Z component
WW component

◆ Vector4() [9/9]

template<typename T >
template<typename U >
Nz::Vector4< T >::Vector4 ( const Vector4< U > &  vec)
explicit

Constructs a Vector4 object from another type of Vector4.

Parameters
vecVector of type U to convert to type T

Member Function Documentation

◆ AbsDotProduct()

template<typename T >
T Nz::Vector4< T >::AbsDotProduct ( const Vector4< T > &  vec) const

Calculates the absolute dot (scalar) product with two vectors.

Returns
The dot product with absolutes values on each component
Parameters
vecThe other vector to calculate the absolute dot product with
See also
DotProduct

◆ DotProduct()

template<typename T >
T Nz::Vector4< T >::DotProduct ( const Vector4< T > &  vec) const

Calculates the dot (scalar) product with two vectors.

Returns
The value of the dot product
Parameters
vecThe other vector to calculate the dot product with
See also
AbsDotProduct, DotProduct

◆ GetNormal()

template<typename T>
Vector4< T > Nz::Vector4< T >::GetNormal ( T *  length = nullptr) const

Gets a copy normalized of the vector.

Returns
A new vector which is the vector normalized
Parameters
lengthOptional argument to obtain the length's ratio of the vector and the unit-length in this case w
See also
Normalize

◆ Lerp()

template<typename T>
Vector4< T > Nz::Vector4< T >::Lerp ( const Vector4< T > &  from,
const Vector4< T > &  to,
interpolation 
)
static

Interpolates the vector to other one with a factor of interpolation.

Returns
A new vector which is the interpolation of two vectors
Parameters
fromInitial vector
toTarget vector
interpolationFactor of interpolation
Remarks
interpolation is meant to be between 0 and 1, other values are potentially undefined behavior
See also
Lerp

◆ MakeUnitX()

template<typename T >
Vector4< T > & Nz::Vector4< T >::MakeUnitX ( )

Makes the vector (1, 0, 0, 1)

Returns
A reference to this vector with components (1, 0, 0, 1)
See also
UnitX

◆ MakeUnitY()

template<typename T >
Vector4< T > & Nz::Vector4< T >::MakeUnitY ( )

Makes the vector (0, 1, 0, 1)

Returns
A reference to this vector with components (0, 1, 0, 1)
See also
UnitY

◆ MakeUnitZ()

template<typename T >
Vector4< T > & Nz::Vector4< T >::MakeUnitZ ( )

Makes the vector (0, 0, 1, 1)

Returns
A reference to this vector with components (0, 0, 1, 1)
See also
UnitZ

◆ MakeZero()

template<typename T >
Vector4< T > & Nz::Vector4< T >::MakeZero ( )

Makes the vector (0, 0, 0, 1)

Returns
A reference to this vector with components (0, 0, 0, 1)
See also
Zero

◆ Maximize()

template<typename T >
Vector4< T > & Nz::Vector4< T >::Maximize ( const Vector4< T > &  vec)

Sets this vector's components to the maximum of its own and other components.

Returns
A reference to this vector with replaced values with the corresponding max value
Parameters
vecOther vector to compare the components with
See also
Minimize

◆ Minimize()

template<typename T >
Vector4< T > & Nz::Vector4< T >::Minimize ( const Vector4< T > &  vec)

Sets this vector's components to the minimum of its own and other components.

Returns
A reference to this vector with replaced values with the corresponding min value
Parameters
vecOther vector to compare the components with
See also
Maximize

◆ Normalize() [1/2]

template<typename T>
Vector4< T > & Nz::Vector4< T >::Normalize ( T *  length = nullptr)

Gives the normalized vector.

Returns
A normalized vector from the vec with w = 1
Parameters
lengthOptional argument to obtain the length's ratio of the vector in this case w
See also
GetNormal

◆ Normalize() [2/2]

template<typename T>
Vector4< T > Nz::Vector4< T >::Normalize ( const Vector4< T > &  vec)
static

Gives the normalized vector.

Returns
A normalized vector from the vec with w = 1
Parameters
vecVector to normalize
See also
GetNormal

◆ operator const T *()

template<typename T >
Nz::Vector4< T >::operator const T * ( ) const

Converts vector to const pointer to its own data.

Returns
A constant pointer to the own data
Remarks
Access to index greather than 3 is undefined behavior

◆ operator T*()

template<typename T >
Nz::Vector4< T >::operator T* ( )

Converts vector to pointer to its own data.

Returns
A pointer to the own data
Remarks
Access to index greather than 3 is undefined behavior

◆ operator!=()

template<typename T >
bool Nz::Vector4< T >::operator!= ( const Vector4< T > &  vec) const

Compares the vector to other one.

Returns
false if the vectors are the same
Parameters
vecOther vector to compare with

◆ operator*() [1/2]

template<typename T >
Vector4< T > Nz::Vector4< T >::operator* ( const Vector4< T > &  vec) const

Multiplies the components of the vector with other vector.

Returns
A vector where components are the product of this vector and the other one
Parameters
vecThe other vector to multiply components with

◆ operator*() [2/2]

template<typename T>
Vector4< T > Nz::Vector4< T >::operator* ( scale) const

Multiplies the components of the vector with a scalar.

Returns
A vector where components are the product of this vector and the scalar
Parameters
scaleThe scalar to multiply components with

◆ operator*=() [1/2]

template<typename T >
Vector4< T > & Nz::Vector4< T >::operator*= ( const Vector4< T > &  vec)

Multiplies the components of other vector to this vector.

Returns
A reference to this vector where components are the product of this vector and the other one
Parameters
vecThe other vector to multiply components with

◆ operator*=() [2/2]

template<typename T>
Vector4< T > & Nz::Vector4< T >::operator*= ( scale)

Multiplies the components of other vector with a scalar.

Returns
A reference to this vector where components are the product of this vector and the scalar
Parameters
vecThe other vector to multiply components with

◆ operator+() [1/2]

template<typename T >
const Vector4< T > & Nz::Vector4< T >::operator+ ( ) const

Helps to represent the sign of the vector.

Returns
A constant reference to this vector

◆ operator+() [2/2]

template<typename T >
Vector4< T > Nz::Vector4< T >::operator+ ( const Vector4< T > &  vec) const

Adds the components of the vector with other vector.

Returns
A vector where components are the sum of this vector and the other one
Parameters
vecThe other vector to add components with

◆ operator+=()

template<typename T >
Vector4< T > & Nz::Vector4< T >::operator+= ( const Vector4< T > &  vec)

Adds the components of other vector to this vector.

Returns
A reference to this vector where components are the sum of this vector and the other one
Parameters
vecThe other vector to add components with

◆ operator-() [1/2]

template<typename T >
Vector4< T > Nz::Vector4< T >::operator- ( ) const

Negates the components of the vector.

Returns
A constant reference to this vector with negate components

◆ operator-() [2/2]

template<typename T >
Vector4< T > Nz::Vector4< T >::operator- ( const Vector4< T > &  vec) const

Substracts the components of the vector with other vector.

Returns
A vector where components are the difference of this vector and the other one
Parameters
vecThe other vector to substract components with

◆ operator-=()

template<typename T >
Vector4< T > & Nz::Vector4< T >::operator-= ( const Vector4< T > &  vec)

Substracts the components of other vector to this vector.

Returns
A reference to this vector where components are the difference of this vector and the other one
Parameters
vecThe other vector to substract components with

◆ operator/() [1/2]

template<typename T >
Vector4< T > Nz::Vector4< T >::operator/ ( const Vector4< T > &  vec) const

Divides the components of the vector with other vector.

Returns
A vector where components are the quotient of this vector and the other one
Parameters
vecThe other vector to divide components with
Remarks
Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined
Exceptions
std::domain_errorif NAZARA_MATH_SAFE is defined and one of the vec components is null

◆ operator/() [2/2]

template<typename T>
Vector4< T > Nz::Vector4< T >::operator/ ( scale) const

Divides the components of the vector with a scalar.

Returns
A vector where components are the quotient of this vector and the scalar
Parameters
scaleThe scalar to divide components with
Remarks
Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
Exceptions
std::domain_errorif NAZARA_MATH_SAFE is defined and scale is null

◆ operator/=() [1/2]

template<typename T >
Vector4< T > & Nz::Vector4< T >::operator/= ( const Vector4< T > &  vec)

Multiplies the components of other vector to this vector.

Returns
A reference to this vector where components are the quotient of this vector and the other one
Parameters
vecThe other vector to multiply components with
Remarks
Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined
Exceptions
std::domain_errorif NAZARA_MATH_SAFE is defined and one of the vec components is null

◆ operator/=() [2/2]

template<typename T>
Vector4< T > & Nz::Vector4< T >::operator/= ( scale)

Divides the components of other vector with a scalar.

Returns
A reference to this vector where components are the quotient of this vector and the scalar
Parameters
vecThe other vector to divide components with
Remarks
Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
Exceptions
std::domain_errorif NAZARA_MATH_SAFE is defined and scale is null

◆ operator<()

template<typename T >
bool Nz::Vector4< T >::operator< ( const Vector4< T > &  vec) const

Compares the vector to other one.

Returns
true if this vector has its first components inferior to the other ones
Parameters
vecOther vector to compare with

◆ operator<=()

template<typename T >
bool Nz::Vector4< T >::operator<= ( const Vector4< T > &  vec) const

Compares the vector to other one.

Returns
true if this vector has its first components inferior or equal to the other ones
Parameters
vecOther vector to compare with

◆ operator==()

template<typename T >
bool Nz::Vector4< T >::operator== ( const Vector4< T > &  vec) const

Compares the vector to other one.

Returns
true if the vectors are the same
Parameters
vecOther vector to compare with

◆ operator>()

template<typename T >
bool Nz::Vector4< T >::operator> ( const Vector4< T > &  vec) const

Compares the vector to other one.

Returns
true if this vector has its first components superior to the other ones
Parameters
vecOther vector to compare with

◆ operator>=()

template<typename T >
bool Nz::Vector4< T >::operator>= ( const Vector4< T > &  vec) const

Compares the vector to other one.

Returns
true if this vector has its first components superior or equal to the other ones
Parameters
vecOther vector to compare with

◆ Set() [1/10]

template<typename T>
Vector4< T > & Nz::Vector4< T >::Set ( X,
Y,
Z,
W = 1.0 
)

Sets the components of the vector.

Returns
A reference to this vector
Parameters
XX component
YY component
ZZ component
WW component

◆ Set() [2/10]

template<typename T>
Vector4< T > & Nz::Vector4< T >::Set ( X,
Y,
const Vector2< T > &  vec 
)

Sets the components of the vector from two components and a Vector2.

Returns
A reference to this vector
Parameters
XX component
YY component
vecvec.X = Z component and vec.y = W component

◆ Set() [3/10]

template<typename T>
Vector4< T > & Nz::Vector4< T >::Set ( X,
const Vector2< T > &  vec,
W 
)

Sets the components of the vector from one component, a Vector2 and one component.

Returns
A reference to this vector
Parameters
XX component
vecvec.X = Y component and vec.y = Z component
WW component

◆ Set() [4/10]

template<typename T>
Vector4< T > & Nz::Vector4< T >::Set ( X,
const Vector3< T > &  vec 
)

Sets the components of the vector from one component and a Vector3.

Returns
A reference to this vector
Parameters
XX component
vecvec.X = Y component, vec.y = Z component and vec.z = W component

◆ Set() [5/10]

template<typename T>
Vector4< T > & Nz::Vector4< T >::Set ( scale)

Sets the components of the vector from a "scale".

Returns
A reference to this vector
Parameters
scaleX component = Y component = Z component = W component

◆ Set() [6/10]

template<typename T>
Vector4< T > & Nz::Vector4< T >::Set ( const T  vec[4])

Sets the components of the vector from an array of four elements.

Returns
A reference to this vector
Parameters
vec[4]vec[0] is X component, vec[1] is Y component, vec[2] is Z component and vec[3] is W component

◆ Set() [7/10]

template<typename T>
Vector4< T > & Nz::Vector4< T >::Set ( const Vector2< T > &  vec,
Z = 0.0,
W = 1.0 
)

Sets the components of the vector from a Vector2 and two components.

Parameters
vecvec.X = X component and vec.y = Y component
ZZ component
WW component

◆ Set() [8/10]

template<typename T>
Vector4< T > & Nz::Vector4< T >::Set ( const Vector3< T > &  vec,
W = 1.0 
)

Sets the components of the vector from a Vector3 and one components.

Parameters
vecvec.X = X component, vec.y = Y component and vec.z = Z component
WW component

◆ Set() [9/10]

template<typename T>
Vector4< T > & Nz::Vector4< T >::Set ( const Vector4< T > &  vec)

Sets the components of the vector from another vector.

Returns
A reference to this vector
Parameters
vecThe other vector

◆ Set() [10/10]

template<typename T>
template<typename U >
Vector4<T>& Nz::Vector4< T >::Set ( const Vector4< U > &  vec)

Sets the components of the vector from another type of Vector4.

Returns
A reference to this vector
Parameters
vecVector of type U to convert its components

◆ ToString()

template<typename T >
String Nz::Vector4< T >::ToString ( ) const

Gives a string representation.

Returns
A string representation of the object: "Vector4(x, y, z, w)"

◆ UnitX()

template<typename T >
Vector4< T > Nz::Vector4< T >::UnitX ( )
static

Shorthand for the vector (1, 0, 0, 1)

Returns
A vector with components (1, 0, 0, 1)
See also
MakeUnitX

◆ UnitY()

template<typename T >
Vector4< T > Nz::Vector4< T >::UnitY ( )
static

Shorthand for the vector (0, 1, 0, 1)

Returns
A vector with components (0, 1, 0, 1)
See also
MakeUnitY

◆ UnitZ()

template<typename T >
Vector4< T > Nz::Vector4< T >::UnitZ ( )
static

Shorthand for the vector (0, 0, 1, 1)

Returns
A vector with components (0, 0, 1, 1)
See also
MakeUnitZ

◆ Zero()

template<typename T >
Vector4< T > Nz::Vector4< T >::Zero ( )
static

Shorthand for the vector (0, 0, 0, 1)

Returns
A vector with components (0, 0, 0, 1)
See also
MakeZero

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