Matrix - Polkm105/DesignPatternPractice GitHub Wiki

COMPLETE

This section contains all functions relating to CP_Matrix

Table Of Contents

CP_Matrix_Set

Creates a CP_Matrix from the given values.

Function

CP_Matrix CP_Matrix_Set(float m00, float m01, float m02, 
                        float m10, float m11, float m12, 
                        float m20, float m21, float m22);

Parameters

  • mXY (float) - The 'X' corresponds to the row, the 'Y' corresponds to the column

Diagram: [m00][m01][m02] [m10][m11][m12] [m20][m21][m22]

Return

  • CP_Matrix - The matrix created from the given inputs

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
 
  // 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);
}

Related

CP_Matrix_Identity

Creates a 3x3 identity Matrix.

Function

CP_Matrix CP_Matrix_Identity();

Parameters

This function does not have any parameters

Return

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
 
  // Create transformation matrices
  CP_Matrix mat = CP_Matrix_Identity();
  mat = CP_Matrix_Multiply(mat, CP_Matrix_Rotate(25));
}

Related

CP_Matrix_FromVector

Creates a CP_Matrix by inputting each column of the matrix from the given CP_Vectors.

Function

CP_Matrix CP_Matrix_FromVector(CP_Vector col0, CP_Vector col1, CP_Vector col2);

Parameters

Return

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
  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);
}

Related

CP_Matrix_Scale

Creates a CP_Matrix used for scaling from the given CP_Vector.

Function

CP_Matrix CP_Matrix_Scale(CP_Vector scale);

Parameters

  • scale (CP_Vector) - The x and y scale that you want the matrix to hold

Return

  • CP_Matrix - A matrix that can be used to scale other matrices/vectors by the given CP_Vector amounts

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
  CP_Matrix mat = CP_Matrix_Scale(CP_Vector_Set(5, 2));
}

Related

CP_Matrix_Translate

Creates a translation Matrix using the given CP_Vector.

Function

CP_Matrix CP_Matrix_Translate(CP_Vector translation);

Parameters

  • translation (CP_Vector) - The x and y translation that you want the matrix to hold

Return

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
  CP_Matrix mat = CP_Matrix_Translate(CP_Vector_Set(20, 45));
}

Related

CP_Matrix_Rotate

Creates a rotation Matrix using the given number of degrees.

Function

CP_Matrix CP_Matrix_Rotate(float degrees);

Parameters

  • degrees (float) - The number of degrees you want to matrix to apply

Return

  • CP_Matrix - A rotation matrix using the given degrees

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
  CP_Matrix mat = CP_Matrix_Rotate(45);
}

Related

CP_Matrix_RotateRadians

Creates a rotation Matrix using the given number of radians.

Function

CP_Matrix CP_Matrix_RotateRadians(float radians);

Parameters

  • radians (float) - The number of radians you want to matrix to apply

Return

  • CP_Matrix - A rotation matrix using the given radians

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
  CP_Matrix mat = CP_Matrix_RotateRadians((float)M_PI / 2);
}

Related

CP_Matrix_Transpose

Creates a Matrix that is the transposition of the given Matrix.

Function

CP_Matrix CP_Matrix_Transpose(CP_Matrix matrix);

Parameters

Return

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
  CP_Matrix mat1 = CP_Matrix_Set(0, -1, 20, 1, 0, 10, 0, 0, 1);
  CP_Matrix transposed = CP_Matrix_Transpose(mat1);
}

Related

CP_Matrix_Inverse

Creates a Matrix that is the inverse of the given Matrix.

Function

CP_Matrix CP_Matrix_Inverse(CP_Matrix matrix);

Parameters

Return

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
  CP_Matrix mat1 = CP_Matrix_Set(0, -1, 20, 1, 0, 10, 0, 0, 1);
  CP_Matrix inveresed = CP_Matrix_Inverse(mat1);
}

Related

CP_Matrix_Multiply

Creates a Matrix that is the result of multiplying the given Matrices.

Function

CP_Matrix CP_Matrix_Multiply(CP_Matrix mat1, CP_Matrix mat2);

Parameters

Return

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
  CP_Matrix mat1 = CP_Matrix_Set(0, -1, 20, 1, 0, 10, 0, 0, 1);
  CP_Matrix inveresed = CP_Matrix_Inverse(mat1);
  CP_Matrix multiply = CP_Matrix_Multiply(mat1, inveresed); // Gives identity matrix
}

Related