We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Noob question about pushMatrix/popMatrix
Page Index Toggle Pages: 1
Noob question about pushMatrix/popMatrix (Read 1114 times)
Noob question about pushMatrix/popMatrix
Apr 14th, 2009, 10:05am
 
PFont font;
String s = "VERTIGO";
float angle;

void setup() {
 size(100, 100);
 font = loadFont("AgencyFB-Reg-48.vlw");
 textFont(font, 24);
 fill(0);
}

void draw() {
 background(204);
 angle = angle + 0.02;
 pushMatrix();
 translate(33, 50);
 scale((cos(angle/4.0) + 1.2) * 2.0);
 rotate(angle);
 text(s, 0, 0);
 popMatrix();
}

Hello, the preceding code is from page 330 of the Processing book. What's the point of including pushMatrix and popMatrix in this example? I don't notice any difference when I run the code without pushMatrix and popMatrix. Is it just good form? Or is it in case the code gets more complex later on?
Re: Noob question about pushMatrix/popMatrix
Reply #1 - Apr 14th, 2009, 11:21am
 
Phattee wrote on Apr 14th, 2009, 10:05am:
Or is it in case the code gets more complex later on

Exactly! Eg. if you need to do other independent transformations on another shape.
draw() resets the matrix when exiting, so indeed, the example isn't very meaningful.
Try adding a rect(0, 0, 10, 10); after popMatrix() to see a difference.
Re: Noob question about pushMatrix/popMatrix
Reply #2 - Apr 14th, 2009, 1:15pm
 
I think the case is that in your code you are not using 3D animation,

to do this change add OPENGL or P3D in the size window.

size(100,100,OPENGL);

note you have to import the opengl library if you did not.

import processing.opengl.*;

hope this helps!

blessings!
Page Index Toggle Pages: 1