メイン・コンテンツまでスキップ

Matrix3x3

touchgfx/Matrix3x3.hpp

Class representing a 3x3 matrix of floats. The class is used to define affine transformations for 2D graphics.

Public Classes

structPoint
A simple struct containing coordinates.

Public Functions

Matrix3x3::PointaffineTransform(const float x, const float y) const
Do affine transformation of 2D point.
Matrix3x3::PointaffineTransform(const Matrix3x3::Point & point) const
Do affine transformation of 2D point.
FORCE_INLINE_FUNCTION floatgetElement(int row, int column) const
Get an element.
FORCE_INLINE_FUNCTION float *getElements()
Get the internal matrix elements.
Matrix3x3()
Initialize a new instance of the Matrix3x3 class.
Matrix3x3multiply(const Matrix3x3 & rhs) const
Multiply with another Matrix3x3.
Matrix3x3::PointprojectiveTransform(const Matrix3x3::Point & point) const
Do projective transformation of 2D point.
voidreset()
Reset to identity matrix.
voidrotate(float angleInDegrees)
Apply rotation transformation.
voidrotatePivot(float angleInDegrees, float x, float y)
Apply rotation around a pivot point.
voidscale(float scaleX, float scaleY)
Apply scale transformation.
voidscale(float scaleXY)
Apply scale transformation.
voidsetAffineTransformation(const float transformation[6])
Sets affine transformation from a row-major matrix.
FORCE_INLINE_FUNCTION voidsetElement(int row, int column, float value)
Set an element.
voidtranslate(float deltaX, float deltaY)
Apply translate transformation.

Public Functions Documentation

affineTransform

Matrix3x3::Point affineTransform(const floatx ,const
const floatyconst
)const

Do affine transformation of 2D point.

Affine transformation is a special case of the projective transformation, it has the same properties. However unlike projective transformation, it preserves parallelism.

The Matrix does not include the projective part (g, h, i), see below.

|x'| = |a b c| * |x| |y'| |d e f| |y| |1|

x = x coordinate of the 2D point y = y coordinate of the 2D point x' = x coordinate of the transformed 2D point y' = y coordinate of the transformed 2D point

Parameters:
xX-coordinate of the point to transform
yY-coordinate of the point to transform
Returns:

The transformed 2D point

affineTransform

Matrix3x3::Point affineTransform(const Matrix3x3::Point &point)

Do affine transformation of 2D point.

Affine transformation is a special case of the projective transformation, it has the same properties. However unlike projective transformation, it preserves parallelism.

The Matrix does not include the projective part (g, h, i), see below.

|x'| = |a b c| * |x| |y'| |d e f| |y| |1|

x = x coordinate of the 2D point y = y coordinate of the 2D point x' = x coordinate of the transformed 2D point y' = y coordinate of the transformed 2D point

Parameters:
point2D Point to transform
Returns:

The transformed 2D point

getElement

FORCE_INLINE_FUNCTION float getElement(introw ,const
intcolumnconst
)const

Get an element.

Parameters:
rowThe row (0-2).
columnThe column (0-2).
Returns:

The element.

getElements

FORCE_INLINE_FUNCTION float * getElements()

Get the internal matrix elements.

Return value Internal representation elements[0] <= elements[0][0] elements[1] <= elements[0][1] elements[2] <= elements[0][2] elements[3] <= elements[1][0] elements[4] <= elements[1][1] elements[5] <= elements[1][2] elements[6] <= elements[2][0] elements[7] <= elements[2][1] elements[8] <= elements[2][2]

Returns:

A pointer to the internal matrix elements.

Matrix3x3

Initialize a new instance of the Matrix3x3 class.

The matrix is initialized to the identity matrix.

multiply

Matrix3x3 multiply(const Matrix3x3 &rhs)

Multiply with another Matrix3x3.

Parameters:
rhsRight hand side Matrix3x3 to multiply with
Returns:

The resulting Matrix3x3

projectiveTransform

Matrix3x3::Point projectiveTransform(const Matrix3x3::Point &point)

Do projective transformation of 2D point.

Projective transformation does not preserve parallelism, length, and angle. But it still preserves collinearity and incidence.

The Matrix includes the projective part (g, h, i), see below.

|x'| |a b c| |x/w| |y'| = |d e f| * |y/w| |1 | |g h i| |1/w|

w = gx + hy + i x = x coordinate of the 2D point y = y coordinate of the 2D point x' = x coordinate of the transformed 2D point y' = y coordinate of the transformed 2D point

Parameters:
point2D Point to transform
Returns:

The transformed 2D point

reset

void reset()

Reset to identity matrix.

rotate

void rotate(floatangleInDegrees)

Apply rotation transformation.

Parameters:
angleInDegreesAngle to rotate in degrees (positive => clockwise, negative => counterclockwise)

rotatePivot

void rotatePivot(floatangleInDegrees ,
floatx ,
floaty
)

Apply rotation around a pivot point.

Parameters:
angleInDegreesAngle to rotate in degrees (positive => clockwise, negative => counterclockwise)
xX coordinate of the pivot point.
yY coordinate of the pivot point.
Note

This will overwrite the matrix elements set prior to this call.

scale

void scale(floatscaleX ,
floatscaleY
)

Apply scale transformation.

Parameters:
scaleXScale factor in the direction of X
scaleYScale factor in the direction of Y

scale

void scale(floatscaleXY)

Apply scale transformation.

Parameters:
scaleXYScale factor in the direction of both X and Y

setAffineTransformation

void setAffineTransformation(const floattransformation[6])

Sets affine transformation from a row-major matrix.

Parameters:
transformationThe transformation.

setElement

FORCE_INLINE_FUNCTION void setElement(introw ,
intcolumn ,
floatvalue
)

Set an element.

Parameters:
rowThe row.
columnThe column.
valueThe value.

translate

void translate(floatdeltaX ,
floatdeltaY
)

Apply translate transformation.

Parameters:
deltaXDelta distance in the direction of X
deltaYDelta distance in the direction of Y