kzc_matrix3x3.hpp File Reference

Matrix3x3 structure and operations. More...

Classes

struct  KzcMatrix3x3
 Structure for 3x3 matrix. More...
 

Macros

#define KZC_MATRIX3X3_INDEX_AXISX_X
 Matrix index for coordinate X of X axis. More...
 
#define KZC_MATRIX3X3_INDEX_AXISX_Y
 Matrix index for coordinate Y of X axis. More...
 
#define KZC_MATRIX3X3_INDEX_AXISX_Z
 Matrix index for coordinate Z of X axis. More...
 
#define KZC_MATRIX3X3_INDEX_AXISY_X
 Matrix index for coordinate X of Y axis. More...
 
#define KZC_MATRIX3X3_INDEX_AXISY_Y
 Matrix index for coordinate Y of Y axis. More...
 
#define KZC_MATRIX3X3_INDEX_AXISY_Z
 Matrix index for coordinate Z of Y axis. More...
 
#define KZC_MATRIX3X3_INDEX_AXISZ_X
 Matrix index for coordinate X of Z axis. More...
 
#define KZC_MATRIX3X3_INDEX_AXISZ_Y
 Matrix index for coordinate Y of Z axis. More...
 
#define KZC_MATRIX3X3_INDEX_AXISZ_Z
 Matrix index for coordinate Z of Z axis. More...
 
#define KZC_MATRIX3X3_INDEX_TRANSLATION_X
 Matrix index for X translation. More...
 
#define KZC_MATRIX3X3_INDEX_TRANSLATION_Y
 Matrix index for Y translation. More...
 

Functions

KZ_INLINE struct KzcMatrix3x3 kzcMatrix3x3 (kzFloat a11, kzFloat a12, kzFloat a13, kzFloat a21, kzFloat a22, kzFloat a23, kzFloat a31, kzFloat a32, kzFloat a33)
 Creates a matrix with given values. More...
 
void kzcMatrix3x3Copy (const struct KzcMatrix3x3 *sourceMatrix, struct KzcMatrix3x3 *targetMatrix)
 Create a copy of matrix. More...
 
void kzcMatrix3x3SetIdentity (struct KzcMatrix3x3 *matrix)
 Sets an identity matrix. More...
 
void kzcMatrix3x3SetInvalid (struct KzcMatrix3x3 *matrix)
 Sets an invalid matrix filled with NaNs. More...
 
void kzcMatrix3x3SetIdentity2x2 (struct KzcMatrix3x3 *matrix)
 Sets a 3x3 matrix top left 2x2 part as identity. More...
 
void kzcMatrix3x3ResetTranslation (struct KzcMatrix3x3 *matrix)
 Sets a 3x3 matrix translation columns to zero. More...
 
void kzcMatrix3x3SetTranslation (struct KzcMatrix3x3 *matrix, kzFloat translateX, kzFloat translateY)
 Creates a 3x3 translation matrix. More...
 
void kzcMatrix3x3Transpose (const struct KzcMatrix3x3 *matrix, struct KzcMatrix3x3 *out_matrix)
 Applies a transpose to a matrix. More...
 
kzBool kzcMatrix3x3InverseAffine (const struct KzcMatrix3x3 *matrix, struct KzcMatrix3x3 *out_matrix)
 Applies an inversion to an affine matrix. More...
 
void kzcMatrix3x3Translate (struct KzcMatrix3x3 *matrix, kzFloat x, kzFloat y)
 Translates matrix by given vector2 in matrix's base. More...
 
void kzcMatrix3x3TranslateVector2 (struct KzcMatrix3x3 *matrix, const struct KzcVector2 *translation)
 Translates matrix by given vector2 in matrix's base. More...
 
void kzcMatrix3x3Rotate (struct KzcMatrix3x3 *matrix, kzFloat angleInRadians)
 Multiplies matrix from right by a rotation matrix, angle is in radians. More...
 
void kzcMatrix3x3SetRotation (struct KzcMatrix3x3 *matrix, kzFloat angleInRadians)
 Creates a 3x3 rotation matrix from rotation angle in radians. More...
 
kzFloat kzcMatrix3x3GetRotation (const struct KzcMatrix3x3 *matrix)
 Get the rotation (over imaginary Z axis) of given matrix in radians. More...
 
KZ_INLINE void kzcMatrix3x3RotateInDegrees (struct KzcMatrix3x3 *matrix, kzFloat angleInDegrees)
 Multiplies matrix from right by a rotation matrix, angle is in degrees. More...
 
