-
Notifications
You must be signed in to change notification settings - Fork 0
Matrix
This section contains all functions relating to CP_Matrix.
- CP_Matrix_Set
- CP_Matrix_Identity
- CP_Matrix_FromVector
- CP_Matrix_Scale
- CP_Matrix_Translate
- CP_Matrix_Rotate
- CP_Matrix_RotateRadians
- CP_Matrix_Transpose
- CP_Matrix_Inverse
- CP_Matrix_Multiply
Creates a CP_Matrix from the given values.
CP_Matrix CP_Matrix_Set(float m00, float m01, float m02,
float m10, float m11, float m12,
float m20, float m21, float m22);
- mXY (float) - The 'X' corresponds to the row, the 'Y' corresponds to the column.
Diagram: [m00][m01][m02] [m10][m11][m12] [m20][m21][m22]
- CP_Matrix - The matrix created from the given inputs.
void update()
{
// Create transformation matrices
CP_Matrix trans = CP_Matrix_Set(1.0f, 0, CP_System_GetWindowWidth() / 2.0f,
0, 1.0f, CP_System_GetWindowHeight() / 2.0f,
0, 0, 1.0f);
}
Creates a CP_Matrix which is a 3x3 identity matrix.
CP_Matrix CP_Matrix_Identity();
This function does not have any parameters
- CP_Matrix - A 3x3 identity matrix.
void update()
{
// Create transformation matrices
CP_Matrix mat = CP_Matrix_Identity();
mat = CP_Matrix_Multiply(mat, CP_Matrix_Rotate(25));
}
Creates a CP_Matrix by inputting each column of the matrix from the given CP_Vector variables. The bottom row of the matrix will be set to (0, 0, 1).
CP_Matrix CP_Matrix_FromVector(CP_Vector col0, CP_Vector col1, CP_Vector col2);
- col0 (CP_Vector) - The first column in the matrix.
- col1 (CP_Vector) - The second column in the matrix.
- col2 (CP_Vector) - The third column in the matrix.
void update()
{
CP_Vector col1 = CP_Vector_Set(0, 1);
CP_Vector col2 = CP_Vector_Set(-1, 0);
CP_Vector col3 = CP_Vector_Set(45, 20);
// Create transformation matrices
CP_Matrix mat = CP_Matrix_FromVector(col1, col2, col3);
}
Creates a CP_Matrix used for scaling from the given CP_Vector.
CP_Matrix CP_Matrix_Scale(CP_Vector scale);
- scale (CP_Vector) - The x and y scale that you want the matrix to hold.
- CP_Matrix - A matrix that can be used to scale other matrices/vectors by the given amounts.
void update()
{
CP_Matrix mat = CP_Matrix_Scale(CP_Vector_Set(5, 2));
}
Creates a translation CP_Matrix using the given CP_Vector.
CP_Matrix CP_Matrix_Translate(CP_Vector translation);
- translation (CP_Vector) - The x and y translation that you want the matrix to hold.
- CP_Matrix - A translation matrix using the given values.
void update()
{
CP_Matrix mat = CP_Matrix_Translate(CP_Vector_Set(20, 45));
}
Creates a rotation CP_Matrix using the given angle in degrees.
CP_Matrix CP_Matrix_Rotate(float degrees);
- degrees (float) - The number of degrees of rotation you want to matrix to apply.
- CP_Matrix - A rotation matrix using the given angle.
void update()
{
CP_Matrix mat = CP_Matrix_Rotate(45);
}
Creates a rotation CP_Matrix using the given angle in radians.
CP_Matrix CP_Matrix_RotateRadians(float radians);
- radians (float) - The rotation angle in radians you want to matrix to apply.
- CP_Matrix - A rotation matrix using the given angle.
void update()
{
CP_Matrix mat = CP_Matrix_RotateRadians((float)M_PI / 2);
}
Creates a CP_Matrix that is the transposition of the given CP_Matrix.
CP_Matrix CP_Matrix_Transpose(CP_Matrix matrix);
- matrix (CP_Matrix) - The matrix you want to transpose.
- CP_Matrix - The transposition of the given matrix.
void update()
{
CP_Matrix mat1 = CP_Matrix_Set(0, -1, 20, 1, 0, 10, 0, 0, 1);
CP_Matrix transposed = CP_Matrix_Transpose(mat1);
}
Creates a CP_Matrix that is the inverse of the given CP_Matrix.
CP_Matrix CP_Matrix_Inverse(CP_Matrix matrix);
- matrix (CP_Matrix) - The matrix you want to inverse.
- CP_Matrix - The inverse of the given matrix.
void update()
{
CP_Matrix mat1 = CP_Matrix_Set(0, -1, 20, 1, 0, 10, 0, 0, 1);
CP_Matrix inveresed = CP_Matrix_Inverse(mat1);
}
Creates a new CP_Matrix that is the result of multiplying the given matrices.
CP_Matrix CP_Matrix_Multiply(CP_Matrix mat1, CP_Matrix mat2);
- mat1 (CP_Matrix) - The matrix on the left of the multiplication.
- mat2 (CP_Matrix) - The matrix on the right side of the multiplication.
- CP_Matrix - The result of mat1 * mat2.
void update()
{
CP_Matrix mat1 = CP_Matrix_Set(0, -1, 20, 1, 0, 10, 0, 0, 1);
CP_Matrix inversed = CP_Matrix_Inverse(mat1);
CP_Matrix multiply = CP_Matrix_Multiply(mat1, inversed); // Gives identity matrix
}