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

Math class that represents an element of the two dimensional vector space. More...

Public Member Functions

 Vector2 (T X, T Y)
 Constructs a Vector2 object from its coordinates. More...
 
 Vector2 (T scale)
 Constructs explicitely a Vector2 object from its "scale". More...
 
 Vector2 (const T vec[2])
 Constructs a Vector2 object from an array of two elements. More...
 
template<typename U >
 Vector2 (const Vector2< U > &vec)
 Constructs a Vector2 object from another type of Vector2. More...
 
 Vector2 (const Vector2 &vec)=default
 
 Vector2 (const Vector3< T > &vec)
 Constructs a Vector2 object from a Vector3. More...
 
 Vector2 (const Vector4< T > &vec)
 Constructs a Vector2 object from a Vector4. More...
 
AbsDotProduct (const Vector2 &vec) const
 Calculates the absolute dot (scalar) product with two vectors. More...
 
AngleBetween (const Vector2 &vec) const
 Calculates the angle between two vectors in orthonormal basis. More...
 
Distance (const Vector2 &vec) const
 Calculates the distance between two vectors. More...
 
float Distancef (const Vector2 &vec) const
 Calculates the distance between two vectors. More...
 
DotProduct (const Vector2 &vec) const
 Calculates the dot (scalar) product with two vectors. More...
 
GetLength () const
 Calculates the length (magnitude) of the vector. More...
 
float GetLengthf () const
 Calculates the length (magnitude) of the vector. More...
 
Vector2 GetNormal (T *length=nullptr) const
 Gets a copy normalized of the vector. More...
 
GetSquaredLength () const
 Calculates the squared length (magnitude) of the vector. More...
 
Vector2MakeUnit ()
 Makes the vector (1, 1) More...
 
Vector2MakeUnitX ()
 Makes the vector (1, 0) More...
 
Vector2MakeUnitY ()
 Makes the vector (0, 1) More...
 
Vector2MakeZero ()
 Makes the vector (0, 0) More...
 
Vector2Maximize (const Vector2 &vec)
 Sets this vector's components to the maximum of its own and other components. More...
 
Vector2Minimize (const Vector2 &vec)
 Sets this vector's components to the minimum of its own and other components. More...
 
Vector2Normalize (T *length=nullptr)
 Normalizes the current vector. More...
 
Vector2Set (T X, T Y)
 Sets the components of the vector. More...
 
Vector2Set (T scale)
 Sets the components of the vector from a "scale". More...
 
Vector2Set (const T vec[2])
 Sets the components of the vector from an array of two elements. More...
 
Vector2Set (const Vector2 &vec)
 Sets the components of the vector from another vector. More...
 
Vector2Set (const Vector3< T > &vec)
 Sets the components of the vector from a Vector3. More...
 
Vector2Set (const Vector4< T > &vec)
 Sets the components of the vector from a Vector4. More...
 
template<typename U >
Vector2Set (const Vector2< U > &vec)
 
SquaredDistance (const Vector2 &vec) const
 Calculates the squared distance between two vectors. More...
 
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 Vector2operator+ () const
 Helps to represent the sign of the vector. More...
 
Vector2 operator- () const
 Negates the components of the vector. More...
 
Vector2 operator+ (const Vector2 &vec) const
 Adds the components of the vector with other vector. More...
 
Vector2 operator- (const Vector2 &vec) const
 Substracts the components of the vector with other vector. More...
 
Vector2 operator* (const Vector2 &vec) const
 Multiplies the components of the vector with other vector. More...
 
Vector2 operator* (T scale) const
 Multiplies the components of the vector with a scalar. More...
 
Vector2 operator/ (const Vector2 &vec) const
 Divides the components of the vector with other vector. More...
 
Vector2 operator/ (T scale) const
 Divides the components of the vector with a scalar. More...
 
Vector2operator= (const Vector2 &other)=default
 
Vector2operator+= (const Vector2 &vec)
 Adds the components of other vector to this vector. More...
 
Vector2operator-= (const Vector2 &vec)
 Substracts the components of other vector to this vector. More...
 
Vector2operator*= (const Vector2 &vec)
 Multiplies the components of other vector to this vector. More...
 
Vector2operator*= (T scale)
 Multiplies the components of other vector with a scalar. More...
 
Vector2operator/= (const Vector2 &vec)
 Multiplies the components of other vector to this vector. More...
 
Vector2operator/= (T scale)
 Divides the components of other vector with a scalar. More...
 
bool operator== (const Vector2 &vec) const
 Compares the vector to other one. More...
 
bool operator!= (const Vector2 &vec) const
 Compares the vector to other one. More...
 
bool operator< (const Vector2 &vec) const
 Compares the vector to other one. More...
 
bool operator<= (const Vector2 &vec) const
 Compares the vector to other one. More...
 
bool operator> (const Vector2 &vec) const
 Compares the vector to other one. More...
 
