tacitdynamite
YaBB Newbies
Offline
Posts: 43
NE
scale(), transform(), flipped fonts, and objects
Oct 11th , 2008, 8:32am
How can an object encapsulate coordinate transformations (such as scale and translate) so they are separate from the environment? An object should be able to request that an environment be "unscaled" or "untransformed," should it not? Here's my problem: I'm using scale and transform a lot, but I also want to have my objects label themselves without the text being backward, upsidedown, or otherwise. How can my objects request that the environment be temporarily unscaled (so my fonts don't appear upside down when I use scale(1,-1) to get a more mathematically conventional coordinate system)? I'm relatively familiar with how to use the matrix stack, but there's no way to call pushMatrix(), then resetMatrix(), then popMatrix(). Are there CoordinateManagers or something behind the scene? Here's a small example of the problem: /////////////example problem//////////// LabelBox b1; void setup() { size( 200, 200 ); background( 255 ); noLoop(); b1 = new LabelBox( 50, 50, 50, 50, 1 ); } void draw() { b1.paint(); // now with the coordinates translated and scaled // so as to be like a graphing calculator, with // with the positive y on top, the negative y on // bottom, and the origin in the middle translate( width/2, height/2 ); scale( 1, -1 ); b1.paint(); // notice how font is upside down } // example class that would need to be able // to know if scale had been called class LabelBox { PFont font; final int x, y, w, h, boxNum; LabelBox( int x, int y, int w, int h, int boxNum ) { this.x = x; this.y = y; this.w = w; this.h = h; this.boxNum = boxNum; font = createFont( "Arial", 16 ); } void paint() { textFont( font ); textAlign( CENTER, CENTER ); rectMode( CENTER ); noFill(); rect( x, y, w, h ); fill( 0 ); text( "Rect " + boxNum, x, y ); } }