 cpp3ds
 Transformable
Decomposed transform defined by a position, a rotation and a scale. More...
#include <Transformable.hpp>
Public Member Functions  
Transformable ()  
Default constructor. More...  
virtual  ~Transformable () 
Virtual destructor. 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...  
void  setRotation (float angle) 
set the orientation of the object More...  
void  setScale (float factorX, float factorY) 
set the scale factors of the object More...  
void  setScale (const Vector2f &factors) 
set the scale factors 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 &  getPosition () const 
get the position of the object More...  
float  getRotation () const 
get the orientation of the object More...  
const Vector2f &  getScale () const 
get the current scale 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...  
void  rotate (float angle) 
Rotate the object. More...  
void  scale (float factorX, float factorY) 
Scale the object. More...  
void  scale (const Vector2f &factor) 
Scale the object. More...  
const Transform &  getTransform () const 
get the combined transform of the object More...  
const Transform &  getInverseTransform () const 
get the inverse of the combined transform of the object More...  
Decomposed transform defined by a position, a rotation and a scale.
This class is provided for convenience, on top of cpp3ds::Transform.
cpp3ds::Transform, as a lowlevel class, offers a great level of flexibility but it is not always convenient to manage. Indeed, one can easily combine any kind of operation, such as a translation followed by a rotation followed by a scaling, but once the result transform is built, there's no way to go backward and, let's say, change only the rotation without modifying the translation and scaling. The entire transform must be recomputed, which means that you need to retrieve the initial translation and scale factors as well, and combine them the same way you did before updating the rotation. This is a tedious operation, and it requires to store all the individual components of the final transform.
That's exactly what cpp3ds::Transformable was written for: it hides these variables and the composed transform behind an easy to use interface. You can set or get any of the individual components without worrying about the others. It also provides the composed transform (as a cpp3ds::Transform), and keeps it uptodate.
In addition to the position, rotation and scale, cpp3ds::Transformable provides an "origin" component, which represents the local origin of the three other components. Let's take an example with a 10x10 pixels sprite. By default, the sprite is positioned/rotated/scaled relatively to its topleft corner, because it is the local point (0, 0). But if we change the origin to be (5, 5), the sprite will be positioned/rotated/scaled around its center instead. And if we set the origin to (10, 10), it will be transformed around its bottomright corner.
To keep the cpp3ds::Transformable class simple, there's only one origin for all the components. You cannot position the sprite relatively to its topleft corner while rotating it around its center, for example. To do such things, use cpp3ds::Transform directly.
cpp3ds::Transformable can be used as a base class. It is often combined with cpp3ds::Drawable – that's what cpp3ds's sprites, texts and shapes do.
It can also be used as a member, if you don't want to use its API directly (because you don't need all its functions, or you have different naming conventions for example).
A note on coordinates and undistorted rendering:
By default, cpp3ds (or more exactly, OpenGL) may interpolate drawable objects such as sprites or texts when rendering. While this allows transitions like slow movements or rotations to appear smoothly, it can lead to unwanted results in some cases, for example blurred or distorted objects. In order to render a cpp3ds::Drawable object pixelperfectly, make sure the involved coordinates allow a 1:1 mapping of pixels in the window to texels (pixels in the texture). More specifically, this means:
Definition at line 40 of file Transformable.hpp.
cpp3ds::Transformable::Transformable  (  ) 
Default constructor.

virtual 
Virtual destructor.
const Transform& cpp3ds::Transformable::getInverseTransform  (  )  const 
get the inverse of the combined transform of the object
const Vector2f& cpp3ds::Transformable::getOrigin  (  )  const 
const Vector2f& cpp3ds::Transformable::getPosition  (  )  const 
float cpp3ds::Transformable::getRotation  (  )  const 
get the orientation of the object
The rotation is always in the range [0, 360].
const Vector2f& cpp3ds::Transformable::getScale  (  )  const 
const Transform& cpp3ds::Transformable::getTransform  (  )  const 
get the combined transform of the object
void cpp3ds::Transformable::move  (  float  offsetX, 
float  offsetY  
) 
Move the object by a given offset.
This function adds to the current position of the object, unlike setPosition which overwrites it. Thus, it is equivalent to the following code:
offsetX  X offset 
offsetY  Y offset 
void cpp3ds::Transformable::move  (  const Vector2f &  offset  ) 
Move the object by a given offset.
This function adds to the current position of the object, unlike setPosition which overwrites it. Thus, it is equivalent to the following code:
offset  Offset 
void cpp3ds::Transformable::rotate  (  float  angle  ) 
Rotate the object.
This function adds to the current rotation of the object, unlike setRotation which overwrites it. Thus, it is equivalent to the following code:
angle  Angle of rotation, in degrees 
void cpp3ds::Transformable::scale  (  float  factorX, 
float  factorY  
) 
Scale the object.
This function multiplies the current scale of the object, unlike setScale which overwrites it. Thus, it is equivalent to the following code:
factorX  Horizontal scale factor 
factorY  Vertical scale factor 
void cpp3ds::Transformable::scale  (  const Vector2f &  factor  ) 
Scale the object.
This function multiplies the current scale of the object, unlike setScale which overwrites it. Thus, it is equivalent to the following code:
factor  Scale factors 
void cpp3ds::Transformable::setOrigin  (  float  x, 
float  y  
) 
set the local origin of the object
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 topleft corner of the object, and ignore all transformations (position, scale, rotation). The default origin of a transformable object is (0, 0).
x  X coordinate of the new origin 
y  Y coordinate of the new origin 
void cpp3ds::Transformable::setOrigin  (  const Vector2f &  origin  ) 
set the local origin of the object
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 topleft corner of the object, and ignore all transformations (position, scale, rotation). The default origin of a transformable object is (0, 0).
origin  New origin 
void cpp3ds::Transformable::setPosition  (  float  x, 
float  y  
) 
set the position of the object
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).
x  X coordinate of the new position 
y  Y coordinate of the new position 
void cpp3ds::Transformable::setPosition  (  const Vector2f &  position  ) 
set the position of the object
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).
position  New position 
void cpp3ds::Transformable::setRotation  (  float  angle  ) 
set the orientation of the object
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.
angle  New rotation, in degrees 
void cpp3ds::Transformable::setScale  (  float  factorX, 
float  factorY  
) 
set the scale factors of the object
This function completely overwrites the previous scale. See the scale function to add a factor based on the previous scale instead. The default scale of a transformable object is (1, 1).
factorX  New horizontal scale factor 
factorY  New vertical scale factor 
void cpp3ds::Transformable::setScale  (  const Vector2f &  factors  ) 