Matrix3x3
touchgfx/Matrix3x3.hpp
Class representing a 3x3 matrix of floats. The class is used to define affine transformations for 2D graphics.
Public Classes
struct | Point |
A simple struct containing coordinates. | |
Public Functions
Matrix3x3::Point | affineTransform(const float x, const float y) const |
Do affine transformation of 2D point. | |
Matrix3x3::Point | affineTransform(const Matrix3x3::Point & point) const |
Do affine transformation of 2D point. | |
FORCE_INLINE_FUNCTION float | getElement(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. | |
Matrix3x3 | multiply(const Matrix3x3 & rhs) const |
Multiply with another Matrix3x3. | |
Matrix3x3::Point | projectiveTransform(const Matrix3x3::Point & point) const |
Do projective transformation of 2D point. | |
void | reset() |
Reset to identity matrix. | |
void | rotate(float angleInDegrees) |
Apply rotation transformation. | |
void | rotatePivot(float angleInDegrees, float x, float y) |
Apply rotation around a pivot point. | |
void | scale(float scaleX, float scaleY) |
Apply scale transformation. | |
void | scale(float scaleXY) |
Apply scale transformation. | |
void | setAffineTransformation(const float transformation[6]) |
Sets affine transformation from a row-major matrix. | |
FORCE_INLINE_FUNCTION void | setElement(int row, int column, float value) |
Set an element. | |
void | translate(float deltaX, float deltaY) |
Apply translate transformation. | |
Public Functions Documentation
affineTransform
Matrix3x3::Point affineTransform | ( | const float | x , | const | |
const float | y | const | |||
) | 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
x | X-coordinate of the point to transform |
y | Y-coordinate of the point to transform |
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
point | 2D Point to transform |
The transformed 2D point
getElement
FORCE_INLINE_FUNCTION float getElement | ( | int | row , | const | |
int | column | const | |||
) | const |
Get an element.
row | The row (0-2). |
column | The column (0-2). |
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]
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
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
point | 2D Point to transform |
The transformed 2D point
reset
void reset | ( | ) |
Reset to identity matrix.
rotate
void rotate | ( | float | angleInDegrees | ) | |
Apply rotation transformation.
angleInDegrees | Angle to rotate in degrees (positive => clockwise, negative => counterclockwise) |
rotatePivot
void rotatePivot | ( | float | angleInDegrees , | ||
float | x , | ||||
float | y | ||||
) |
Apply rotation around a pivot point.
angleInDegrees | Angle to rotate in degrees (positive => clockwise, negative => counterclockwise) |
x | X coordinate of the pivot point. |
y | Y coordinate of the pivot point. |
Note
This will overwrite the matrix elements set prior to this call.
scale
void scale | ( | float | scaleX , | ||
float | scaleY | ||||
) |
Apply scale transformation.
scaleX | Scale factor in the direction of X |
scaleY | Scale factor in the direction of Y |
scale
void scale | ( | float | scaleXY | ) | |
Apply scale transformation.
scaleXY | Scale factor in the direction of both X and Y |
setAffineTransformation
void setAffineTransformation | ( | const float | transformation[6] | ) | |
Sets affine transformation from a row-major matrix.
transformation | The transformation. |
setElement
FORCE_INLINE_FUNCTION void setElement | ( | int | row , | ||
int | column , | ||||
float | value | ||||
) |
Set an element.
row | The row. |
column | The column. |
value | The value. |
translate
void translate | ( | float | deltaX , | ||
float | deltaY | ||||
) |
Apply translate transformation.
deltaX | Delta distance in the direction of X |
deltaY | Delta distance in the direction of Y |