TGUI  0.10-beta
tgui::Transform Class Reference

Defines a transform matrix. More...

#include <TGUI/Transform.hpp>

Public Member Functions

 Transform ()
 Default constructor. More...
 
 Transform (float a00, float a01, float a02, float a10, float a11, float a12, float a20, float a21, float a22)
 Construct a transform from a 3x3 matrix. More...
 
 Transform (const float matrix[16])
 Constructs a transform from a 4x4 matrix. More...
 
const float * getMatrix () const
 Return the transform as a 4x4 matrix. More...
 
Transform getInverse () const
 Return the inverse of the transform. More...
 
Vector2f transformPoint (const Vector2f &point) const
 Transform a 2D point. More...
 
FloatRect transformRect (const FloatRect &rectangle) const
 Transform a rectangle. More...
 
Transformcombine (const Transform &other)
 Combine the current transform with another one. More...
 
Transformtranslate (const Vector2f &offset)
 Combine the current transform with a translation. More...
 
Transformrotate (float angle, const Vector2f &center={0, 0})
 Combine the current transform with a rotation. More...
 
Transformscale (const Vector2f &factors, const Vector2f &center={0, 0})
 Combine the current transform with a scaling. More...
 
Transform operator* (const Transform &right) const
 Overload of binary operator * to combine two transforms. More...
 
Transformoperator*= (const Transform &right)
 
Vector2f operator* (const Vector2f &right) const
 
void roundPosition ()
 Rounds the position stored in the transform to the nearest integer.
 
void roundPositionForText ()
 Rounds the position stored in the transform to the nearest integer.
 

Detailed Description

Defines a transform matrix.

Constructor & Destructor Documentation

◆ Transform() [1/3]

tgui::Transform::Transform ( )

Default constructor.

Creates an identity transform (a transform that does nothing).

◆ Transform() [2/3]

tgui::Transform::Transform ( float  a00,
float  a01,
float  a02,
float  a10,
float  a11,
float  a12,
float  a20,
float  a21,
float  a22 
)

Construct a transform from a 3x3 matrix.

Parameters
a00Element (0, 0) of the 3x3 matrix
a01Element (0, 1) of the 3x3 matrix
a02Element (0, 2) of the 3x3 matrix
a10Element (1, 0) of the 3x3 matrix
a11Element (1, 1) of the 3x3 matrix
a12Element (1, 2) of the 3x3 matrix
a20Element (2, 0) of the 3x3 matrix
a21Element (2, 1) of the 3x3 matrix
a22Element (2, 2) of the 3x3 matrix

◆ Transform() [3/3]

tgui::Transform::Transform ( const float  matrix[16])

Constructs a transform from a 4x4 matrix.

Parameters
matrixPointer to a 4x4 matrix, similar to what getMatrix returns

Member Function Documentation

◆ combine()

Transform & tgui::Transform::combine ( const Transform other)

Combine the current transform with another one.

The result is a transform that is equivalent to applying the other transform followed by this transform. Mathematically, it is equivalent to a matrix multiplication (*this) * other.

Parameters
otherTransform to combine with this transform
Returns
Reference to *this

◆ getInverse()

Transform tgui::Transform::getInverse ( ) const

Return the inverse of the transform.

Returns
A new transform which is the inverse of this transform

If the inverse cannot be computed, an identity transform is returned.

◆ getMatrix()

const float * tgui::Transform::getMatrix ( ) const

Return the transform as a 4x4 matrix.

This function returns a pointer to an array of 16 floats containing the transform elements as a 4x4 matrix, which is directly compatible with OpenGL functions.

glLoadMatrixf(transform.getMatrix());
Returns
Pointer to a 4x4 matrix

◆ operator*()

Transform tgui::Transform::operator* ( const Transform right) const

Overload of binary operator * to combine two transforms.

Parameters
rightTransform to combine with a copy of this transform
See also
combine

◆ rotate()

Transform & tgui::Transform::rotate ( float  angle,
const Vector2f center = {0, 0} 
)

Combine the current transform with a rotation.

The center of rotation is provided for convenience as a second argument, so that you can build rotations around arbitrary points more easily (and efficiently) than the usual translate(-center).rotate(angle).translate(center).

Parameters
angleRotation angle, in degrees
centerCenter of rotation
Returns
Reference to *this

◆ scale()

Transform & tgui::Transform::scale ( const Vector2f factors,
const Vector2f center = {0, 0} 
)

Combine the current transform with a scaling.

The center of scaling is provided for convenience as a second argument, so that you can build scaling around arbitrary points more easily (and efficiently) than the usual translate(-center).scale(factors).translate(center).

Parameters
factorsScaling factors
centerCenter of scaling
Returns
Reference to *this

◆ transformPoint()

Vector2f tgui::Transform::transformPoint ( const Vector2f point) const

Transform a 2D point.

Parameters
pointPoint to transform
Returns
Transformed point

◆ transformRect()

FloatRect tgui::Transform::transformRect ( const FloatRect rectangle) const

Transform a rectangle.

If the transform contains a rotation, the bounding rectangle of the transformed rectangle is returned.

Parameters
rectangleRectangle to transform
Returns
Transformed rectangle

◆ translate()

Transform & tgui::Transform::translate ( const Vector2f offset)

Combine the current transform with a translation.

Parameters
offsetTranslation offset to apply
Returns
Reference to *this

The documentation for this class was generated from the following file: