GSDP:GAM100/CProcessing/mat3 mult vec2()

From Inside
Jump to: navigation, search

mat3_mult_vec2()

Description

Creates a Vec2 by multiplying (transforming) an input Vec2 by an input Mat3.

Parameters

mat3_mult_vec2(Mat3 mat, Vec2 vec)

  • mat - (Mat3) The transform matrix to apply to the input vector.
  • vec - (Vec2) The vector to transform with the input matrix.

Example

Vec2 end_position;
void init()
{
  end_position = vec2_set(canvasWidth / 2.0f + 80.0f, canvasHeight / 2.0f + 80.0f);
}

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

  // Create transformation matrices
  Mat3 trans = mat3_translate(vec2_set(canvasWidth / 2.0f, canvasHeight / 2.0f));
  Mat3 rotate = mat3_rotate(5.0f);

  // Combine
  Mat3 transform = mat3_concat(trans, mat3_concat(rotate, mat3_inverse(trans)));

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

  line(canvasWidth / 2.0f, canvasHeight / 2.0f, end_position.x, end_position.y);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>