GSDP:GAM100/CProcessing/CP Matrix Scale()

From Inside
Jump to: navigation, search

CP_Matrix_Scale()

Description

Creates a CP_Matrix scale matrix from an input CP_Vector.

Parameters

CP_Matrix_Scale(CP_Vector scale)

  • scale - (CP_Vector) A vector containing the x and y scalars to create the matrix from.

Example

void init()
{
  CP_Settings_RectMode(CP_POSITION_CENTER);
  CP_Settings_NoStroke();
}

void update()
{
  // White background
  CP_Settings_Background(CP_Color_Create(255, 255, 255, 255));

  CP_Vector position = CP_Vector_Set(CP_System_GetWindowWidth() / 2, CP_System_GetWindowHeight() / 2);

  // Create transform matrices
  CP_Matrix scale = CP_Matrix_Scale(vec2_set(150, 100));
  CP_Matrix translate = CP_Matrix_Translate(position);
  CP_Matrix rotate = CP_Matrix_Rotate(90.0f);

  // Combine transfrom
  // Translate * rotation * scale
  CP_Matrix transform = CP_Matrix_Multiply(translate, CP_Matrix_Multiply(rotate, scale));

  // Set the camera transfrom to the created matrix
  CP_Settings_ApplyMatrix(transform);

  // Draw a blue cube at the "center" of the screen
  CP_Settings_Fill(CP_Color_Create(0, 0, 255, 255));
  CP_Graphics_DrawRect(0, 0, 1, 1);

  // Reset the matrix to the identity matrix
  CP_Settings_ResetMatrix();

  // Draw a red cube in the center of the screen
  CP_Settings_Fill(CP_Color_Create(255, 0, 0, 255));
  CP_Graphics_DrawRect(position.x, position.y, 50, 50);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>