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-2026 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
86 void setPosition(Vector2f position);
87
100 void setRotation(Angle angle);
101
114 void setScale(Vector2f factors);
115
131 void setOrigin(Vector2f origin);
132
141 [[nodiscard]] Vector2f getPosition() const;
142
153 [[nodiscard]] Angle getRotation() const;
154
163 [[nodiscard]] Vector2f getScale() const;
164
173 [[nodiscard]] Vector2f getOrigin() const;
174
190 void move(Vector2f offset);
191
205 void rotate(Angle angle);
206
223 void scale(Vector2f factor);
224
233 [[nodiscard]] const Transform& getTransform() const;
234
243 [[nodiscard]] const Transform& getInverseTransform() const;
244
245private:
247 // Member data
249 Vector2f m_origin;
250 Vector2f m_position;
251 Angle m_rotation;
252 Vector2f m_scale{1, 1};
253 mutable Transform m_transform;
254 mutable Transform m_inverseTransform;
255 mutable bool m_transformNeedUpdate{true};
256 mutable bool m_inverseTransformNeedUpdate{true};
257};
258
259} // namespace sf
260
261
#define SFML_GRAPHICS_API
Represents an angle value.
Definition Angle.hpp:35
3x3 transform matrix
Definition Transform.hpp:48
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
Vector2< float > Vector2f
Definition Vector2.hpp:213