TGUI  1.6.1
Loading...
Searching...
No Matches
tgui::Transform Class Reference

Defines a transform matrix. More...

#include <TGUI/Transform.hpp>

Public Member Functions

 Transform ()
 Default constructor.
 
 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.
 
 Transform (const std::array< float, 16 > &matrix)
 Constructs a transform from a 4x4 matrix.
 
const std::array< float, 16 > & getMatrix () const
 Return the transform as a 4x4 matrix.
 
Transform getInverse () const
 Return the inverse of the transform.
 
Vector2f transformPoint (const Vector2f &point) const
 Transform a 2D point.
 
FloatRect transformRect (const FloatRect &rectangle) const
 Transform a rectangle.
 
Transformcombine (const Transform &other)
 Combine the current transform with another one.
 
Transformtranslate (const Vector2f &offset)
 Combine the current transform with a translation.
 
Transformrotate (float angle, const Vector2f &center={0, 0})
 Combine the current transform with a rotation.
 
Transformscale (const Vector2f &factors, const Vector2f &center={0, 0})
 Combine the current transform with a scaling.
 
Transform operator* (const Transform &right) const
 Overload of binary operator * to combine two transforms.
 
Transformoperator*= (const Transform &right)
 
Vector2f operator* (const Vector2f &right) const
 
void roundPosition (float pixelScaleX, float pixelScaleY)
 Rounds the position stored in the transform to the nearest pixel.
 
void roundPosition (Vector2f pixelScale)
 Rounds the position stored in the transform to the nearest pixel.
 

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 std::array< float, 16 > & matrix)

Constructs a transform from a 4x4 matrix.

Parameters
matrix4x4 transform 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
nodiscard

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 std::array< float, 16 > & tgui::Transform::getMatrix ( ) const
nodiscard

Return the transform as a 4x4 matrix.

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

glLoadMatrixf(transform.getMatrix().data());
Returns
4x4 transform matrix

◆ operator*()

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

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

◆ roundPosition() [1/2]

void tgui::Transform::roundPosition ( float pixelScaleX,
float pixelScaleY )

Rounds the position stored in the transform to the nearest pixel.

Parameters
pixelScaleXPixels per point horizontally
pixelScaleYPixels per point vertically

◆ roundPosition() [2/2]

void tgui::Transform::roundPosition ( Vector2f pixelScale)

Rounds the position stored in the transform to the nearest pixel.

Parameters
pixelScalePixels per point, both horizontally and vertically

◆ 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
nodiscard

Transform a 2D point.

Parameters
pointPoint to transform
Returns
Transformed point

◆ transformRect()

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

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: