Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Public Member Functions | Public Attributes | List of all members
gf::Vector< T, 3 > Struct Template Reference

A 3D vector. More...

#include <gf/Vector.h>

Public Member Functions

 Vector ()=default
 Default constructor. More...
 
constexpr Vector (ZeroType) noexcept
 Constructor that zero the vector out. More...
 
constexpr Vector (T val) noexcept
 Constructor that fills the vector with a value. More...
 
constexpr Vector (const T *array)
 Constructor that takes an array. More...
 
constexpr Vector (T first, T second, T third) noexcept
 Constructor that takes 3 components. More...
 
constexpr Vector (Vector< T, 2 > xy, T third)
 Constructor that takes a 2D vector and a z component. More...
 
 Vector (const Vector &other)=default
 Default copy constructor. More...
 
template<typename U >
 Vector (const Vector< U, 3 > &other) noexcept
 Converting copy constructor. More...
 
Vectoroperator= (const Vector &other)=default
 Default copy assignment. More...
 
constexpr T operator[] (std::size_t i) const
 Access to the \( i \)-th coordinate. More...
 
constexpr T & operator[] (std::size_t i)
 Access to the \( i \)-th coordinate. More...
 
T * begin ()
 Iterator.to the first element. More...
 
T * end ()
 Iterator to the element after the last one. More...
 
const T * begin () const
 Iterator.to the first element (const version). More...
 
const T * end () const
 Iterator on the element after the last one (const version). More...
 
const T * cbegin () const
 Iterator.on the first element (const version). More...
 
const T * cend () const
 Iterator on the element after the last one (const version). More...
 
constexpr void zero () noexcept
 Zero out the vector. More...
 
constexpr Vector< T, 2 > xy () const
 Swizzle to get the first two coordinates as a 2D vector. More...
 

Public Attributes

union gf::Vector< T, 3 >:: { ... }  
 
union gf::Vector< T, 3 >:: { ... }  
 
union gf::Vector< T, 3 >:: { ... }  
 
x
 First coordinate in the (x,y,z) representation. More...
 
r
 First coordinate in the (r,g,b) representation. More...
 
y
 Second coordinate in the (x,y,z) representation. More...
 
g
 Second coordinate in the (r,g,b) representation. More...
 
z
 Third coordinate in the (x,y,z) representation. More...
 
b
 Third coordinate in the (r,g,b) representation. More...
 

Detailed Description

template<typename T>
struct gf::Vector< T, 3 >

A 3D vector.

This specialization of gf::Vector handles the 3-dimension spaces. It can be accessed with various representations:

Several common typedef are defined:

For colors, some additional typedef are defined:

Usage example:

gf::Vector3f v1(58.0f, 96.0f, 63.0f);
v1.x = 94.0f;
gf::Vector3f v2 = v1 * 5.0f;
gf::Vector3f v3 = v1 + v2;
gf::Color3u green(0x00, 0xFF, 0x00);
A 3D vector.
Definition: Vector.h:570
General purpose math vector.
Definition: Vector.h:61

Constructor & Destructor Documentation

◆ Vector() [1/8]

template<typename T >
gf::Vector< T, 3 >::Vector ( )
default

Default constructor.

This constructor is defaulted so that this type is trivial.

◆ Vector() [2/8]

template<typename T >
constexpr gf::Vector< T, 3 >::Vector ( ZeroType  )
inlineconstexprnoexcept

Constructor that zero the vector out.

◆ Vector() [3/8]

template<typename T >
constexpr gf::Vector< T, 3 >::Vector ( val)
inlineexplicitconstexprnoexcept

Constructor that fills the vector with a value.

This constructor takes a value and fills the entire vector with this value. Care must be taken when calling this constructor:

gf::Vector<int, 3> vecOK(42); // OK, vector is filled with 42
gf::Vector<int, 3> vecKO{42}; // KO, vector is initialized with a 42 in the first coordinate
Parameters
valThe value to fill the vector with

◆ Vector() [4/8]

template<typename T >
constexpr gf::Vector< T, 3 >::Vector ( const T *  array)
inlineexplicitconstexpr

Constructor that takes an array.

This constructor can ease conversion from other math libraries. The array must contain enough data for 3 dimensions.

float array[3] = { 1.0f, -1.0f, 0.0f };
Parameters
arrayAn array with the values of the vector

◆ Vector() [5/8]

template<typename T >
constexpr gf::Vector< T, 3 >::Vector ( first,
second,
third 
)
inlineconstexprnoexcept

Constructor that takes 3 components.

Parameters
firstThe first component
secondThe second component
thirdThe third component

