Transform defined by a position, a rotation and a scale. More...
#include <Transform.h>
Public Member Functions | |
Transform () | |
Default constructor. More... | |
void | setPosition (float x, float y) |
Set the position of the object. More... | |
void | setPosition (const Vector2f &position) |
Set the position of the object. More... | |
const 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 (const 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 (const Vector2f &offset) |
Scale the object by an offset. More... | |
const 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 (const Vector2f &origin) |
Set the local origin of the object. More... | |
const 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 (const Vector2f &offset) |
Move the object by a given offset. More... | |
int | onPropertyChange (const Callback< Property > &callback, bool oneTime=false) |
Add an event listener to a property change event. More... | |
bool | unsubscribe (int id) |
Remove a property change event listener. More... | |
Transform defined by a position, a rotation and a scale.
Definition at line 38 of file Transform.h.
ime::Transform::Transform | ( | ) |
Default constructor.
const Vector2f & ime::Transform::getOrigin | ( | ) | const |
Get the local origin of the object.
const 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]
const Vector2f & ime::Transform::getScale | ( | ) | const |
Get the current scale of the object.
void ime::Transform::move | ( | const 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
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
int ime::Transform::onPropertyChange | ( | const Callback< Property > & | callback, |
bool | oneTime = false |
||
) |
Add an event listener to a property change event.
callback | The function to be executed when a property changes |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
A property change event is triggered by any function that has a 'set' prefix, that is a setter function. The name of the property is the text that appears after the 'set' prefix in lowercase. For example, the setPosition() function will trigger a 'position' change event.
The callback is passed a property object that has the name and new value of the property that was changed. For example, the following code prints the position (whenever it changes) to the standard output stream:
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 | ( | const 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::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::setOrigin | ( | const 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::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::setPosition | ( | const 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::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::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 | ( | const Vector2f & | scale | ) |
Set the scale factor of the object.
scale | New scale |
This function completely overwrites the previous scale
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
bool ime::Transform::unsubscribe | ( | int | id | ) |
Remove a property change event listener.
id | The identification number of the event listener |