|
SFML
Simple and Fast Multimedia Library
|
Utility template class for manipulating 3-dimensional vectors. More...
#include <Vector3.hpp>
Public Member Functions | |
| constexpr | Vector3 ()=default |
| Default constructor. | |
| constexpr | Vector3 (T x, T y, T z) |
| Construct the vector from its coordinates. | |
| template<typename U> | |
| constexpr | Vector3 (const Vector3< U > &vector) |
| Construct the vector from another type of vector. | |
| SFML_SYSTEM_API T | length () const |
| Length of the vector (floating-point). | |
| constexpr T | lengthSquared () const |
| Square of vector's length. | |
| SFML_SYSTEM_API Vector3 | normalized () const |
| Vector with same direction but length 1 (floating-point). | |
| constexpr T | dot (const Vector3 &rhs) const |
| Dot product of two 3D vectors. | |
| constexpr Vector3 | cross (const Vector3 &rhs) const |
| Cross product of two 3D vectors. | |
| constexpr Vector3 | componentWiseMul (const Vector3 &rhs) const |
Component-wise multiplication of *this and rhs. | |
| constexpr Vector3 | componentWiseDiv (const Vector3 &rhs) const |
Component-wise division of *this and rhs. | |
Public Attributes | |
| T | x {} |
| X coordinate of the vector. | |
| T | y {} |
| Y coordinate of the vector. | |
| T | z {} |
| Z coordinate of the vector. | |
Related Symbols | |
(Note that these are not member symbols.) | |
| template<typename T> | |
| constexpr Vector3< T > | operator- (const Vector3< T > &left) |
| Overload of unary operator -. | |
| template<typename T> | |
| constexpr Vector3< T > & | operator+= (Vector3< T > &left, const Vector3< T > &right) |
| Overload of binary operator +=. | |
| template<typename T> | |
| constexpr Vector3< T > & | operator-= (Vector3< T > &left, const Vector3< T > &right) |
| Overload of binary operator -=. | |
| template<typename T> | |
| constexpr Vector3< T > | operator+ (const Vector3< T > &left, const Vector3< T > &right) |
| Overload of binary operator +. | |
| template<typename T> | |
| constexpr Vector3< T > | operator- (const Vector3< T > &left, const Vector3< T > &right) |
| Overload of binary operator -. | |
| template<typename T> | |
| constexpr Vector3< T > | operator* (const Vector3< T > &left, T right) |
| Overload of binary operator *. | |
| template<typename T> | |
| constexpr Vector3< T > | operator* (T left, const Vector3< T > &right) |
| Overload of binary operator *. | |
| template<typename T> | |
| constexpr Vector3< T > & | operator*= (Vector3< T > &left, T right) |
| Overload of binary operator *=. | |
| template<typename T> | |
| constexpr Vector3< T > | operator/ (const Vector3< T > &left, T right) |
| Overload of binary operator /. | |
| template<typename T> | |
| constexpr Vector3< T > & | operator/= (Vector3< T > &left, T right) |
| Overload of binary operator /=. | |
| template<typename T> | |
| constexpr bool | operator== (const Vector3< T > &left, const Vector3< T > &right) |
| Overload of binary operator ==. | |
| template<typename T> | |
| constexpr bool | operator!= (const Vector3< T > &left, const Vector3< T > &right) |
| Overload of binary operator !=. | |
Utility template class for manipulating 3-dimensional vectors.
sf::Vector3 is a simple class that defines a mathematical vector with three coordinates (x, y and z). It can be used to represent anything that has three dimensions: a size, a point, a velocity, etc.
The template parameter T is the type of the coordinates. It can be any type that supports arithmetic operations (+, -, /, *) and comparisons (==, !=), for example int or float. Note that some operations are only meaningful for vectors where T is a floating point type (e.g. float or double), often because results cannot be represented accurately with integers. The method documentation mentions "(floating-point)" in those cases.
You generally don't have to care about the templated form (sf::Vector3<T>), the most common specializations have special type aliases:
The sf::Vector3 class has a small and simple interface, its x, y and z members can be accessed directly (there are no accessors like setX(), getX()).
Usage example:
Note: for 2-dimensional vectors, see sf::Vector2.
|
constexprdefault |
Default constructor.
Creates a Vector3(0, 0, 0).
|
constexpr |
|
explicitconstexpr |
Construct the vector from another type of vector.
This constructor doesn't replace the copy constructor, it's called only when U != T. A call to this constructor will fail to compile if U is not convertible to T.
| vector | Vector to convert |
|
nodiscardconstexpr |
|
nodiscardconstexpr |
|
nodiscardconstexpr |
Cross product of two 3D vectors.
|
nodiscardconstexpr |
Dot product of two 3D vectors.
|
nodiscard |
Length of the vector (floating-point).
If you are not interested in the actual length, but only in comparisons, consider using lengthSquared().
|
nodiscardconstexpr |
Square of vector's length.
Suitable for comparisons, more efficient than length().
|
nodiscard |
Vector with same direction but length 1 (floating-point).
*this is no zero vector. Overload of binary operator !=.
This operator compares strict difference between two vectors.
| left | Left operand (a vector) |
| right | Right operand (a vector) |
Overload of binary operator *.
| left | Left operand (a vector) |
| right | Right operand (a scalar value) |
Overload of binary operator *.
| left | Left operand (a scalar value) |
| right | Right operand (a vector) |
Overload of binary operator *=.
This operator performs a memberwise multiplication by right, and assigns the result to left.
| left | Left operand (a vector) |
| right | Right operand (a scalar value) |
|
Overload of binary operator +.
| left | Left operand (a vector) |
| right | Right operand (a vector) |
Overload of binary operator +=.
This operator performs a memberwise addition of both vectors, and assigns the result to left.
| left | Left operand (a vector) |
| right | Right operand (a vector) |
Overload of unary operator -.
| left | Vector to negate |
|
Overload of binary operator -.
| left | Left operand (a vector) |
| right | Right operand (a vector) |
Overload of binary operator -=.
This operator performs a memberwise subtraction of both vectors, and assigns the result to left.
| left | Left operand (a vector) |
| right | Right operand (a vector) |
Overload of binary operator /.
| left | Left operand (a vector) |
| right | Right operand (a scalar value) |
Overload of binary operator /=.
This operator performs a memberwise division by right, and assigns the result to left.
| left | Left operand (a vector) |
| right | Right operand (a scalar value) |
Overload of binary operator ==.
This operator compares strict equality between two vectors.
| left | Left operand (a vector) |
| right | Right operand (a vector) |
| T sf::Vector3< T >::x {} |
X coordinate of the vector.
| T sf::Vector3< T >::y {} |
Y coordinate of the vector.
| T sf::Vector3< T >::z {} |
Z coordinate of the vector.