Class OcsfmlGraphics.transformable

class transformable : ?position:float * float -> ?scale:float * float -> ?origin:float * float -> ?rotation:float -> unit -> object .. end
Decomposed transform defined by a position, a rotation and a scale.

This class is provided for convenience, on top of Transform.

Transform, as a low-level 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 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 Transform), and keeps it up-to-date.

In addition to the position, rotation and scale, 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 positionned/rotated/scaled relatively to its top-left corner, because it is the local point (0, 0). But if we change the origin to be (5, 5), the sprite will be positionned/rotated/scaled around its center instead. And if we set the origin to (10, 10), it will be transformed around its bottom-right corner.

To keep the Transformable class simple, there's only one origin for all the components. You cannot position the sprite relatively to its top-left corner while rotating it around its center, for example. To do such things, use Transform directly.

Transformable can be used as a base class. It is often combined with Drawable -- that's what SFML's sprites, texts and shapes do.


method destroy : unit
method affect : < affect : 'a; destroy : unit;
get_inverse_transform : const_transform
reference;
get_origin : float * float; get_position : float * float;
get_rotation : float; get_scale : float * float;
get_transform : const_transform reference;
move : float -> float -> unit; move_v : float * float -> unit;
rep__sf_Transformable : Transformable.t;
rotate : float -> unit; scale : float -> float -> unit;
scale_v : float * float -> unit; set_origin : float -> float -> unit;
set_origin_v : float * float -> unit;
set_position : float -> float -> unit;
set_position_v : float * float -> unit; set_rotation : float -> unit;
set_scale : float -> float -> unit; set_scale_v : float * float -> unit;
.. > ->
unit as 'a
method get_inverse_transform : const_transform reference
Get the inverse of the combined transform of the object
Returns Inverse of the combined transformations applied to the object.
method get_origin : float * float
Get the local origin of the object.
Returns Current origin.
method get_position : float * float
Getthe position of the object.
Returns Current position
method get_rotation : float
Get the the orientation of the object.

The rotation is always in the range 0, 360.
Returns Current rotation, in degrees.

method get_scale : float * float
Get the scale of the object.
Returns Current scale factors.
method get_transform : const_transform reference
Get the combined transform of the object.
Returns Transform combining the position/rotation/scale/origin of the object
method move : float -> float -> unit
Move the object by a given offset.

This function adds to the current position of the object, unlike setPosition which overwrites it.

method move_v : float * float -> unit
Move the object by a given offset.

This function adds to the current position of the object, unlike setPosition which overwrites it.

method rotate : float -> unit
Rotate the object.

This function adds to the current rotation of the object, unlike setRotation which overwrites it.

method scale : float -> float -> unit
Scale the object.

This function multiplies the current scale of the object, unlike setScale which overwrites it.

method scale_v : float * float -> unit
Scale the object.

This function multiplies the current scale of the object, unlike setScale which overwrites it.

method set_origin : float -> float -> unit
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 top-left corner of the object, and ignore all transformations (position, scale, rotation). The default origin of a transformable object is (0, 0).

method set_origin_v : float * float -> unit
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 top-left corner of the object, and ignore all transformations (position, scale, rotation). The default origin of a transformable object is (0, 0).

method set_position : float -> float -> unit
Set the position of the object

This function completely overwrites the previous position. See Move to apply an offset based on the previous position instead. The default position of a transformable object is (0, 0).

method set_position_v : float * float -> unit
Set the position of the object

This function completely overwrites the previous position. See Move to apply an offset based on the previous position instead. The default position of a transformable object is (0, 0).

method set_rotation : float -> unit
Set the orientation of the object

This function completely overwrites the previous rotation. See Rotate to add an angle based on the previous rotation instead. The default rotation of a transformable object is 0.

method set_scale : float -> float -> unit
Set the scale factors of the object

This function completely overwrites the previous scale. See Scale to add a factor based on the previous scale instead. The default scale of a transformable object is (1, 1).

method set_scale_v : float * float -> unit
Set the scale factors of the object

This function completely overwrites the previous scale. See Scale to add a factor based on the previous scale instead. The default scale of a transformable object is (1, 1).