get actual width of scaled shape??

edited May 2016 in Questions about Code

I'm building a small set of functions that mirror primitive shapes (rect, ellipse, line), however normalize their pixel values for sending via OSC to openFrameworks. I've set this up, so that one just puts an 'x' in front of the existing shape. Everything is going great and screenX, screenY are my best friends in making this possible.. but I'm running into strange bugs if using scale() before drawing one of these shapes... the x,y coords get corrected, but not my width/height. a sample from basic setup looks like this:

pushMatrix(); // only adjusts translate/scale within matrix translate(width/2, height/2); // suggestion to draw from center out scale(.65); xrect(0,0,250,250); popMatrix();

void xrect(float x1, float y1, float w1, float h1) { rect(x1, y1, w1, h1); String shape = "rect"; float x1out = map(screenX(x1, y1), 0, width, 0, 1); float y1out = map(screenY(x1, y1), 0, height, 0, 1); float w1out = map(w1, 0, width, 0, 1); float h1out = map(h1, 0, height, 0, 1); // .. OSC message w/ these values sent after this }

perhaps i should just be grabbing the screenX of (x1+w1) to know where that xpoint is then check the distance between those points? Wondering if there's a better way to check for transformations and know if anything's being scaled.


  • Hmm phew, seemed to have solved it by breaking down the rect params into a polyline (beginShape()..vertex()...endShape()) so that all the points get screenX/Y'ed. Now for dealing with an ellipse..?? Doesn't quite function the same way.

    Any ideas for how to convert ellipse(0,0,250,250) -> into some sort of beginShape().... endShape() set of values that can be screenX/Y'ed?

  • Slowly worked this problem out publicly... Managed to find a great formula for drawing an ellipse out of vertices for OPENGL here - allowing a very similar method I was using for the rect. Passing along vertex points, which luckily recognize all transformations.

    Perhaps this thread should be deleted, or maybe it's useful if someone else was trying to do something similar.

Sign In or Register to comment.