SFML 3.1.0
Loading...
Searching...
No Matches
Vector3.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
27#include <type_traits>
28
29#include <cassert>
30#include <cmath>
31
32 namespace sf
33{
39 template <typename T>
40 class Vector3
41{
42 public:
49 constexpr Vector3() = default;
50
59 constexpr Vector3(T x, T y, T z);
60
65 template <typename U>
66 constexpr explicit operator Vector3<U>() const;
67
74 [[nodiscard]] T length() const;
75
82 [[nodiscard]] constexpr T lengthSquared() const;
83
90 [[nodiscard]] Vector3 normalized() const;
91
96 [[nodiscard]] constexpr T dot(const Vector3& rhs) const;
97
102 [[nodiscard]] constexpr Vector3 cross(const Vector3& rhs) const;
103
113 [[nodiscard]] constexpr Vector3 componentWiseMul(const Vector3& rhs) const;
114
125 [[nodiscard]] constexpr Vector3 componentWiseDiv(const Vector3& rhs) const;
126
128 // Member data
130 T x{};
131 T y{};
132 T z{};
133};
134
144 template <typename T>
145[[nodiscard]] constexpr Vector3<T> operator-(const Vector3<T>& left);
146
160 template <typename T>
161 constexpr Vector3<T>& operator+=(Vector3<T>& left, const Vector3<T>& right);
162
176 template <typename T>
177 constexpr Vector3<T>& operator-=(Vector3<T>& left, const Vector3<T>& right);
178
189 template <typename T>
190[[nodiscard]] constexpr Vector3<T> operator+(const Vector3<T>& left, const Vector3<T>& right);
191
202 template <typename T>
203[[nodiscard]] constexpr Vector3<T> operator-(const Vector3<T>& left, const Vector3<T>& right);
204
215 template <typename T>
216[[nodiscard]] constexpr Vector3<T> operator*(const Vector3<T>& left, T right);
217
228 template <typename T>
229[[nodiscard]] constexpr Vector3<T> operator*(T left, const Vector3<T>& right);
230
244 template <typename T>
245 constexpr Vector3<T>& operator*=(Vector3<T>& left, T right);
246
257 template <typename T>
258[[nodiscard]] constexpr Vector3<T> operator/(const Vector3<T>& left, T right);
259
273 template <typename T>
274 constexpr Vector3<T>& operator/=(Vector3<T>& left, T right);
275
288 template <typename T>
289[[nodiscard]] constexpr bool operator==(const Vector3<T>& left, const Vector3<T>& right);
290
303 template <typename T>
304[[nodiscard]] constexpr bool operator!=(const Vector3<T>& left, const Vector3<T>& right);
305
306// Aliases for the most common types
307 using Vector3i = Vector3<int>;
308 using Vector3u = Vector3<unsigned int>;
309 using Vector3f = Vector3<float>;
310
311} // namespace sf
312
313#include <SFML/System/Vector3.inl>
314
315
sf::Vector3
Utility template class for manipulating 3-dimensional vectors.
Definition Vector3.hpp:41
sf::Vector3::operator/
constexpr Vector3< T > operator/(const Vector3< T > &left, T right)
Overload of binary operator/.
sf::Vector3::operator==
constexpr bool operator==(const Vector3< T > &left, const Vector3< T > &right)
Overload of binary operator==.
sf::Vector3::cross
constexpr Vector3 cross(const Vector3 &rhs) const
Cross product of two 3D vectors.
sf::Vector3::operator/=
constexpr Vector3< T > & operator/=(Vector3< T > &left, T right)
Overload of binary operator/=.
sf::Vector3::componentWiseDiv
constexpr Vector3 componentWiseDiv(const Vector3 &rhs) const
Component-wise division of *this and rhs.
sf::Vector3< float >::z
float z
Definition Vector3.hpp:132
sf::Vector3::dot
constexpr T dot(const Vector3 &rhs) const
Dot product of two 3D vectors.
sf::Vector3< float >::x
float x
Definition Vector3.hpp:130
sf::Vector3::operator-=
constexpr Vector3< T > & operator-=(Vector3< T > &left, const Vector3< T > &right)
Overload of binary operator-=.
sf::Vector3::operator*
constexpr Vector3< T > operator*(T left, const Vector3< T > &right)
Overload of binary operator*.
sf::Vector3< float >::y
float y
Definition Vector3.hpp:131
sf::Vector3::operator-
constexpr Vector3< T > operator-(const Vector3< T > &left, const Vector3< T > &right)
Overload of binary operator-.
sf::Vector3::operator+=
constexpr Vector3< T > & operator+=(Vector3< T > &left, const Vector3< T > &right)
Overload of binary operator+=.
sf::Vector3::operator*=
constexpr Vector3< T > & operator*=(Vector3< T > &left, T right)
Overload of binary operator*=.
sf::Vector3::Vector3
constexpr Vector3(T x, T y, T z)
Construct the vector from its coordinates.
sf::Vector3::operator*
constexpr Vector3< T > operator*(const Vector3< T > &left, T right)
Overload of binary operator*.
sf::Vector3::componentWiseMul
constexpr Vector3 componentWiseMul(const Vector3 &rhs) const
Component-wise multiplication of *this and rhs.
sf::Vector3::operator!=
constexpr bool operator!=(const Vector3< T > &left, const Vector3< T > &right)
Overload of binary operator!=.
sf::Vector3::operator+
constexpr Vector3< T > operator+(const Vector3< T > &left, const Vector3< T > &right)
Overload of binary operator+.
sf::Vector3::normalized
Vector3 normalized() const
Vector with same direction but length 1 (floating-point).
sf::Vector3::Vector3
constexpr Vector3()=default
Default constructor.
sf::Vector3::lengthSquared
constexpr T lengthSquared() const
Square of vector's length.
sf::Vector3::length
T length() const
Length of the vector (floating-point).
sf::Vector3::operator-
constexpr Vector3< T > operator-(const Vector3< T > &left)
Overload of unary operator-.
sf
Definition AudioResource.hpp:36
sf::Vector3u
Vector3< unsigned int > Vector3u
Definition Vector3.hpp:308
sf::Vector3f
Vector3< float > Vector3f
Definition Vector3.hpp:309
sf::Vector3i
Vector3< int > Vector3i
Definition Vector3.hpp:307