Difference between revisions of "GSDP:GAM100/CProcessing/mat3 scale()"

From Inside
Jump to: navigation, search
>Zachary.logsdon
(New page: {{GSDP:GAM100API.css}} = mat3_scale() = == Description == Creates a Mat3 scale matrix from an input vector. ==== Parameters ==== mat3_scale(Vec2 scale) ...)
 
>Zachary.logsdon
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
 
= mat3_scale() =
 
= mat3_scale() =
 
== Description ==
 
== Description ==
Creates a [[GSDP:GAM100/CProcessing/Mat3|Mat3]] scale matrix from an input vector.
+
Creates a [[GSDP:GAM100/CProcessing/Mat3|Mat3]] scale matrix from an input [[GSDP:GAM100/CProcessing/Vec2|Vec2]].
  
 
==== Parameters ====
 
==== Parameters ====
 
mat3_scale(Vec2 scale)  
 
mat3_scale(Vec2 scale)  
  
*data - (unsigned char *) A pointer to a list of colors in and order like R,G,B,A,R,G,... order
+
*scale - ([[GSDP:GAM100/CProcessing/Vec2|Vec2]]) A vector containing the x and y scalars to create the matrix from.
*w - (int) The desired width of the created image.
 
*h - (int) The desired height of the created image.
 
  
 
== Example ==
 
== Example ==
 
<syntaxhighlight lang='c'>
 
<syntaxhighlight lang='c'>
PImage created;
 
 
 
void init()
 
void init()
 
{
 
{
   unsigned char colors[] = {255,0,0,255,  // Red
+
   rectMode(CENTER);
                            255,255,0,255, // Yellow
+
   noStroke();
                            0,0,255,255,  // Blue
 
                            0,255,0,255}; // Green
 
 
 
   created = createImage(colors, 2, 2);
 
 
}
 
}
  
 
void update()
 
void update()
 
{
 
{
 +
  // White background
 
   background(color(255, 255, 255, 255));
 
   background(color(255, 255, 255, 255));
   image(created, canvasWidth/2, canvasHeight/2, 100, 100, 255);
+
 
 +
   Vec2 position = vec2_set(canvasWidth / 2, canvasHeight / 2);
 +
 
 +
  // Create transform matrices
 +
  Mat3 scale = mat3_scale(vec2_set(150, 100));
 +
  Mat3 translate = mat3_translate(position);
 +
  Mat3 rotate = mat3_rotate(90.0f);
 +
 
 +
  // 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 cube at the "center" of the screen
 +
  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);
 
}
 
}
 +
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Latest revision as of 07:34, 26 June 2019

mat3_scale()

Description

Creates a Mat3 scale matrix from an input Vec2.

Parameters

mat3_scale(Vec2 scale)

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

Example

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

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

  Vec2 position = vec2_set(canvasWidth / 2, canvasHeight / 2);

  // Create transform matrices
  Mat3 scale = mat3_scale(vec2_set(150, 100));
  Mat3 translate = mat3_translate(position);
  Mat3 rotate = mat3_rotate(90.0f);

  // 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 cube at the "center" of the screen
  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:>