bool operator>= (const Vector2 &vec) const
 Compares the vector to other one. More...
 
template<typename U >
Vector2< T > & Set (const Vector2< U > &vec)
 Sets the components of the vector from another type of Vector2. More...
 

Static Public Member Functions

static T DotProduct (const Vector2 &vec1, const Vector2 &vec2)
 Calculates the dot (scalar) product with two vectors. More...
 
static Vector2 Lerp (const Vector2 &from, const Vector2 &to, T interpolation)
 Interpolates the vector to other one with a factor of interpolation. More...
 
static Vector2 Normalize (const Vector2 &vec)
 Gives the normalized vector. More...
 
static Vector2 Unit ()
 Shorthand for the vector (1, 1) More...
 
static Vector2 UnitX ()
 Shorthand for the vector (1, 0) More...
 
static Vector2 UnitY ()
 Shorthand for the vector (0, 1) More...
 
static Vector2 Zero ()
 Shorthand for the vector (0, 0) More...
 

Public Attributes

x
 
y
 

Detailed Description

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

Math class that represents an element of the two dimensional vector space.

Constructor & Destructor Documentation

◆ Vector2() [1/6]

template<typename T>
Nz::Vector2< T >::Vector2 ( X,
Y 
)

Constructs a Vector2 object from its coordinates.

Parameters
XX component
YY component

◆ Vector2() [2/6]

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

Constructs explicitely a Vector2 object from its "scale".

Parameters
scaleX component = Y component

◆ Vector2() [3/6]

template<typename T>
Nz::Vector2< T >::Vector2 ( const T  vec[2])

Constructs a Vector2 object from an array of two elements.

Parameters
vec[2]vec[0] is X component and vec[1] is Y component

◆ Vector2() [4/6]

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

Constructs a Vector2 object from another type of Vector2.

Parameters
vecVector of type U to convert to type T

◆ Vector2() [5/6]

template<typename T>
Nz::Vector2< T >::Vector2 ( const Vector3< T > &  vec)
explicit

Constructs a Vector2 object from a Vector3.

Parameters
vecVector3 where only the first two components are taken

◆ Vector2() [6/6]

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

Constructs a Vector2 object from a Vector4.

Parameters
vecVector4 where only the first two components are taken

Member Function Documentation

◆ AbsDotProduct()

