Loading...
Searching...
No Matches
Transform.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// Headers
31
33
35
36#include <array>
37
38
39namespace sf
40{
41class Angle;
42
48{
49public:
56 constexpr Transform() = default;
57
72 constexpr Transform(float a00, float a01, float a02, float a10, float a11, float a12, float a20, float a21, float a22);
73
89 [[nodiscard]] constexpr const float* getMatrix() const;
90
100 [[nodiscard]] constexpr Transform getInverse() const;
101
116 [[nodiscard]] constexpr Vector2f transformPoint(Vector2f point) const;
117
132 [[nodiscard]] constexpr FloatRect transformRect(const FloatRect& rectangle) const;
133
152 constexpr Transform& combine(const Transform& transform);
153
171 constexpr Transform& translate(Vector2f offset);
172
191
216
234 constexpr Transform& scale(Vector2f factors);
235
259 constexpr Transform& scale(Vector2f factors, Vector2f center);
260
262 // Static member data
264 // NOLINTNEXTLINE(readability-identifier-naming)
265 static const Transform Identity;
266
267private:
269 // Member data
271 // clang-format off
272 std::array<float, 16> m_matrix{1.f, 0.f, 0.f, 0.f,
273 0.f, 1.f, 0.f, 0.f,
274 0.f, 0.f, 1.f, 0.f,
275 0.f, 0.f, 0.f, 1.f};
276 // clang-format off
277};
278
291[[nodiscard]] constexpr Transform operator*(const Transform& left, const Transform& right);
292
305constexpr Transform& operator*=(Transform& left, const Transform& right);
306
319[[nodiscard]] constexpr Vector2f operator*(const Transform& left, Vector2f right);
320
334[[nodiscard]] constexpr bool operator==(const Transform& left, const Transform& right);
335
348[[nodiscard]] constexpr bool operator!=(const Transform& left, const Transform& right);
349
350} // namespace sf
351
352#include <SFML/Graphics/Transform.inl>
353
354
#define SFML_GRAPHICS_API
Represents an angle value.
Definition Angle.hpp:35
3x3 transform matrix
Definition Transform.hpp:48
constexpr Vector2f operator*(const Transform &left, Vector2f right)
Overload of binary operator* to transform a point.
constexpr Transform & operator*=(Transform &left, const Transform &right)
Overload of binary operator*= to combine two transforms.
constexpr Transform(float a00, float a01, float a02, float a10, float a11, float a12, float a20, float a21, float a22)
Construct a transform from a 3x3 matrix.
constexpr Vector2f transformPoint(Vector2f point) const
Transform a 2D point.
constexpr Transform & scale(Vector2f factors, Vector2f center)
Combine the current transform with a scaling.
constexpr bool operator!=(const Transform &left, const Transform &right)
Overload of binary operator!= to compare two transforms.
Transform & rotate(Angle angle)
Combine the current transform with a rotation.
constexpr Transform()=default
Default constructor.
constexpr FloatRect transformRect(const FloatRect &rectangle) const
Transform a rectangle.
constexpr Transform & translate(Vector2f offset)
Combine the current transform with a translation.
constexpr bool operator==(const Transform &left, const Transform &right)
Overload of binary operator== to compare two transforms.
static const Transform Identity
The identity transform (does nothing)
constexpr Transform & scale(Vector2f factors)
Combine the current transform with a scaling.
Transform & rotate(Angle angle, Vector2f center)
Combine the current transform with a rotation.
constexpr Transform & combine(const Transform &transform)
Combine the current transform with another one.
constexpr Transform getInverse() const
Return the inverse of the transform.
constexpr const float * getMatrix() const
Return the transform as a 4x4 matrix.
constexpr Transform operator*(const Transform &left, const Transform &right)
Overload of binary operator* to combine two transforms.