Gamedev Framework (gf)  0.5.0
A C++11 framework for 2D games
Transformable.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2017 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 "Matrix.h"
30 #include "Portability.h"
31 #include "Rect.h"
32 #include "Vector.h"
33 
34 namespace gf {
35 #ifndef DOXYGEN_SHOULD_SKIP_THIS
36 inline namespace v1 {
37 #endif
38 
95  class GF_API Transformable : public Drawable {
96  public:
107  Transformable();
108 
124  void setOrigin(Vector2f origin);
125 
133  Vector2f getOrigin() const {
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 
262  Vector2f getScale() const {
263  return m_scale;
264  }
265 
281  void scale(Vector2f factors);
282 
297  void scale(float factor) {
298  scale({ factor, factor });
299  }
300 
315  Matrix3f getTransform() const;
316 
324  Matrix3f getInverseTransform() const;
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
Decomposed transform defined by a position, a rotation and a scale.
Definition: Transformable.h:95
void scale(float factor)
Scale the object.
Definition: Transformable.h:297
void scale(Matrix3f &mat, Vector2f factor)
Combine the current transform with a scaling.
Vector2f getScale() const
Get the current scale of the object.
Definition: Transformable.h:262
float getRotation() const
Get the orientation of the object.
Definition: Transformable.h:202
void setScale(float factor)
Set the scale factor of the object.
Definition: Transformable.h:251
Abstract base class for objects that can be drawn to a render window.
Definition: Drawable.h:79
The namespace for gf classes.
Definition: Action.h:34
float angle(Direction direction)
Get an angle from a direction.
void rotate(Matrix3f &mat, float angle)
Combine the current transform with a rotation.
Anchor
An anchor of a box.
Definition: Anchor.h:41
Vector2f getOrigin() const
Get the local origin of the object.
Definition: Transformable.h:133
Vector2f getPosition() const
Get the position of the object.
Definition: Transformable.h:159