KZ_INLINE void kzcMatrix3x3SetRotationInDegrees (struct KzcMatrix3x3 *matrix, kzFloat angleInDegrees)
 Creates a 3x3 rotation matrix from rotation angle in degrees. More...
 
KZ_INLINE kzFloat kzcMatrix3x3GetRotationInDegrees (const struct KzcMatrix3x3 *matrix)
 Get the rotation (over imaginary Z axis) of given matrix in degrees. More...
 
void kzcMatrix3x3ScaleUniform (struct KzcMatrix3x3 *matrix, kzFloat scale)
 Applies a uniform scaling to a matrix. More...
 
void kzcMatrix3x3Scale (struct KzcMatrix3x3 *matrix, kzFloat scaleX, kzFloat scaleY)
 Applies a scaling for a matrix. More...
 
kzFloat kzcMatrix3x3GetScaleX (const struct KzcMatrix3x3 *matrix)
 Gets scaling factor from matrix for its X axis. More...
 
kzFloat kzcMatrix3x3GetScaleY (const struct KzcMatrix3x3 *matrix)
 Gets scaling factor from matrix for its Y axis. More...
 
void kzcMatrix3x3ScaleX (struct KzcMatrix3x3 *matrix, kzFloat scale)
 Applies a scaling for a matrix on axis X. More...
 
void kzcMatrix3x3ScaleY (struct KzcMatrix3x3 *matrix, kzFloat scale)
 Applies a scaling for a matrix on axis Y. More...
 
void kzcMatrix3x3Normalize (const struct KzcMatrix3x3 *matrix, struct KzcMatrix3x3 *out_matrix)
 Normalizes the given matrix, result in out_matrix. More...
 
void kzcMatrix3x3Multiply (const struct KzcMatrix3x3 *matrix1, const struct KzcMatrix3x3 *matrix2, struct KzcMatrix3x3 *out_matrix)
 Multiplies two matrices. More...
 
void kzcMatrix3x3MultiplyVector2 (const struct KzcMatrix3x3 *matrix, const struct KzcVector2 *vector, struct KzcVector2 *out_vector)
 Multiplies matrix and vector2 defined as vea33(vector2.xy, 1.0). More...
 
void kzcMatrix3x3MultiplyVector2By2x2 (const struct KzcMatrix3x3 *matrix, const struct KzcVector2 *vector, struct KzcVector2 *out_vector)
 Multiplies matrix and vector2. More...
 
void kzcMatrix3x3MultiplyVector3 (const struct KzcMatrix3x3 *matrix, const struct KzcVector3 *vector, struct KzcVector3 *out_vector)
 Multiplies matrix and vector3. More...
 
kzBool kzcMatrix3x3IsScalingOnly (const struct KzcMatrix3x3 *matrix)
 Check if the matrix transformation is scaling-only. More...
 
kzBool kzcMatrix3x3IsTranslationOnly (const struct KzcMatrix3x3 *matrix)
 Check if the matrix transformation is translation-only. More...
 
void kzcMatrix3x3CreateSRT (struct KzcMatrix3x3 *matrix, kzFloat scaleX, kzFloat scaleY, kzFloat rotationAngleInRadians, kzFloat translateX, kzFloat translateY)
 Creates matrix from scale, rotation and translation. More...
 
void kzcMatrix3x3GetSRT (const struct KzcMatrix3x3 *matrix, struct KzcVector2 *out_scale, kzFloat *out_rotationAngleInRadians, struct KzcVector2 *out_translate)
 Gets the matrix SRT values, rotation angle in radians. More...
 
KZ_INLINE void kzcMatrix3x3CreateSRTInDegrees (struct KzcMatrix3x3 *matrix, kzFloat scaleX, kzFloat scaleY, kzFloat rotationAngleInDegrees, kzFloat translateX, kzFloat translateY)
 Creates matrix from scale, rotation and translation. More...
 
KZ_INLINE void kzcMatrix3x3GetSRTInDegrees (const struct KzcMatrix3x3 *matrix, struct KzcVector2 *out_scale, kzFloat *out_rotationAngleInDegrees, struct KzcVector2 *out_translate)
 Gets the matrix SRT values, rotation angle in degrees. More...
 
KZ_INLINE void kzcMatrix3x3GetAxisX (const struct KzcMatrix3x3 *matrix, struct KzcVector3 *out_axis)
 Returns the X axis vector of the matrix. More...
 
KZ_INLINE void kzcMatrix3x3GetAxisY (const struct KzcMatrix3x3 *matrix, struct KzcVector3 *out_axis)
 Returns the Y axis vector of the matrix. More...
 
