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

Three-component vector.

Template parameters
T Data type

See Operations with matrices and vectors for brief introduction. The vectors are columns, see Matrix3x1 for a row vector.

Base classes

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

Derived classes

template<class T>
class Color3
Color in linear RGB color space.

Public static functions

static auto xAxis(T length = T(1)) -> Vector3<T> constexpr
Vector in a direction of X axis (right)
static auto yAxis(T length = T(1)) -> Vector3<T> constexpr
Vector in a direction of Y axis (up)
static auto zAxis(T length = T(1)) -> Vector3<T> constexpr
Vector in a direction of Z axis (backward)
static auto xScale(T scale) -> Vector3<T> constexpr
Scaling vector in a direction of X axis (width)
static auto yScale(T scale) -> Vector3<T> constexpr
Scaling vector in a direction of Y axis (height)
static auto zScale(T scale) -> Vector3<T> constexpr
Scaling vector in a direction of Z axis (depth)

Constructors, destructors, conversion operators

Vector3() constexpr noexcept
Default constructor.
Vector3(ZeroInitT) explicit constexpr noexcept
Construct a zero vector.
Vector3(Magnum::NoInitT) explicit noexcept
Construct a vector without initializing the contents.
Vector3(T value) explicit constexpr noexcept
Construct a vector with one value for all components.
Vector3(T x, T y, T z) constexpr noexcept
Constructor.
Vector3(const Vector2<T>& xy, T z) constexpr noexcept
Constructor.
template<std::size_t size_>
Vector3(const T(&data)[size_]) explicit constexpr noexcept new in Git master
Construct a vector from a fixed-size array.
template<class U>
Vector3(const Vector<3, U>& other) explicit constexpr noexcept
Construct a vector from another of different type.
Vector3(const BitVector3& other) explicit constexpr noexcept new in Git master
Construct a vector from a BitVector.
template<class U, class = decltype(Implementation::VectorConverter<3, T, U>::from(std::declval<U>()))>
Vector3(const U& other) explicit constexpr
Construct a vector from external representation.
Vector3(const Vector<3, T>& other) constexpr noexcept
Copy constructor.

Public functions

auto x() -> T&
X component.
auto x() const -> const T& constexpr
auto y() -> T&
Y component.
auto y() const -> const T& constexpr
auto z() -> T&
Z component.
auto z() const -> const T& constexpr
auto r() -> T&
R component.
auto r() const -> const T& constexpr
auto g() -> T&
G component.
auto g() const -> const T& constexpr
auto b() -> T&
B component.
auto b() const -> const 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>
static Vector3<T> Magnum::Math::Vector3<T>::xAxis(T length = T(1)) constexpr

Vector in a direction of X axis (right)

Usable for translation or rotation along given axis, for example:

Matrix4::translation(Vector3::xAxis(5.0f));
        // same as Matrix4::translation({5.0f, 0.0f, 0.0f});
Matrix4::rotation(30.0_degf, Vector3::xAxis());
        // same as Matrix4::rotation(30.0_degf, {1.0f, 0.0f, 0.0f});

template<class T>
static Vector3<T> Magnum::Math::Vector3<T>::yAxis(T length = T(1)) constexpr

Vector in a direction of Y axis (up)

See xAxis() for more information.

template<class T>
static Vector3<T> Magnum::Math::Vector3<T>::zAxis(T length = T(1)) constexpr

Vector in a direction of Z axis (backward)

See xAxis() for more information.

template<class T>
static Vector3<T> Magnum::Math::Vector3<T>::xScale(T scale) constexpr

Scaling vector in a direction of X axis (width)

Usable for scaling along given direction, for example:

Matrix4::scaling(Vector3::xScale(-2.0f));
        // same as Matrix4::scaling({-2.0f, 1.0f, 1.0f});

template<class T>
static Vector3<T> Magnum::Math::Vector3<T>::yScale(T scale) constexpr

Scaling vector in a direction of Y axis (height)

See xScale() for more information.

template<class T>
static Vector3<T> Magnum::Math::Vector3<T>::zScale(T scale) constexpr

Scaling vector in a direction of Z axis (depth)

See xScale() for more information.

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

Default constructor.

Equivalent to Vector3(ZeroInitT).

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

Construct a zero vector.

\[ \boldsymbol v = \boldsymbol 0 \]

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

Constructor.

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

template<class T>
Magnum::Math::Vector3<T>::Vector3(const Vector2<T>& xy, T z) constexpr noexcept

Constructor.

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

template<class T> template<std::size_t size_>
Magnum::Math::Vector3<T>::Vector3(const T(&data)[size_]) explicit constexpr noexcept new in Git master

Construct a vector from a fixed-size array.

Use from(const T*) to reinterpret an arbitrary pointer to a vector.

template<class T> template<class U>
Magnum::Math::Vector3<T>::Vector3(const Vector<3, 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::Vector3<T>::Vector3(const BitVector3& 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::Vector3<T>::x()

X component.

template<class T>
const T& Magnum::Math::Vector3<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::Vector3<T>::y()

Y component.

template<class T>
const T& Magnum::Math::Vector3<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::Vector3<T>::z()

Z component.

template<class T>
const T& Magnum::Math::Vector3<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::Vector3<T>::r()

R component.

Equivalent to x().

template<class T>
const T& Magnum::Math::Vector3<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::Vector3<T>::g()

G component.

Equivalent to y().

template<class T>
const T& Magnum::Math::Vector3<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::Vector3<T>::b()

B component.

Equivalent to z().

template<class T>
const T& Magnum::Math::Vector3<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>
Vector2<T>& Magnum::Math::Vector3<T>::xy()

XY part of the vector.

Returns First two components of the vector

template<class T>
const Vector2<T> Magnum::Math::Vector3<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::Vector3<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::Vector3<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.