template<typename T >
T Nz::Vector2< T >::AbsDotProduct ( const Vector2< 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

◆ AngleBetween()

template<typename T >
T Nz::Vector2< T >::AngleBetween ( const Vector2< T > &  vec) const

Calculates the angle between two vectors in orthonormal basis.

Returns
The angle unit depends of NAZARA_MATH_ANGLE_RADIAN, you may want to normalize it to the range 0..2*pi with NormalizeAngle
Parameters
vecThe other vector to measure the angle with
Remarks
The vectors do not need to be normalised and if the angle is normalised, it represents the rotation from *this to vec in anti-clockwise direction
See also
NormalizeAngle

◆ Distance()

template<typename T >
T Nz::Vector2< T >::Distance ( const Vector2< T > &  vec) const

Calculates the distance between two vectors.

Returns
The metric distance between two vectors with euclidean norm
Parameters
vecThe other vector to measure the distance with
See also
SquaredDistance

◆ Distancef()

template<typename T >
float Nz::Vector2< T >::Distancef ( const Vector2< T > &  vec) const

Calculates the distance between two vectors.

Returns
The metric distance in float between two vectors with euclidean norm
Parameters
vecThe other vector to measure the distance with

◆ DotProduct() [1/2]

template<typename T >
T Nz::Vector2< T >::DotProduct ( const Vector2< 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

◆ DotProduct() [2/2]

template<typename T >
T Nz::Vector2< T >::DotProduct ( const Vector2< T > &  vec1,
const Vector2< T > &  vec2 
)
static

Calculates the dot (scalar) product with two vectors.

Returns
The value of the dot product
Parameters
vec1The first vector to calculate the dot product with
vec2The second vector to calculate the dot product with
See also
AbsDotProduct, DotProduct

◆ GetLength()

template<typename T >
T Nz::Vector2< T >::GetLength ( ) const

Calculates the length (magnitude) of the vector.

Returns
The length of the vector
See also
GetSquaredLength

◆ GetLengthf()

template<typename T >
float Nz::Vector2< T >::GetLengthf ( ) const

Calculates the length (magnitude) of the vector.

Returns
The length in float of the vector

◆ GetNormal()

template<typename T>
Vector2< T > Nz::Vector2< 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
Remarks
If this vector is (0, 0), then it returns (0, 0) and length is 0
See also
Normalize

◆ GetSquaredLength()

template<typename T >
T Nz::Vector2< T >::GetSquaredLength ( ) const

Calculates the squared length (magnitude) of the vector.

Returns
The squared length of the vector
See also
GetLength

◆ Lerp()

template<typename T>
Vector2< T > Nz::Vector2< T >::Lerp ( const Vector2< T > &  from,
const Vector2< 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

◆ MakeUnit()

template<typename T >
Vector2< T > & Nz::Vector2< T >::MakeUnit ( )

Makes the vector (1, 1)

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

◆ MakeUnitX()

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

Makes the vector (1, 0)

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

◆ MakeUnitY()

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

Makes the vector (0, 1)

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

◆ MakeZero()

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

Makes the vector (0, 0)

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

◆ Maximize()

template<typename T >
Vector2< T > & Nz::Vector2< T >::Maximize ( const Vector2< 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 >
Vector2< T > & Nz::Vector2< T >::Minimize ( const Vector2< 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>
Vector2< T > & Nz::Vector2< T >::Normalize ( T *  length = nullptr)

Normalizes the current vector.

Returns
A reference to this vector
Parameters
lengthOptional argument to obtain the length's ratio of the vector and the unit-length
Remarks
If the vector is (0, 0), then it returns (0, 0) and length is 0
See also
GetNormal

◆ Normalize() [2/2]

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

Gives the normalized vector.

Returns
A normalized vector from the vec
Parameters
vecVector to normalize
Remarks
If the vector is (0, 0), then it returns (0, 0)
See also
GetNormal

◆ operator const T *()

template<typename T >
Nz::Vector2< 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 1 is undefined behavior

◆ operator T*()

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

Converts vector to pointer to its own data.

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

◆ operator!=()

template<typename T >
bool Nz::Vector2< T >::operator!= ( const Vector2< 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 >
Vector2< T > Nz::Vector2< T >::operator* ( const Vector2< 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>
Vector2< T > Nz::Vector2< 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 >
Vector2< T > & Nz::Vector2< T >::operator*= ( const Vector2< 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>
Vector2< T > & Nz::Vector2< 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 Vector2< T > & Nz::Vector2< T >::operator+ ( ) const

Helps to represent the sign of the vector.

Returns
A constant reference to this vector

◆ operator+() [2/2]

template<typename T >
Vector2< T > Nz::Vector2< T >::operator+ ( const Vector2< 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 >
Vector2< T > & Nz::Vector2< T >::operator+= ( const Vector2< 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 >
Vector2< T > Nz::Vector2< 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 >
Vector2< T > Nz::Vector2< T >::operator- ( const Vector2< 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 >
Vector2< T > & Nz::Vector2< T >::operator-= ( const Vector2< 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 >
Vector2< T > Nz::Vector2< T >::operator/ ( const Vector2< 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>
Vector2< T > Nz::Vector2< 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 >
Vector2< T > & Nz::Vector2< T >::operator/= ( const Vector2< 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>
Vector2< T > & Nz::Vector2< 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::Vector2< T >::operator< ( const Vector2< 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::Vector2< T >::operator<= ( const Vector2< 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::Vector2< T >::operator== ( const Vector2< 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::Vector2< T >::operator> ( const Vector2< 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::Vector2< T >::operator>= ( const Vector2< 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/7]

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

Sets the components of the vector.

Returns
A reference to this vector
Parameters
XX component
YY component

◆ Set() [2/7]

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

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

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

◆ Set() [3/7]

template<typename T>
Vector2< T > & Nz::Vector2< T >::Set ( const T  vec[2])

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

Returns
A reference to this vector
Parameters
vec[2]vec[0] is X component and vec[1] is Y component

◆ Set() [4/7]

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

Sets the components of the vector from another vector.

Returns
A reference to this vector
Parameters
vecThe other vector

◆ Set() [5/7]

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

Sets the components of the vector from a Vector3.

Returns
A reference to this vector
Parameters
vecVector3 where only the first two components are taken

◆ Set() [6/7]

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

Sets the components of the vector from a Vector4.

Returns
A reference to this vector
Parameters
vecVector4 where only the first two components are taken

◆ Set() [7/7]

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

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

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

◆ SquaredDistance()

template<typename T >
T Nz::Vector2< T >::SquaredDistance ( const Vector2< T > &  vec) const

Calculates the squared distance between two vectors.

Returns
The metric distance between two vectors with the squared euclidean norm
Parameters
vecThe other vector to measure the distance with
See also
Distance

◆ ToString()

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

Gives a string representation.

Returns
A string representation of the object: "Vector2(x, y)"

◆ Unit()

template<typename T >
Vector2< T > Nz::Vector2< T >::Unit ( )
static

Shorthand for the vector (1, 1)

Returns
A vector with components (1, 1)
See also
MakeUnit

◆ UnitX()

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

Shorthand for the vector (1, 0)

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

◆ UnitY()

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

Shorthand for the vector (0, 1)

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

◆ Zero()

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

Shorthand for the vector (0, 0)

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

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