◆ Vector() [6/8]

template<typename T >
constexpr gf::Vector< T, 3 >::Vector ( Vector< T, 2 >  xy,
third 
)
inlineconstexpr

Constructor that takes a 2D vector and a z component.

Parameters
xyThe first 2 component, x and y
thirdThe z component

◆ Vector() [7/8]

template<typename T >
gf::Vector< T, 3 >::Vector ( const Vector< T, 3 > &  other)
default

Default copy constructor.

This constructor is defaulted so that this type is trivial.

Parameters
otherThe vector to copy from

◆ Vector() [8/8]

template<typename T >
template<typename U >
gf::Vector< T, 3 >::Vector ( const Vector< U, 3 > &  other)
inlinenoexcept

Converting copy constructor.

Parameters
otherThe vector to copy from

Member Function Documentation

◆ begin() [1/2]

template<typename T >
T * gf::Vector< T, 3 >::begin ( )
inline

Iterator.to the first element.

Returns
A pointer to the first element.

◆ begin() [2/2]

template<typename T >
const T * gf::Vector< T, 3 >::begin ( ) const
inline

Iterator.to the first element (const version).

Returns
A pointer on the first const element.

◆ cbegin()

template<typename T >
const T * gf::Vector< T, 3 >::cbegin ( ) const
inline

Iterator.on the first element (const version).

Returns
A pointer on the first const element.

◆ cend()

template<typename T >
const T * gf::Vector< T, 3 >::cend ( ) const
inline

Iterator on the element after the last one (const version).

Returns
An invalid pointer that is the adress after the last const element.

◆ end() [1/2]

template<typename T >
T * gf::Vector< T, 3 >::end ( )
inline

Iterator to the element after the last one.

Returns
An invalid pointer that is the adress after the last element.

◆ end() [2/2]

template<typename T >
const T * gf::Vector< T, 3 >::end ( ) const
inline

Iterator on the element after the last one (const version).

Returns
An invalid pointer that is the adress after the last const element.

◆ operator=()

template<typename T >
Vector & gf::Vector< T, 3 >::operator= ( const Vector< T, 3 > &  other)
default

Default copy assignment.

This operator is defaulted so that this type is trivial.

◆ operator[]() [1/2]

template<typename T >
constexpr T & gf::Vector< T, 3 >::operator[] ( std::size_t  i)
inlineconstexpr

Access to the \( i \)-th coordinate.

vec[0] = vec[1] = vec[2] = 0;
Parameters
ithe coordinate number
Returns
The \( i \)-th coordinate of the vector

◆ operator[]() [2/2]

template<typename T >
constexpr T gf::Vector< T, 3 >::operator[] ( std::size_t  i) const
inlineconstexpr

Access to the \( i \)-th coordinate.

gf::Vector<int, 3> vec = { 1, 3, 5 };
std::printf("%i", vec[1]); // prints 3
Parameters
ithe coordinate number
Returns
The \( i \)-th coordinate of the vector

◆ xy()

template<typename T >
constexpr Vector< T, 2 > gf::Vector< T, 3 >::xy ( ) const
inlineconstexpr

Swizzle to get the first two coordinates as a 2D vector.

◆ zero()

template<typename T >
constexpr void gf::Vector< T, 3 >::zero ( )
inlineconstexprnoexcept

Zero out the vector.

Member Data Documentation

◆ 

union gf::Vector< T, 3 > { ... } gf::Vector< T, 3 >::@71

An anonymous union to handle the first coordinate

◆ 

union gf::Vector< T, 3 > { ... } gf::Vector< T, 3 >::@73

An anonymous union to handle the second coordinate

◆ 

union gf::Vector< T, 3 > { ... } gf::Vector< T, 3 >::@75

An anonymous union to handle the third coordinate

◆ b

template<typename T >
T gf::Vector< T, 3 >::b

Third coordinate in the (r,g,b) representation.

See also
r, g

◆ g

template<typename T >
T gf::Vector< T, 3 >::g

Second coordinate in the (r,g,b) representation.

See also
r, b

◆ r

template<typename T >
T gf::Vector< T, 3 >::r

First coordinate in the (r,g,b) representation.

See also
g, b

◆ x

template<typename T >
T gf::Vector< T, 3 >::x

First coordinate in the (x,y,z) representation.

See also
y, z

◆ y

template<typename T >
T gf::Vector< T, 3 >::y

Second coordinate in the (x,y,z) representation.

See also
x, z

◆ z

template<typename T >
T gf::Vector< T, 3 >::z

Third coordinate in the (x,y,z) representation.

See also
x, y