template<class T>
Magnum::Math::Vector4 class

Four-component vector.

Template parameters
T Data type

See Operations with matrices and vectors for brief introduction.

Base classes

template<std::size_t size, class T>
class Vector<4, T>
Vector.

Public static functions

template<std::size_t otherSize>
static auto pad(const Vector<otherSize, T>& a, T xyz, T w) -> Vector4<T> constexpr
Pad vector to four-component one.

Constructors, destructors, conversion operators

Vector4() constexpr noexcept
Default constructor.
Vector4(ZeroInitT) explicit constexpr noexcept
Construct a zero vector.
Vector4(Magnum::NoInitT) explicit noexcept
Construct a vector without initializing the contents.
Vector4(T value) explicit constexpr noexcept
Construct a vector with one value for all components.
Vector4(T x, T y, T z, T w) constexpr noexcept
Constructor.
Vector4(const Vector3<T>& xyz, T w) constexpr noexcept
Constructor.
template<class U>
Vector4(const Vector<4, U>& other) explicit constexpr noexcept
Construct a vector from another of different type.
Vector4(const BitVector4& other) explicit constexpr noexcept new in Git master
Construct a vector from a BitVector.
template<class U, class = decltype(Implementation::VectorConverter<4, T, U>::from(std::declval<U>()))>
Vector4(const U& other) explicit constexpr
Construct a vector from external representation.
Vector4(const Vector<4, T>& other) constexpr noexcept
Copy constructor.

Public functions

auto x() -> T&
X component.
auto x() const -> T constexpr
auto y() -> T&
Y component.
auto y() const -> T constexpr
auto z() -> T&
Z component.
auto z() const -> T constexpr
auto w() -> T&
W component.
auto w() const -> T constexpr
auto r() -> T&
R component.
auto r() const -> T constexpr
auto g() -> T&
G component.
auto g() const -> T constexpr
auto b() -> T&
B component.
auto b() const -> T constexpr
auto a() -> T&
A component.
auto a() const -> T constexpr
auto xyz() -> Vector3<T>&
XYZ part of the vector.
auto xyz() const -> const Vector3<T> constexpr
auto rgb() -> Vector3<T>&
RGB part of the vector.
auto rgb() const -> const Vector3<T> constexpr
auto xy() -> Vector2<T>&
XY part of the vector.
auto xy() const -> const Vector2<T> constexpr
auto rg() -> Vector2<T>& new in Git master
RG part of the vector.
auto rg() const -> const Vector2<T> constexpr new in Git master

Function documentation

template<class T> template<std::size_t otherSize>
static Vector4<T> Magnum::Math::Vector4<T>::pad(const Vector<otherSize, T>& a, T xyz, T w) constexpr

Pad vector to four-component one.

If size of a is smaller than 4, it is padded from right with xyz for first three component and w for fourth component, otherwise it's cut.

template<class T>
Magnum::Math::Vector4<T>::Vector4() constexpr noexcept

Default constructor.

Equivalent to Vector4(ZeroInitT).

template<class T>
Magnum::Math::Vector4<T>::Vector4(ZeroInitT) explicit constexpr noexcept

Construct a zero vector.

\[ \boldsymbol v = \boldsymbol 0 \]

template<class T>
Magnum::Math::Vector4<T>::Vector4(T x, T y, T z, T w) constexpr noexcept

Constructor.

\[ \boldsymbol v = \begin{pmatrix} x \\ y \\ z \\ w \end{pmatrix} \]

template<class T>
Magnum::Math::Vector4<T>::Vector4(const Vector3<T>& xyz, T w) constexpr noexcept

Constructor.

\[ \boldsymbol v = \begin{pmatrix} v_x \\ v_y \\ v_z \\ w \end{pmatrix} \]

template<class T> template<class U>
Magnum::Math::Vector4<T>::Vector4(const Vector<4, U>& other) explicit constexpr noexcept

Construct a vector from another of different type.

Performs only default casting on the values, no rounding or anything else. Example usage:

Vector4 floatingPoint{1.3f, 2.7f, -15.0f, 7.0f};
Vector4i integral{floatingPoint}; // {1, 2, -15, 7}

template<class T>
Magnum::Math::Vector4<T>::Vector4(const BitVector4& other) explicit constexpr noexcept new in Git master

