#include <Magnum/Math/Vector4.h>
template<class T>
Vector4 class
Four-component vector.
Template parameters | |
---|---|
T | Data type |
See Operations with matrices and vectors for brief introduction. The vectors are columns, see Matrix4x1 for a row vector.
Base classes
-
template<std::class Vector<4, T>
size_t size, class T> - Vector.
Public static functions
-
template<std::static auto pad(const Vector<otherSize, T>& a, T xyz, T w) -> Vector4<T> constexpr
size_t otherSize> - 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<std::Vector4(const T(&data)[size_]) explicit constexpr noexcept new in Git master
size_t size_> - Construct a vector from a fixed-size array.
-
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::Vector4(const U& other) explicit constexpr
declval<U>()))> - 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 -> 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 w() -> T&
- W component.
- auto w() 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 a() -> T&
- A component.
- auto a() const -> 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(T x,
T y,
T z,
T w) constexpr noexcept
Constructor.
template<class T>
template<std:: size_t size_>
Magnum:: Math:: Vector4<T>:: Vector4(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:: 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>
const 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>
const 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>
const 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>
const 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>
const 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>
const 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>
const 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>
const 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>
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:
The first three coefficients describe the scaled normal and are calculated using a cross product. The coefficient is calculated using a dot product with the normal using the first point in order to satisfy the equation when assigning to , , .
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:
The first three coefficients describe the scaled normal , the coefficient is calculated using a dot product with the normal using the point in order to satisfy the equation when assigning to , , .