SFML - Simple and Fast Multimedia Library

SFML 3.1.0
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Related Symbols | List of all members
sf::Vector3< T > Class Template Reference
System module

Utility template class for manipulating 3-dimensional vectors. More...

`#include <SFML/System/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 | operator Vector3< U > () const
| Converts the vector to another type of vector.
T | length () const
| Length of the vector (floating-point).
constexpr T | lengthSquared () const
| Square of vector's length.
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!=.

## Detailed Description

template<typename T>
class sf::Vector3< T >

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:

- sf::Vector3<float> is sf::Vector3f
- sf::Vector3<int> is sf::Vector3i

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:

sf::Vector3f v(16.5f, 24.f, -3.2f);
v.x = 18.2f;
float y = v.y;
sf::Vector3f w = v * 5.f;
sf::Vector3f u;
u = v + w;
float s = v.dot(w);
sf::Vector3f t = v.cross(w);
bool different = (v != u);
sf::Vector3::dot
constexpr T dot(const Vector3 &rhs) const
Dot product of two 3D vectors.
sf::Vector3::y
T y
Y coordinate of the vector.
Definition Vector3.hpp:131
sf::Vector3f
Vector3< float > Vector3f
Definition Vector3.hpp:309

Note: for 2-dimensional vectors, see sf::Vector2.

Definition at line 40 of file Vector3.hpp.

## Constructor & Destructor Documentation

## ◆ Vector3() [1/2]

template<typename T>

sf::Vector3< T >::Vector3 | ( |  | ) |
| constexprdefault

Default constructor.

Creates a Vector3(0, 0, 0).

## ◆ Vector3() [2/2]

template<typename T>

sf::Vector3< T >::Vector3 | ( | T | x,
|  | T | y,
|  | T | z )
| constexpr

Construct the vector from its coordinates.

Parameters

  x | X coordinate
  y | Y coordinate
  z | Z coordinate

## Member Function Documentation

## ◆ componentWiseDiv()

template<typename T>

Vector3 sf::Vector3< T >::componentWiseDiv | ( | const Vector3< T > & | rhs | ) | const
| nodiscardconstexpr

Component-wise division of *this and rhs.

Computes (lhs.x/rhs.x, lhs.y/rhs.y, lhs.z/rhs.z).

Scaling is the most common use case for component-wise multiplication/division.

Precondition
  Neither component of rhs is zero.

## ◆ componentWiseMul()

template<typename T>

Vector3 sf::Vector3< T >::componentWiseMul | ( | const Vector3< T > & | rhs | ) | const
| nodiscardconstexpr

Component-wise multiplication of *this and rhs.

Computes (lhs.x*rhs.x, lhs.y*rhs.y, lhs.z*rhs.z).

Scaling is the most common use case for component-wise multiplication/division. This operation is also known as the Hadamard or Schur product.

## ◆ cross()

template<typename T>

Vector3 sf::Vector3< T >::cross | ( | const Vector3< T > & | rhs | ) | const
| nodiscardconstexpr

Cross product of two 3D vectors.

## ◆ dot()

template<typename T>

T sf::Vector3< T >::dot | ( | const Vector3< T > & | rhs | ) | const
| nodiscardconstexpr

Dot product of two 3D vectors.

## ◆ length()

template<typename T>

T sf::Vector3< T >::length | ( |  | ) | const
| nodiscard

Length of the vector (floating-point).

If you are not interested in the actual length, but only in comparisons, consider using lengthSquared().

## ◆ lengthSquared()

template<typename T>

T sf::Vector3< T >::lengthSquared | ( |  | ) | const
| nodiscardconstexpr

Square of vector's length.

Suitable for comparisons, more efficient than length().

## ◆ normalized()

template<typename T>

Vector3 sf::Vector3< T >::normalized | ( |  | ) | const
| nodiscard

Vector with same direction but length 1 (floating-point).

Precondition
  *this is no zero vector.

## ◆ operator Vector3< U >()

template<typename T>
template<typename U>

sf::Vector3< T >::operator Vector3< U > | ( |  | ) | const
| explicitconstexpr

Converts the vector to another type of vector.

## Friends And Related Symbol Documentation

## ◆ operator!=()

template<typename T>

bool operator!= | ( | const Vector3< T > & | left,
|  | const Vector3< T > & | right )
| related

Overload of binary operator!=.

This operator compares strict difference between two vectors.

Parameters

  left | Left operand (a vector)
  right | Right operand (a vector)

Returns
  true if left is not equal to right

## ◆ operator*() [1/2]

template<typename T>

Vector3< T > operator* | ( | const Vector3< T > & | left,
|  | T | right )
| related

Overload of binary operator*.

Parameters

  left | Left operand (a vector)
  right | Right operand (a scalar value)

Returns
  Member-wise multiplication by right

## ◆ operator*() [2/2]

template<typename T>

Vector3< T > operator* | ( | T | left,
|  | const Vector3< T > & | right )
| related

Overload of binary operator*.

Parameters

  left | Left operand (a scalar value)
  right | Right operand (a vector)

Returns
  Member-wise multiplication by left

## ◆ operator*=()

template<typename T>

Vector3< T > & operator*= | ( | Vector3< T > & | left,
|  | T | right )
| related

Overload of binary operator*=.

This operator performs a member-wise multiplication by right, and assigns the result to left.

Parameters

  left | Left operand (a vector)
  right | Right operand (a scalar value)

Returns
  Reference to left

## ◆ operator+()

template<typename T>

Vector3< T > operator+ | ( | const Vector3< T > & | left,
|  | const Vector3< T > & | right )
| related

Overload of binary operator+.

Parameters

  left | Left operand (a vector)
  right | Right operand (a vector)

Returns
  Member-wise addition of both vectors

## ◆ operator+=()

template<typename T>

Vector3< T > & operator+= | ( | Vector3< T > & | left,
|  | const Vector3< T > & | right )
| related

Overload of binary operator+=.

This operator performs a member-wise addition of both vectors, and assigns the result to left.

Parameters

  left | Left operand (a vector)
  right | Right operand (a vector)

Returns
  Reference to left

## ◆ operator-() [1/2]

template<typename T>

Vector3< T > operator- | ( | const Vector3< T > & | left | ) |
| related

Overload of unary operator-.

Parameters

  left | Vector to negate

Returns
  Member-wise opposite of the vector

## ◆ operator-() [2/2]

template<typename T>

Vector3< T > operator- | ( | const Vector3< T > & | left,
|  | const Vector3< T > & | right )
| related

Overload of binary operator-.

Parameters

  left | Left operand (a vector)
  right | Right operand (a vector)

Returns
  Member-wise subtraction of both vectors

## ◆ operator-=()

template<typename T>

Vector3< T > & operator-= | ( | Vector3< T > & | left,
|  | const Vector3< T > & | right )
| related

Overload of binary operator-=.

This operator performs a member-wise subtraction of both vectors, and assigns the result to left.

Parameters

  left | Left operand (a vector)
  right | Right operand (a vector)

Returns
  Reference to left

## ◆ operator/()

template<typename T>

Vector3< T > operator/ | ( | const Vector3< T > & | left,
|  | T | right )
| related

Overload of binary operator/.

Parameters

  left | Left operand (a vector)
  right | Right operand (a scalar value)

Returns
  Member-wise division by right

## ◆ operator/=()

template<typename T>

Vector3< T > & operator/= | ( | Vector3< T > & | left,
|  | T | right )
| related

Overload of binary operator/=.

This operator performs a member-wise division by right, and assigns the result to left.

Parameters

  left | Left operand (a vector)
  right | Right operand (a scalar value)

Returns
  Reference to left

## ◆ operator==()

template<typename T>

bool operator== | ( | const Vector3< T > & | left,
|  | const Vector3< T > & | right )
| related

Overload of binary operator==.

This operator compares strict equality between two vectors.

Parameters

  left | Left operand (a vector)
  right | Right operand (a vector)

Returns
  true if left is equal to right

## Member Data Documentation

## ◆ x

template<typename T>

T sf::Vector3< T >::x {}

X coordinate of the vector.

Definition at line 130 of file Vector3.hpp.

## ◆ y

template<typename T>

T sf::Vector3< T >::y {}

Y coordinate of the vector.

Definition at line 131 of file Vector3.hpp.

## ◆ z

template<typename T>

T sf::Vector3< T >::z {}

Z coordinate of the vector.

Definition at line 132 of file Vector3.hpp.

The documentation for this class was generated from the following file:

- Vector3.hpp