GSDP:GAM100/CProcessing/applyMatrix()

From Inside
Jump to: navigation, search

applyMatrix()

Description

Multiplies the current camera transform matrix with the an input matrix.

Parameters

applyMatrix(Mat3 m)

  • m - (Mat3) The matrix to apply to the camera transform.

Example

void init()
{
  rectMode(CENTER);
  noStroke();
}

void update()
{
  // White background
  background(color(255, 255, 255, 255));

  // Reset the transform matrix
  resetMatrix();

  // The position of the rectangle we are drawing
  Vec2 position = vec2_set(canvasWidth / 2, canvasHeight / 2);

  // Create a transform matrix
  Mat3 scale = mat3_scale(vec2_set(150, 100));
  Mat3 translate = mat3_translate(position);
  Mat3 rotate = mat3_rotate_rad(QUARTER_PI);

  // Combine transfrom
  // Translate * rotation * scale
  Mat3 transform = mat3_concat(translate, mat3_concat(rotate, scale));

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

  // Draw a blue rectangle that has been transformed by the camera transform
  fill(color(0, 0, 255, 255));
  rect(0, 0, 1, 1);

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

  // Draw a red cube in the center of the screen
  fill(color(255, 0, 0, 255));
  rect(position.x, position.y, 50, 50);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>