Transform defined by a position, a rotation and a scale. More...
#include <Transform.h>
Public Types | |
template<typename... Args> | |
using | Callback = std::function< void(Args...)> |
Event listener. More... | |
Public Member Functions | |
Transform () | |
Default constructor. More... | |
void | setPosition (float x, float y) |
Set the position of the object. More... | |
void | setPosition (Vector2f position) |
Set the position of the object. More... | |
Vector2f | getPosition () const |
Get the position of the object. More... | |
void | setRotation (float angle) |
Set the orientation of the object. More... | |
void | rotate (float angle) |
Rotate the object. More... | |
float | getRotation () const |
Get the orientation of the object. More... | |
void | setScale (float factorX, float factorY) |
Set the scale factors of the object. More... | |
void | setScale (Vector2f scale) |
Set the scale factor of the object. More... | |
void | scale (float factorX, float factorY) |
Scale the object by an offset. More... | |
void | scale (Vector2f offset) |
Scale the object by an offset. More... | |
Vector2f | getScale () const |
Get the current scale of the object. More... | |
void | setOrigin (float x, float y) |
Set the local origin of the object. More... | |
void | setOrigin (Vector2f origin) |
Set the local origin of the object. More... | |
Vector2f | getOrigin () const |
Get the local origin of the object. More... | |
void | move (float offsetX, float offsetY) |
Move the object by a given offset. More... | |
void | move (Vector2f offset) |
Move the object by a given offset. More... | |
void | onPropertyChange (Callback< const Property & > callback) |
Add an event listener to a property change event. More... | |
Transform defined by a position, a rotation and a scale.
Definition at line 38 of file Transform.h.
using ime::Transform::Callback = std::function<void(Args...)> |
Event listener.
Definition at line 41 of file Transform.h.
ime::Transform::Transform | ( | ) |
Default constructor.
Vector2f ime::Transform::getOrigin | ( | ) | const |
Get the local origin of the object.
Vector2f ime::Transform::getPosition | ( | ) | const |
Get the position of the object.
float ime::Transform::getRotation | ( | ) | const |
Get the orientation of the object.
The rotation is always in the range [0, 360]
Vector2f ime::Transform::getScale | ( | ) | const |
Get the current scale of the object.
void ime::Transform::move | ( | float | offsetX, |
float | offsetY | ||
) |
Move the object by a given offset.
offsetX | Horizontal offset |
offsetY | Vertical offset |
This function adds to the current position of the object, unlike setPosition which overwrites it
void ime::Transform::move | ( | Vector2f | offset | ) |
Move the object by a given offset.
offset | Offset to apply |
This function adds to the current position of the object, unlike setPosition which overwrites it
Add an event listener to a property change event.
callback | The function to be executed when a property changes |
Note that only one callback may be registered at a time. The new callback overwrites the previous one. The callback is passed the property that changed on invocation. Pass nullptr to cancel the callback.
void ime::Transform::rotate | ( | float | angle | ) |
Rotate the object.
angle | Angle of rotation, in degrees |
This function adds to the current rotation of the object, unlike setRotation which overwrites it
void ime::Transform::scale | ( | float | factorX, |
float | factorY | ||
) |
Scale the object by an offset.
factorX | Horizontal scale factor |
factorY | Vertical scale factor |
This function multiplies the current scale of the object, unlike setScale which overwrites it
void ime::Transform::scale | ( | Vector2f | offset | ) |
Scale the object by an offset.
offset | Offset to apply |
This function multiplies the current scale of the object, unlike setScale which overwrites it
void ime::Transform::setOrigin | ( | float | x, |
float | y | ||
) |
Set the local origin of the object.
x | X coordinate of the new origin |
y | Y coordinate of the new origin |
The origin of an object defines the center point for all transformations (position, scale, rotation). The coordinates of this point must be relative to the top-left corner of the object, and ignore all transformations (position, scale, rotation).
The default origin of a transformable object is (0, 0)
void ime::Transform::setOrigin | ( | Vector2f | origin | ) |
Set the local origin of the object.
origin | New origin |
The origin of an object defines the center point for all transformations (position, scale, rotation). The coordinates of this point must be relative to the top-left corner of the object, and ignore all transformations (position, scale, rotation). The default origin of a transformable object is (0, 0)
void ime::Transform::setPosition | ( | float | x, |
float | y | ||
) |
Set the position of the object.
x | X coordinate of the new position |
y | Y coordinate of the new position |
This function completely overwrites the previous position. See the move function to apply an offset based on the previous position instead. The default position of a transformable object is (0, 0).
void ime::Transform::setPosition | ( | Vector2f | position | ) |
Set the position of the object.
position | New position |
This function completely overwrites the previous position. See the move function to apply an offset based on the previous position instead. The default position of a transformable object is (0, 0).
void ime::Transform::setRotation | ( | float | angle | ) |
Set the orientation of the object.
angle | New rotation, in degrees |
This function completely overwrites the previous rotation. See the rotate function to add an angle based on the previous rotation instead. The default rotation of a transformable object is 0
void ime::Transform::setScale | ( | float | factorX, |
float | factorY | ||
) |
Set the scale factors of the object.
factorX | New horizontal scale factor |
factorY | New vertical scale factor |
This function completely overwrites the previous scale
void ime::Transform::setScale | ( | Vector2f | scale | ) |
Set the scale factor of the object.
scale | New scale |
This function completely overwrites the previous scale