Construct a vector from a BitVector.

Bits that are unset are converted to 0, set bits to 1. If you need a different behavior, for example converting a bit mask to 0 or 255 for a color representation, use lerp(const Vector<size, T>&, const Vector<size, T>&, const BitVector<size>&) instead, for example:

BitVector3 mask = ;
Vector3ub a = Math::lerp(Vector3ub{0}, Vector3ub{255}, mask);

template<class T>
T& Magnum::Math::Vector4<T>::x()

X component.

template<class T>
T Magnum::Math::Vector4<T>::x() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
T& Magnum::Math::Vector4<T>::y()

Y component.

template<class T>
T Magnum::Math::Vector4<T>::y() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
T& Magnum::Math::Vector4<T>::z()

Z component.

template<class T>
T Magnum::Math::Vector4<T>::z() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
T& Magnum::Math::Vector4<T>::w()

W component.

template<class T>
T Magnum::Math::Vector4<T>::w() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
T& Magnum::Math::Vector4<T>::r()

R component.

Equivalent to x().

template<class T>
T Magnum::Math::Vector4<T>::r() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
T& Magnum::Math::Vector4<T>::g()

G component.

Equivalent to y().

template<class T>
T Magnum::Math::Vector4<T>::g() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
T& Magnum::Math::Vector4<T>::b()

B component.

Equivalent to z().

template<class T>
T Magnum::Math::Vector4<T>::b() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
T& Magnum::Math::Vector4<T>::a()

A component.

Equivalent to w().

template<class T>
T Magnum::Math::Vector4<T>::a() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
Vector3<T>& Magnum::Math::Vector4<T>::xyz()

XYZ part of the vector.

Returns First three components of the vector

template<class T>
const Vector3<T> Magnum::Math::Vector4<T>::xyz() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
Vector3<T>& Magnum::Math::Vector4<T>::rgb()

RGB part of the vector.

Returns First three components of the vector

Equivalent to xyz().

template<class T>
const Vector3<T> Magnum::Math::Vector4<T>::rgb() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
Vector2<T>& Magnum::Math::Vector4<T>::xy()

XY part of the vector.

Returns First two components of the vector

template<class T>
const Vector2<T> Magnum::Math::Vector4<T>::xy() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
Vector2<T>& Magnum::Math::Vector4<T>::rg() new in Git master

RG part of the vector.

Returns First two components of the vector

Equivalent to xy().

template<class T>
const Vector2<T> Magnum::Math::Vector4<T>::rg() const constexpr new in Git master

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T> template<class T>
Vector4<T> planeEquation(const Vector3<T>& p0, const Vector3<T>& p1, const Vector3<T>& p2)

Create a plane equation from three points.

Assuming the three points form a triangle in a counter-clockwise winding, creates a plane equation in the following form:

\[ ax + by + cz + d = 0 \]

The first three coefficients describe the scaled normal $ \boldsymbol{n} = (a, b, c)^T $ and are calculated using a cross product. The coefficient $ d $ is calculated using a dot product with the normal $ \boldsymbol{n} $ using the first point in order to satisfy the equation when assigning $ \boldsymbol{p_i} $ to $ x $ , $ y $ , $ z $ .

\[ \begin{array}{rcl} \boldsymbol{n} & = & (\boldsymbol{p_1} - \boldsymbol{p_0}) \times (\boldsymbol{p_2} - \boldsymbol{p_0}) \\ d & = & - \boldsymbol{n} \cdot \boldsymbol{p_0} \end{array} \]

template<class T> template<class T>
Vector4<T> planeEquation(const Vector3<T>& normal, const Vector3<T>& point)

Create a plane equation from a normal and a point.

Creates a plane equation in the following form:

\[ ax + by + cz + d = 0 \]

The first three coefficients describe the scaled normal $ \boldsymbol{n} = (a, b, c)^T $ , the coefficient $ d $ is calculated using a dot product with the normal $ \boldsymbol{n} $ using the point $ \boldsymbol{p} $ in order to satisfy the equation when assigning $ \boldsymbol{p} $ to $ x $ , $ y $ , $ z $ .

\[ d = - \boldsymbol{n} \cdot \boldsymbol{p} \]