SFML 3.0.1
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-2025 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
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
229 private:
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
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:210