KZ_INLINE void kzcMatrix3x3GetAxisZ (const struct KzcMatrix3x3 *matrix, struct KzcVector3 *out_axis)
 Returns the Z axis vector of the matrix. More...
 
KZ_INLINE void kzcMatrix3x3GetTranslation (const struct KzcMatrix3x3 *matrix, struct KzcVector2 *out_translation)
 Returns the translation vector of the matrix. More...
 
KZ_INLINE void kzcMatrix3x3SetAxisXVector3 (struct KzcMatrix3x3 *matrix, const struct KzcVector3 *axis)
 Sets the X axis vector of the matrix. More...
 
KZ_INLINE void kzcMatrix3x3SetAxisYVector3 (struct KzcMatrix3x3 *matrix, const struct KzcVector3 *axis)
 Sets the Y axis vector of the matrix. More...
 
KZ_INLINE void kzcMatrix3x3SetAxisZVector3 (struct KzcMatrix3x3 *matrix, const struct KzcVector3 *axis)
 Sets the Z axis vector of the matrix. More...
 
KZ_INLINE void kzcMatrix3x3SetTranslationVector2 (struct KzcMatrix3x3 *matrix, const struct KzcVector2 *translation)
 Sets the translation vector of the matrix. More...
 
kzFloat kzcMatrix3x3Determinant (const struct KzcMatrix3x3 *matrix)
 Calculates the determinant of the matrix. More...
 
kzFloat kzcMatrix3x3Trace (const struct KzcMatrix3x3 *matrix)
 Returns matrix's trace. More...
 
KZ_INLINE kzBool kzcMatrix3x3IsEqual (const struct KzcMatrix3x3 *matrixA, const struct KzcMatrix3x3 *matrixB)
 Compares 2 matrices if they are equal. More...
 

Variables

KANZI_API const struct KzcMatrix3x3 KZC_MATRIX3X3_IDENTITY
 Constant for identity matrix. More...
 

Detailed Description

Matrix3x3 structure and operations.

Copyright 2008-2017 by Rightware. All rights reserved.

Macro Definition Documentation

#define KZC_MATRIX3X3_INDEX_AXISX_X

Matrix index for coordinate X of X axis.

#define KZC_MATRIX3X3_INDEX_AXISX_Y

Matrix index for coordinate Y of X axis.

#define KZC_MATRIX3X3_INDEX_AXISX_Z

Matrix index for coordinate Z of X axis.

#define KZC_MATRIX3X3_INDEX_AXISY_X

Matrix index for coordinate X of Y axis.

#define KZC_MATRIX3X3_INDEX_AXISY_Y

Matrix index for coordinate Y of Y axis.

#define KZC_MATRIX3X3_INDEX_AXISY_Z

Matrix index for coordinate Z of Y axis.

#define KZC_MATRIX3X3_INDEX_AXISZ_X

Matrix index for coordinate X of Z axis.

#define KZC_MATRIX3X3_INDEX_AXISZ_Y

Matrix index for coordinate Y of Z axis.

#define KZC_MATRIX3X3_INDEX_AXISZ_Z

Matrix index for coordinate Z of Z axis.

#define KZC_MATRIX3X3_INDEX_TRANSLATION_X

Matrix index for X translation.

#define KZC_MATRIX3X3_INDEX_TRANSLATION_Y

Matrix index for Y translation.

Function Documentation

KZ_INLINE struct KzcMatrix3x3 kzcMatrix3x3 ( kzFloat  a11,
kzFloat  a12,
kzFloat  a13,
kzFloat  a21,
kzFloat  a22,
kzFloat  a23,
kzFloat  a31,
kzFloat  a32,
kzFloat  a33 
)

Creates a matrix with given values.

Note that because matrices are internally represented as column-major instead of the scientific row-major notation, matrix specified in using this function actually looks like a transpose of itself in code.

void kzcMatrix3x3Copy ( const struct KzcMatrix3x3 sourceMatrix,
struct KzcMatrix3x3 targetMatrix 
)

Create a copy of matrix.

void kzcMatrix3x3SetIdentity ( struct KzcMatrix3x3 matrix)

Sets an identity matrix.

void kzcMatrix3x3SetInvalid ( struct KzcMatrix3x3 matrix)

Sets an invalid matrix filled with NaNs.

void kzcMatrix3x3SetIdentity2x2 ( struct KzcMatrix3x3 matrix)

Sets a 3x3 matrix top left 2x2 part as identity.

