# SFML - Simple and Fast Multimedia Library

SFML 3.0.0

- Main Page
- Topics
- Namespaces
- Classes
- Files

- File List
- File Members

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-2024 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 <SFML/System/Export.hpp>
28
29
30namespace sf
31{
37template <typename T>
38 class Vector3
39{
40public:
47 constexpr Vector3() = default;
48
57 constexpr Vector3(T x, T y, T z);
58
63 template <typename U>
64 constexpr explicit operator Vector3<U>() const;
65
72 [[nodiscard]] SFML_SYSTEM_API T length() const;
73
80 [[nodiscard]] constexpr T lengthSquared() const;
81
88 [[nodiscard]] SFML_SYSTEM_API Vector3 normalized() const;
89
94 [[nodiscard]] constexpr T dot(const Vector3& rhs) const;
95
100 [[nodiscard]] constexpr Vector3 cross(const Vector3& rhs) const;
101
111 [[nodiscard]] constexpr Vector3 componentWiseMul(const Vector3& rhs) const;
112
123 [[nodiscard]] constexpr Vector3 componentWiseDiv(const Vector3& rhs) const;
124
126 // Member data
128 T x{};
129 T y{};
130 T z{};
131};
132
142template <typename T>
143[[nodiscard]] constexpr Vector3<T> operator-(const Vector3<T>& left);
144
158template <typename T>
159 constexpr Vector3<T>& operator+=(Vector3<T>& left, const Vector3<T>& right);
160
174template <typename T>
175 constexpr Vector3<T>& operator-=(Vector3<T>& left, const Vector3<T>& right);
176
187template <typename T>
188[[nodiscard]] constexpr Vector3<T> operator+(const Vector3<T>& left, const Vector3<T>& right);
189
200template <typename T>
201[[nodiscard]] constexpr Vector3<T> operator-(const Vector3<T>& left, const Vector3<T>& right);
202
213template <typename T>
214[[nodiscard]] constexpr Vector3<T> operator*(const Vector3<T>& left, T right);
215
226template <typename T>
227[[nodiscard]] constexpr Vector3<T> operator*(T left, const Vector3<T>& right);
228
242template <typename T>
243 constexpr Vector3<T>& operator*=(Vector3<T>& left, T right);
244
255template <typename T>
256[[nodiscard]] constexpr Vector3<T> operator/(const Vector3<T>& left, T right);
257
271template <typename T>
272 constexpr Vector3<T>& operator/=(Vector3<T>& left, T right);
273
286template <typename T>
287[[nodiscard]] constexpr bool operator==(const Vector3<T>& left, const Vector3<T>& right);
288
301template <typename T>
302[[nodiscard]] constexpr bool operator!=(const Vector3<T>& left, const Vector3<T>& right);
303
304// Aliases for the most common types
305 using Vector3i = Vector3<int>;
306 using Vector3f = Vector3<float>;
307
308} // namespace sf
309
310#include <SFML/System/Vector3.inl>
311
312
Export.hpp
SFML_SYSTEM_API
#define SFML_SYSTEM_API
Definition System/Export.hpp:42
sf::Vector3
Utility template class for manipulating 3-dimensional vectors.
Definition Vector3.hpp:39
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::z
T z
Z coordinate of the vector.
Definition Vector3.hpp:130
sf::Vector3::dot
constexpr T dot(const Vector3 &rhs) const
Dot product of two 3D vectors.
sf::Vector3::x
T x
X coordinate of the vector.
Definition Vector3.hpp:128
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::y
T y
Y coordinate of the vector.
Definition Vector3.hpp:129
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