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
28
29
30namespace sf
31{
37template <typename T>
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>
159constexpr Vector3<T>& operator+=(Vector3<T>& left, const Vector3<T>& right);
160
174template <typename T>
175constexpr 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>
243constexpr 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>
272constexpr 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
307
308} // namespace sf
309
310#include <SFML/System/Vector3.inl>
311
312
#define SFML_SYSTEM_API
Utility template class for manipulating 3-dimensional vectors.
Definition Vector3.hpp:39
constexpr Vector3< T > operator/(const Vector3< T > &left, T right)
Overload of binary operator/
constexpr bool operator==(const Vector3< T > &left, const Vector3< T > &right)
Overload of binary operator==
constexpr Vector3 cross(const Vector3 &rhs) const
Cross product of two 3D vectors.
constexpr Vector3< T > & operator/=(Vector3< T > &left, T right)
Overload of binary operator/=
constexpr Vector3 componentWiseDiv(const Vector3 &rhs) const
Component-wise division of *this and rhs.
T z
Z coordinate of the vector.
Definition Vector3.hpp:130
constexpr T dot(const Vector3 &rhs) const
Dot product of two 3D vectors.
T x
X coordinate of the vector.
Definition Vector3.hpp:128
constexpr Vector3< T > & operator-=(Vector3< T > &left, const Vector3< T > &right)
Overload of binary operator-=
constexpr Vector3< T > operator*(T left, const Vector3< T > &right)
Overload of binary operator*
T y
Y coordinate of the vector.
Definition Vector3.hpp:129
constexpr Vector3< T > operator-(const Vector3< T > &left, const Vector3< T > &right)
Overload of binary operator-
constexpr Vector3< T > & operator+=(Vector3< T > &left, const Vector3< T > &right)
Overload of binary operator+=
constexpr Vector3< T > & operator*=(Vector3< T > &left, T right)
Overload of binary operator*=
constexpr Vector3(T x, T y, T z)
Construct the vector from its coordinates.
constexpr Vector3< T > operator*(const Vector3< T > &left, T right)
Overload of binary operator*
constexpr Vector3 componentWiseMul(const Vector3 &rhs) const
Component-wise multiplication of *this and rhs.
constexpr bool operator!=(const Vector3< T > &left, const Vector3< T > &right)
Overload of binary operator!=
constexpr Vector3< T > operator+(const Vector3< T > &left, const Vector3< T > &right)
Overload of binary operator+
Vector3 normalized() const
Vector with same direction but length 1 (floating-point).
constexpr Vector3()=default
Default constructor.
constexpr T lengthSquared() const
Square of vector's length.
T length() const
Length of the vector (floating-point).
constexpr Vector3< T > operator-(const Vector3< T > &left)
Overload of unary operator-