void kzcMatrix3x3ResetTranslation ( struct KzcMatrix3x3 matrix)

Sets a 3x3 matrix translation columns to zero.

void kzcMatrix3x3SetTranslation ( struct KzcMatrix3x3 matrix,
kzFloat  translateX,
kzFloat  translateY 
)

Creates a 3x3 translation matrix.

void kzcMatrix3x3Transpose ( const struct KzcMatrix3x3 matrix,
struct KzcMatrix3x3 out_matrix 
)

Applies a transpose to a matrix.

out_matrix cannot be same as input matrix.

kzBool kzcMatrix3x3InverseAffine ( const struct KzcMatrix3x3 matrix,
struct KzcMatrix3x3 out_matrix 
)

Applies an inversion to an affine matrix.

out_matrix cannot be same as input matrix. Returns KZ_TRUE if the matrix was invertible, KZ_FALSE otherwise.

void kzcMatrix3x3Translate ( struct KzcMatrix3x3 matrix,
kzFloat  x,
kzFloat  y 
)

Translates matrix by given vector2 in matrix's base.

i.e. kzcMatrix3x3Translate(matrix M, vector T) adds M * T to the translation part of the matrix.

void kzcMatrix3x3TranslateVector2 ( struct KzcMatrix3x3 matrix,
const struct KzcVector2 translation 
)

Translates matrix by given vector2 in matrix's base.

i.e. kzcMatrix3x3Translate(matrix M, vector T) adds M * T to the translation part of the matrix.

void kzcMatrix3x3Rotate ( struct KzcMatrix3x3 matrix,
kzFloat  angleInRadians 
)

Multiplies matrix from right by a rotation matrix, angle is in radians.

void kzcMatrix3x3SetRotation ( struct KzcMatrix3x3 matrix,
kzFloat  angleInRadians 
)

Creates a 3x3 rotation matrix from rotation angle in radians.

kzFloat kzcMatrix3x3GetRotation ( const struct KzcMatrix3x3 matrix)

Get the rotation (over imaginary Z axis) of given matrix in radians.

KZ_INLINE void kzcMatrix3x3RotateInDegrees ( struct KzcMatrix3x3 matrix,
kzFloat  angleInDegrees 
)

Multiplies matrix from right by a rotation matrix, angle is in degrees.

KZ_INLINE void kzcMatrix3x3SetRotationInDegrees ( struct KzcMatrix3x3 matrix,
kzFloat  angleInDegrees 
)

Creates a 3x3 rotation matrix from rotation angle in degrees.

KZ_INLINE kzFloat kzcMatrix3x3GetRotationInDegrees ( const struct KzcMatrix3x3 matrix)

Get the rotation (over imaginary Z axis) of given matrix in degrees.

void kzcMatrix3x3ScaleUniform ( struct KzcMatrix3x3 matrix,
kzFloat  scale 
)

Applies a uniform scaling to a matrix.

void kzcMatrix3x3Scale ( struct KzcMatrix3x3 matrix,
kzFloat  scaleX,
kzFloat  scaleY 
)

Applies a scaling for a matrix.

kzFloat kzcMatrix3x3GetScaleX ( const struct KzcMatrix3x3 matrix)

Gets scaling factor from matrix for its X axis.

Assumes an affine matrix.

kzFloat kzcMatrix3x3GetScaleY ( const struct KzcMatrix3x3 matrix)

Gets scaling factor from matrix for its Y axis.

Assumes an affine matrix.

void kzcMatrix3x3ScaleX ( struct KzcMatrix3x3 matrix,
kzFloat  scale 
)

Applies a scaling for a matrix on axis X.

void kzcMatrix3x3ScaleY ( struct KzcMatrix3x3 matrix,
kzFloat  scale 
)

Applies a scaling for a matrix on axis Y.

void kzcMatrix3x3Normalize ( const struct KzcMatrix3x3 matrix,
struct KzcMatrix3x3 out_matrix 
)

Normalizes the given matrix, result in out_matrix.

The matrix must be an affine transformation.

void kzcMatrix3x3Multiply ( const struct KzcMatrix3x3 matrix1,
const struct KzcMatrix3x3 matrix2,
struct KzcMatrix3x3 out_matrix 
)

Multiplies two matrices.

The result, product 'matrix1' * 'matrix2', is set to out_matrix. out_matrix cannot be any of the input matrices.

void kzcMatrix3x3MultiplyVector2 ( const struct KzcMatrix3x3 matrix,
const struct KzcVector2 vector,
struct KzcVector2 out_vector 
)

