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
70 template <typename U>
71 constexpr explicit Vector3(const Vector3<U>& vector);
72
79 [[nodiscard]] SFML_SYSTEM_API T length() const;
80
87 [[nodiscard]] constexpr T lengthSquared() const;
88
95 [[nodiscard]] SFML_SYSTEM_API Vector3 normalized() const;
96
101 [[nodiscard]] constexpr T dot(const Vector3& rhs) const;
102
107 [[nodiscard]] constexpr Vector3 cross(const Vector3& rhs) const;
108
118 [[nodiscard]] constexpr Vector3 componentWiseMul(const Vector3& rhs) const;
119
130 [[nodiscard]] constexpr Vector3 componentWiseDiv(const Vector3& rhs) const;
131
133 // Member data
135 T x{};
136 T y{};
137 T z{};
138};
139
149template <typename T>
150[[nodiscard]] constexpr Vector3<T> operator-(const Vector3<T>& left);
151
165template <typename T>
166constexpr Vector3<T>& operator+=(Vector3<T>& left, const Vector3<T>& right);
167
181template <typename T>
182constexpr Vector3<T>& operator-=(Vector3<T>& left, const Vector3<T>& right);
183
194template <typename T>
195[[nodiscard]] constexpr Vector3<T> operator+(const Vector3<T>& left, const Vector3<T>& right);
196
207template <typename T>
208[[nodiscard]] constexpr Vector3<T> operator-(const Vector3<T>& left, const Vector3<T>& right);
209
220template <typename T>
221[[nodiscard]] constexpr Vector3<T> operator*(const Vector3<T>& left, T right);
222
233template <typename T>
234[[nodiscard]] constexpr Vector3<T> operator*(T left, const Vector3<T>& right);
235
249template <typename T>
250constexpr Vector3<T>& operator*=(Vector3<T>& left, T right);
251
262template <typename T>
263[[nodiscard]] constexpr Vector3<T> operator/(const Vector3<T>& left, T right);
264
278template <typename T>
279constexpr Vector3<T>& operator/=(Vector3<T>& left, T right);
280
293template <typename T>
294[[nodiscard]] constexpr bool operator==(const Vector3<T>& left, const Vector3<T>& right);
295
308template <typename T>
309[[nodiscard]] constexpr bool operator!=(const Vector3<T>& left, const Vector3<T>& right);
310
311// Define the most common types
314
315} // namespace sf
316
317#include <SFML/System/Vector3.inl>
318
319
#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:137
constexpr T dot(const Vector3 &rhs) const
Dot product of two 3D vectors.
T x
X coordinate of the vector.
Definition Vector3.hpp:135
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:136
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(const Vector3< U > &vector)
Construct the vector from another type of vector.
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-