SFML 3.1.0
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
30#include <SFML/Graphics/Export.hpp>
31
32#include <SFML/Graphics/Transform.hpp>
33
34#include <SFML/System/Angle.hpp>
35
36
37 namespace sf
38{
43 class SFML_GRAPHICS_API Transformable
44{
45 public:
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
245 private:
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
Angle.hpp
Export.hpp
SFML_GRAPHICS_API
#define SFML_GRAPHICS_API
Definition Graphics/Export.hpp:42
Transform.hpp
sf::Angle
Represents an angle value.
Definition Angle.hpp:35
sf::Transform
3x3 transform matrix
Definition Transform.hpp:48
sf::Transformable::getRotation
Angle getRotation() const
get the orientation of the object
sf::Transformable::setRotation
void setRotation(Angle angle)
set the orientation of the object
sf::Transformable::scale
void scale(Vector2f factor)
Scale the object.
sf::Transformable::setOrigin
void setOrigin(Vector2f origin)
set the local origin of the object
sf::Transformable::getTransform
const Transform & getTransform() const
get the combined transform of the object
sf::Transformable::setPosition
void setPosition(Vector2f position)
set the position of the object
sf::Transformable::setScale
void setScale(Vector2f factors)
set the scale factors of the object
sf::Transformable::~Transformable
virtual ~Transformable()=default
Virtual destructor.
sf::Transformable::move
void move(Vector2f offset)
Move the object by a given offset.
sf::Transformable::getScale
Vector2f getScale() const
get the current scale of the object
sf::Transformable::getPosition
Vector2f getPosition() const
get the position of the object
sf::Transformable::getOrigin
Vector2f getOrigin() const
get the local origin of the object
sf::Transformable::Transformable
Transformable()=default
Default constructor.
sf::Transformable::rotate
void rotate(Angle angle)
Rotate the object.
sf::Transformable::getInverseTransform
const Transform & getInverseTransform() const
get the inverse of the combined transform of the object
sf
Definition AudioResource.hpp:36
sf::Vector2f
Vector2< float > Vector2f
Definition Vector2.hpp:213