Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Transformable.h
1/*
2 * Gamedev Framework (gf)
3 * Copyright (C) 2016-2022 Julien Bernard
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * 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
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 * 3. This notice may not be removed or altered from any source distribution.
20 *
21 * Part of this file comes from SFML, with the same license:
22 * Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
23 */
24#ifndef GF_TRANSFORMABLE_H
25#define GF_TRANSFORMABLE_H
26
27#include "Anchor.h"
28#include "Drawable.h"
29#include "GraphicsApi.h"
30#include "Matrix.h"
31#include "Rect.h"
32#include "Vector.h"
33
34namespace gf {
35#ifndef DOXYGEN_SHOULD_SKIP_THIS
36inline namespace v1 {
37#endif
38
95 class GF_GRAPHICS_API Transformable : public Drawable {
96 public:
108
124 void setOrigin(Vector2f origin);
125
134 return m_origin;
135 }
136
150 void setPosition(Vector2f position);
151
160 return m_position;
161 }
162
178 void move(Vector2f offset);
179
193 void setRotation(float angle);
194
202 float getRotation() const {
203 return m_rotation;
204 }
205
219 void rotate(float angle);
220
234 void setScale(Vector2f factors);
235
236
251 void setScale(float factor) {
252 setScale({ factor, factor });
253 }
254
263 return m_scale;
264 }
265
281 void scale(Vector2f factors);
282
297 void scale(float factor) {
298 scale({ factor, factor });
299 }
300
316
325
326 protected:
336 void setOriginFromAnchorAndBounds(Anchor anchor, const RectF& bounds);
337
338 private:
339 Vector2f m_origin;
340 Vector2f m_position;
341 float m_rotation;
342 Vector2f m_scale;
343 };
344
345#ifndef DOXYGEN_SHOULD_SKIP_THIS
346}
347#endif
348}
349
350#endif // GF_TRANSFORMABLE_H
Abstract base class for objects that can be drawn to a render window.
Definition: Drawable.h:57
Decomposed transform defined by a position, a rotation and a scale.
Definition: Transformable.h:95
void setPosition(Vector2f position)
Set the position of the object.
void rotate(float angle)
Rotate the object.
void move(Vector2f offset)
Move the object by a given offset.
void setOrigin(Vector2f origin)
Set the local origin of the object.
float getRotation() const
Get the orientation of the object.
Definition: Transformable.h:202
Vector2f getOrigin() const
Get the local origin of the object.
Definition: Transformable.h:133
void scale(Vector2f factors)
Scale the object.
void setScale(float factor)
Set the scale factor of the object.
Definition: Transformable.h:251
void setRotation(float angle)
Set the orientation of the object.
Vector2f getPosition() const
Get the position of the object.
Definition: Transformable.h:159
void setOriginFromAnchorAndBounds(Anchor anchor, const RectF &bounds)
Set the origin from an anchor and bounds.
void setScale(Vector2f factors)
Set the scale factors of the object.
Vector2f getScale() const
Get the current scale of the object.
Definition: Transformable.h:262
Matrix3f getTransform() const
Get the combined transform of the object.
Transformable()
Default constructor.
Matrix3f getInverseTransform() const
Get the inverse of the combined transform of the object.
void scale(float factor)
Scale the object.
Definition: Transformable.h:297
GF_CORE_API float angle(Direction direction)
Get an angle from a direction.
GF_CORE_API void scale(Matrix3f &mat, Vector2f factor)
Combine the current transform with a scaling.
Anchor
An anchor of a box.
Definition: Anchor.h:38
The namespace for gf classes.