Multiplies matrix and vector2 defined as vea33(vector2.xy, 1.0).

out_vector cannot be same as input vector.

void kzcMatrix3x3MultiplyVector2By2x2 ( const struct KzcMatrix3x3 matrix,
const struct KzcVector2 vector,
struct KzcVector2 out_vector 
)

Multiplies matrix and vector2.

Translation component of matrix is ignored. out_vector cannot be same as input vector.

void kzcMatrix3x3MultiplyVector3 ( const struct KzcMatrix3x3 matrix,
const struct KzcVector3 vector,
struct KzcVector3 out_vector 
)

Multiplies matrix and vector3.

out_vector cannot be same as input vector.

kzBool kzcMatrix3x3IsScalingOnly ( const struct KzcMatrix3x3 matrix)

Check if the matrix transformation is scaling-only.

kzBool kzcMatrix3x3IsTranslationOnly ( const struct KzcMatrix3x3 matrix)

Check if the matrix transformation is translation-only.

This is a subset of scaling-only.

void kzcMatrix3x3CreateSRT ( struct KzcMatrix3x3 matrix,
kzFloat  scaleX,
kzFloat  scaleY,
kzFloat  rotationAngleInRadians,
kzFloat  translateX,
kzFloat  translateY 
)

Creates matrix from scale, rotation and translation.

Rotation angle in radians.

void kzcMatrix3x3GetSRT ( const struct KzcMatrix3x3 matrix,
struct KzcVector2 out_scale,
kzFloat out_rotationAngleInRadians,
struct KzcVector2 out_translate 
)

Gets the matrix SRT values, rotation angle in radians.

KZ_INLINE void kzcMatrix3x3CreateSRTInDegrees ( struct KzcMatrix3x3 matrix,
kzFloat  scaleX,
kzFloat  scaleY,
kzFloat  rotationAngleInDegrees,
kzFloat  translateX,
kzFloat  translateY 
)

Creates matrix from scale, rotation and translation.

Rotation angle in degrees.

KZ_INLINE void kzcMatrix3x3GetSRTInDegrees ( const struct KzcMatrix3x3 matrix,
struct KzcVector2 out_scale,
kzFloat out_rotationAngleInDegrees,
struct KzcVector2 out_translate 
)

Gets the matrix SRT values, rotation angle in degrees.

KZ_INLINE void kzcMatrix3x3GetAxisX ( const struct KzcMatrix3x3 matrix,
struct KzcVector3 out_axis 
)

Returns the X axis vector of the matrix.

KZ_INLINE void kzcMatrix3x3GetAxisY ( const struct KzcMatrix3x3 matrix,
struct KzcVector3 out_axis 
)

Returns the Y axis vector of the matrix.

KZ_INLINE void kzcMatrix3x3GetAxisZ ( const struct KzcMatrix3x3 matrix,
struct KzcVector3 out_axis 
)

Returns the Z axis vector of the matrix.

KZ_INLINE void kzcMatrix3x3GetTranslation ( const struct KzcMatrix3x3 matrix,
struct KzcVector2 out_translation 
)

Returns the translation vector of the matrix.

KZ_INLINE void kzcMatrix3x3SetAxisXVector3 ( struct KzcMatrix3x3 matrix,
const struct KzcVector3 axis 
)

Sets the X axis vector of the matrix.

KZ_INLINE void kzcMatrix3x3SetAxisYVector3 ( struct KzcMatrix3x3 matrix,
const struct KzcVector3 axis 
)

Sets the Y axis vector of the matrix.

KZ_INLINE void kzcMatrix3x3SetAxisZVector3 ( struct KzcMatrix3x3 matrix,
const struct KzcVector3 axis 
)

Sets the Z axis vector of the matrix.

KZ_INLINE void kzcMatrix3x3SetTranslationVector2 ( struct KzcMatrix3x3 matrix,
const struct KzcVector2 translation 
)

Sets the translation vector of the matrix.

kzFloat kzcMatrix3x3Determinant ( const struct KzcMatrix3x3 matrix)

Calculates the determinant of the matrix.

kzFloat kzcMatrix3x3Trace ( const struct KzcMatrix3x3 matrix)

Returns matrix's trace.

KZ_INLINE kzBool kzcMatrix3x3IsEqual ( const struct KzcMatrix3x3 matrixA,
const struct KzcMatrix3x3 matrixB 
)

Compares 2 matrices if they are equal.

Variable Documentation

KANZI_API const struct KzcMatrix3x3 KZC_MATRIX3X3_IDENTITY

Constant for identity matrix.