Bug 589 : Java2D renderer should have a modelX and modelY implementation
Last modified: 2007-07-06 20:55




Status:
RESOLVED
Resolution:
INVALID -
Priority:
P2
Severity:
normal

 

Reporter:
gjuggler
Assigned To:
fry

Attachment Type Created Size Actions
Proposed implementation of modelX and modelY for Java2D renderer. text/plain 2007-06-28 08:17 39.35 KB

Description:   Opened: 2007-06-28 08:16
It seems a bit silly that the Java2D renderer has an implementation of the
screenX and screenY functions but not modelX and modelY. Without this,
there is no easy way to find where in the "model" space the current mouse
point is.

I've quickly drawn together a possible fix, which I'll attach to this
report. It's all within the PgraphicsJava2D class, and I've inserted "BEGIN
GJ_MOD" and "END_GJ_MOD" where I've modified the code.

With this in place, converting between screen and model coordinates will
become much easier and much more consistent.

--greg
Additional Comment #1 From gjuggler 2007-06-28 08:17
edit]
Proposed implementation of modelX and modelY for Java2D renderer.

PGraphicsJava2D with modelX and modelY implementation. All changes occur within
the loadMatrix() function and within the new modelX and modelY functions.
Additional Comment #2 From gjuggler 2007-06-28 08:54
(From update of edit])

public void loadMatrix() {
g2.getTransform().getMatrix(transform);

m00 = (float) transform[0];
m01 = (float) transform[2];
m02 = (float) transform[4];

m10 = (float) transform[1];
m11 = (float) transform[3];
m12 = (float) transform[5];

// Begin GJ_MOD
try {
AffineTransform tr = g2.getTransform();
tr.invert();
tr.getMatrix(inverseTransform);
} catch (NoninvertibleTransformException e) {
}
// End GJ_MOD

}

public float screenX(float x, float y) {
loadMatrix();
return super.screenX(x, y);
//g2.getTransform().getMatrix(transform);
//return (float)transform[0]*x + (float)transform[2]*y +
(float)transform[4];
}


public float screenY(float x, float y) {
loadMatrix();
return super.screenY(x, y);
//g2.getTransform().getMatrix(transform);
//return (float)transform[1]*x + (float)transform[3]*y +
(float)transform[5];
}

// BEGIN GJ_MOD
public float modelX(float x, float y, float z) {
loadMatrix();
return (float) (x*inverseTransform[0] + y*inverseTransform[2] +
inverseTransform[4]);
}

public float modelY(float x, float y, float z) {
loadMatrix();
return (float) (y*inverseTransform[1] + y*inverseTransform[3] +
inverseTransform[5]);
}

// END GJ_MOD

Additional Comment #3 From gjuggler 2007-06-28 08:56
Not sure if I'm using the correct indices from the double array returned by
AffineTransform.getMatrix(), but hopefully this gets across my point!

--greg

(In reply to comment #2)
>
>
>
> Additional Comment #2 From
>
> gjuggler
> 2007-06-28 08:54
>
> <!--
> addReplyLink(2); //-->[reply]
>
>
>
>
> (From update of edit] [edit])
>
> public void loadMatrix() {
> g2.getTransform().getMatrix(transform);
>
> m00 = (float) transform[0];
> m01 = (float) transform[2];
> m02 = (float) transform[4];
>
> m10 = (float) transform[1];
> m11 = (float) transform[3];
> m12 = (float) transform[5];
>
> // Begin GJ_MOD
> try {
> AffineTransform tr = g2.getTransform();
> tr.invert();
> tr.getMatrix(inverseTransform);
> } catch (NoninvertibleTransformException e) {
> }
> // End GJ_MOD
>
> }
>
> public float screenX(float x, float y) {
> loadMatrix();
> return super.screenX(x, y);
> //g2.getTransform().getMatrix(transform);
> //return (float)transform[0]*x + (float)transform[2]*y +
> (float)transform[4];
> }
>
>
> public float screenY(float x, float y) {
> loadMatrix();
> return super.screenY(x, y);
> //g2.getTransform().getMatrix(transform);
> //return (float)transform[1]*x + (float)transform[3]*y +
> (float)transform[5];
> }
>
> // BEGIN GJ_MOD
> public float modelX(float x, float y, float z) {
> loadMatrix();
> return (float) (x*inverseTransform[0] + y*inverseTransform[2] +
> inverseTransform[4]);
> }
>
> public float modelY(float x, float y, float z) {
> loadMatrix();
> return (float) (y*inverseTransform[1] + y*inverseTransform[3] +
> inverseTransform[5]);
> }
>
> // END GJ_MOD
>
>
>
>

Additional Comment #4 From fry 2007-07-06 20:55
i think you're misunderstanding what modelX and modelY do. they don't
perform an inverse transform, they provide the coordinates after
transformation of points in camera space. there's no camera in 2D, and thus
no modelXYZ implementation in the 2D renderers.