Looking good!
If you're using JAVA2D, you can get the underlying Graphics2D object, which contains an AffineTransform, which has all of the transformation info. You'll want to a) cast the generic PGraphics instance (simply called 'g') into a PGraphicsJava2D, b) access the Graphics2D object (called 'g2'), c) access the AffineTransform object (with the 'getTransform()' method), and then use one of the transform() methods. It's not as complicated as it sounds:
- import java.awt.geom.*;
- import java.awt.*;
- void setup() {
- size(500, 500, JAVA2D);
- }
- void draw() {
- background(255);
- translate(frameCount/5, frameCount/5);
- rotate(millis() / 1000f);
- Point2D.Float end = new Point2D.Float(100, 0); //I'm using the java.awt.geom.Point2D class because that's what AffineTransform.transform expects
- line(0, 0, end.x, end.y);
-
- Graphics2D g2d = ((PGraphicsJava2D)g).g2; //Get the java.awt.Graphics2D instance
- AffineTransform tx = g2d.getTransform(); //get the transform
- Point2D.Float coords = (Point2D.Float) tx.transform(end, null); //apply the transform onto our point
- resetMatrix(); //Reset the drawing coordinate
- fill(0);
- text(coords.x+", "+coords.y, coords.x, coords.y); //show the coordinates
- }
There's something similar for P2D that involves using the PMatrix class; I'd suggest looking at the Processing source code. In fact, whatever you're looking to do, try looking at the source code if possible. It'll teach you a lot.