Loading...
Searching...
No Matches
Transformable.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
34#include <SFML/System/Angle.hpp>
35
36
37namespace sf
38{
44{
45public:
50 Transformable() = default;
51
56 virtual ~Transformable() = default;
57
70 void setPosition(Vector2f position);
71
84 void setRotation(Angle angle);
85
98 void setScale(Vector2f factors);
99
115 void setOrigin(Vector2f origin);
116
125 [[nodiscard]] Vector2f getPosition() const;
126
137 [[nodiscard]] Angle getRotation() const;
138
147 [[nodiscard]] Vector2f getScale() const;
148
157 [[nodiscard]] Vector2f getOrigin() const;
158
174 void move(Vector2f offset);
175
189 void rotate(Angle angle);
190
207 void scale(Vector2f factor);
208
217 [[nodiscard]] const Transform& getTransform() const;
218
227 [[nodiscard]] const Transform& getInverseTransform() const;
228
229private:
231 // Member data
233 Vector2f m_origin;
234 Vector2f m_position;
235 Angle m_rotation;
236 Vector2f m_scale{1, 1};
237 mutable Transform m_transform;
238 mutable Transform m_inverseTransform;
239 mutable bool m_transformNeedUpdate{true};
240 mutable bool m_inverseTransformNeedUpdate{true};
241};
242
243} // namespace sf
244
245
#define SFML_GRAPHICS_API
Represents an angle value.
Definition Angle.hpp:35
3x3 transform matrix
Definition Transform.hpp:48
Decomposed transform defined by a position, a rotation and a scale.
Angle getRotation() const
get the orientation of the object
void setRotation(Angle angle)
set the orientation of the object
void scale(Vector2f factor)
Scale the object.
void setOrigin(Vector2f origin)
set the local origin of the object
const Transform & getTransform() const
get the combined transform of the object
void setPosition(Vector2f position)
set the position of the object
void setScale(Vector2f factors)
set the scale factors of the object
virtual ~Transformable()=default
Virtual destructor.
void move(Vector2f offset)
Move the object by a given offset.
Vector2f getScale() const
get the current scale of the object
Vector2f getPosition() const
get the position of the object
Vector2f getOrigin() const
get the local origin of the object
Transformable()=default
Default constructor.
void rotate(Angle angle)
Rotate the object.
const Transform & getInverseTransform() const
get the inverse of the combined transform of the object