GSDP:GAM100/CProcessing/CP Matrix FromVector()

CP_Matrix_FromVector()

Description

Create a CP_Matrix by inputting each column of the matrix as CP_Vectors.

Parameters

CP_Matrix_FromVector(CP_Vector col1, CP_Vector col2, CP_Vector col3)

  • colX - (CP_Vector) Each is used to make column X when constructing the matrix.

Example

CP_Vector end_position;
void init()
{
  end_position = CP_Vector_Set(CP_System_GetWindowWidth() / 2.0f + 80.0f, CP_System_GetWindowHeight() / 2.0f + 80.0f);
}

void update()
{
  CP_Settings_Background(CP_Color_Create(255, 255, 255, 255));

  // Create transformation matrices
  CP_Matrix trans = CP_Matrix_FromVector(CP_Vector_Set(1.0f, 0.0f), 
                                         CP_Vector_Set(0.0f, 1.0f), 
                                         CP_Vector_Set(CP_System_GetWindowWidth() / 2.0f, CP_System_GetWindowHeight() / 2.0f));

  CP_Matrix rotate = CP_Matrix_Rotate(5.0f);

  // Combine
  CP_Matrix transform = CP_Matrix_Multiply(trans, CP_Matrix_Multiply(rotate, CP_Matrix_Inverse(trans)));

  // Update the end point of the line
  end_position = CP_Vector_MatrixMultiply(transform, end_position);

  CP_Graphics_DrawLine(CP_System_GetWindowWidth() / 2.0f, CP_System_GetWindowHeight() / 2.0f, end_position.x, end_position.y);
}

Related