diff options
author | Sven Gothel <[email protected]> | 2023-03-19 15:34:24 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-03-19 15:34:24 +0100 |
commit | 01d35625f848ed3a97fae750ff2e8928f9d6538a (patch) | |
tree | 8688e14c313db83d0cfff1aa24ecd4ff876ea55d /src | |
parent | 8eb70fb10a4f81c93dbc4ed12571a67ffbc1649a (diff) |
GraphUI Shape win<->obj/shape mapping: Return actual int[] or float[] result or null on error instead of boolean to easy API usage
Diffstat (limited to 'src')
8 files changed, 152 insertions, 120 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01.java index ede9cd829..e580ded9a 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01.java @@ -204,10 +204,6 @@ public class UISceneDemo01 { scene.waitUntilDisplayed(); final AABBox sceneBox = scene.getBounds(); - final float[] surfaceSize = { 0f, 0f }; - scene.surfaceToPlaneSize(scene.getViewport(), surfaceSize); - - System.err.println("m1 scene "+surfaceSize[0]+" x "+surfaceSize[1]); System.err.println("m1 scene "+sceneBox); System.err.println("m1.0 "+shape); shape.scale(sceneBox.getWidth(), sceneBox.getWidth(), 1f); // scale shape to sceneBox @@ -224,8 +220,8 @@ public class UISceneDemo01 { System.err.println("m2 ["+min+" .. "+max+"], step "+step); for(float x=min; x < max; x+=step) { shape.move(step, 0f, 0f); - final int[] glWinPos = new int[2]; - if( shape.objToWinCoord(scene.getPMVMatrixSetup(), scene.getViewport(), shape.getBounds().getCenter(), new PMVMatrix(), glWinPos) ) { + final int[] glWinPos = shape.shapeToWinCoord(scene.getPMVMatrixSetup(), scene.getViewport(), shape.getBounds().getCenter(), new PMVMatrix(), new int[2]); + if( null != glWinPos ) { window.warpPointer(glWinPos[0], window.getHeight() - glWinPos[1] - 1); } System.err.println("mm x "+x+", ["+min+" .. "+max+"], step "+step); @@ -237,15 +233,13 @@ public class UISceneDemo01 { } static void testProject(final Scene scene, final Shape shape, final int glWinX, final int glWinY) { - final float[] objPos = new float[3]; - final int[] glWinPos = new int[2]; final PMVMatrix pmv = new PMVMatrix(); - boolean ok = shape.winToObjCoord(scene.getPMVMatrixSetup(), scene.getViewport(), glWinX, glWinY, pmv, objPos); - System.err.printf("MM1: winToObjCoord: ok "+ok+", obj [%25.20ff, %25.20ff, %25.20ff]%n", objPos[0], objPos[1], objPos[2]); - ok = shape.objToWinCoord(scene.getPMVMatrixSetup(), scene.getViewport(), objPos, pmv, glWinPos); + final float[] objPos = shape.winToShapeCoord(scene.getPMVMatrixSetup(), scene.getViewport(), glWinX, glWinY, pmv, new float[3]); + System.err.printf("MM1: winToObjCoord: obj [%25.20ff, %25.20ff, %25.20ff]%n", objPos[0], objPos[1], objPos[2]); + final int[] glWinPos = shape.shapeToWinCoord(scene.getPMVMatrixSetup(), scene.getViewport(), objPos, pmv, new int[2]); final int windx = glWinPos[0]-glWinX; final int windy = glWinPos[1]-glWinY; - System.err.printf("MM2: objToWinCoord: ok "+ok+", winCoords %d / %d, diff %d x %d%n", glWinPos[0], glWinPos[1], windx, windy); + System.err.printf("MM2: objToWinCoord: winCoords %d / %d, diff %d x %d%n", glWinPos[0], glWinPos[1], windx, windy); } @SuppressWarnings("unused") diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo02.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo02.java index 2bcc3a536..4655b773c 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo02.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo02.java @@ -190,9 +190,8 @@ public class UISceneDemo02 implements GLEventListener { for(float x=0; x < max; x+=step) { demo.shape.move(-step, 0f, 0f); // System.err.println(demo.shape); - final int[] glWinPos = new int[2]; - final boolean ok = demo.shape.objToWinCoord(scene.getPMVMatrixSetup(), scene.getViewport(), demo.shape.getBounds().getCenter(), new PMVMatrix(), glWinPos); - System.err.printf("m3: objToWinCoord: ok "+ok+", winCoords %d / %d%n", glWinPos[0], glWinPos[1]); + final int[] glWinPos = demo.shape.shapeToWinCoord(scene.getPMVMatrixSetup(), scene.getViewport(), demo.shape.getBounds().getCenter(), new PMVMatrix(), new int[2]); + System.err.printf("m3: objToWinCoord: winCoords %d / %d%n", glWinPos[0], glWinPos[1]); // demo.testProject(glWinPos[0], glWinPos[1]); window.warpPointer(glWinPos[0], window.getHeight() - glWinPos[1] - 1); System.err.println("mm x "+x+", [0 .. "+max+"], step "+step+", "+box); @@ -200,26 +199,23 @@ public class UISceneDemo02 implements GLEventListener { } } void testProject() { - final int[] glWinPos = new int[2]; - final boolean ok = shape.objToWinCoord(scene.getPMVMatrixSetup(), scene.getViewport(), shape.getBounds().getCenter(), new PMVMatrix(), glWinPos); - System.err.printf("m4: objToWinCoord: ok "+ok+", winCoords %d / %d%n", glWinPos[0], glWinPos[1]); + final int[] glWinPos = shape.shapeToWinCoord(scene.getPMVMatrixSetup(), scene.getViewport(), shape.getBounds().getCenter(), new PMVMatrix(), new int[2]); + System.err.printf("m4: objToWinCoord: winCoords %d / %d%n", glWinPos[0], glWinPos[1]); testProject(glWinPos[0], glWinPos[1]); } void testProject(final int glWinX, final int glWinY) { - final float[] objPos = new float[3]; - final int[] glWinPos = new int[2]; final PMVMatrix pmv = new PMVMatrix(); - boolean ok = shape.winToObjCoord(scene.getPMVMatrixSetup(), scene.getViewport(), glWinX, glWinY, pmv, objPos); - System.err.printf("m5: winToObjCoord: ok "+ok+", obj [%25.20ff, %25.20ff, %25.20ff]%n", objPos[0], objPos[1], objPos[2]); - ok = shape.objToWinCoord(scene.getPMVMatrixSetup(), scene.getViewport(), objPos, pmv, glWinPos); + final float[] objPos = shape.winToShapeCoord(scene.getPMVMatrixSetup(), scene.getViewport(), glWinX, glWinY, pmv, new float[3]); + System.err.printf("m5: winToObjCoord: obj [%25.20ff, %25.20ff, %25.20ff]%n", objPos[0], objPos[1], objPos[2]); + final int[] glWinPos = shape.shapeToWinCoord(scene.getPMVMatrixSetup(), scene.getViewport(), objPos, pmv, new int[2]); final int windx = glWinPos[0]-glWinX; final int windy = glWinPos[1]-glWinY; if( windx > 10 || windy > 10 ) { - System.err.printf("XX: objToWinCoord: ok "+ok+", winCoords %d / %d, diff %d x %d%n", glWinPos[0], glWinPos[1], windx, windy); + System.err.printf("XX: objToWinCoord: winCoords %d / %d, diff %d x %d%n", glWinPos[0], glWinPos[1], windx, windy); // Thread.dumpStack(); // System.exit(-1); } else { - System.err.printf("m6: objToWinCoord: ok "+ok+", winCoords %d / %d, diff %d x %d%n", glWinPos[0], glWinPos[1], windx, windy); + System.err.printf("m6: objToWinCoord: winCoords %d / %d, diff %d x %d%n", glWinPos[0], glWinPos[1], windx, windy); } } @@ -350,13 +346,11 @@ public class UISceneDemo02 implements GLEventListener { pmv.glPushMatrix(); s.setTransform(pmv); - final float[] objPos = new float[3]; - boolean ok = s.winToObjCoord(pmv, viewport, glWinX, glWinY, objPos); - System.err.println("Button: Click: win["+glWinX+", "+glWinY+"] -> ok "+ok+", obj["+objPos[0]+", "+objPos[1]+", "+objPos[1]+"]"); + final float[] objPos = s.winToShapeCoord(pmv, viewport, glWinX, glWinY, new float[3]); + System.err.println("Button: Click: win["+glWinX+", "+glWinY+"] -> obj["+objPos[0]+", "+objPos[1]+", "+objPos[1]+"]"); - final int[] surfaceSize = new int[2]; - ok = s.getSurfaceSize(pmv, viewport, surfaceSize); - System.err.println("Button: Size: ok "+ok+", pixel "+surfaceSize[0]+" x "+surfaceSize[1]); + final int[] surfaceSize = s.getSurfaceSize(pmv, viewport, new int[2]); + System.err.println("Button: Size: pixel "+surfaceSize[0]+" x "+surfaceSize[1]); pmv.glPopMatrix(); } @@ -420,12 +414,11 @@ public class UISceneDemo02 implements GLEventListener { pmv.glPushMatrix(); shape.setTransform(pmv); - final int[] winPosSize = { 0, 0 }; System.err.println("draw.0: "+shape); - boolean ok = shape.getSurfaceSize(pmv, renderer.getViewport(), winPosSize); - System.err.println("draw.1: ok "+ok+", surfaceSize "+winPosSize[0]+" x "+winPosSize[1]); - ok = shape.objToWinCoord(pmv, renderer.getViewport(), shape.getPosition(), winPosSize); - System.err.println("draw.2: ok "+ok+", winCoord "+winPosSize[0]+" x "+winPosSize[1]); + final int[] winSize = shape.getSurfaceSize(pmv, renderer.getViewport(), new int[2]); + System.err.println("draw.1: surfaceSize "+winSize[0]+" x "+winSize[1]); + final int[] winPos = shape.shapeToWinCoord(pmv, renderer.getViewport(), shape.getPosition(), new int[2]); + System.err.println("draw.2: winCoord "+winPos[0]+" x "+winPos[1]); pmv.glPopMatrix(); } diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java index 4d6b85bbd..b1eca9b20 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java @@ -104,10 +104,6 @@ public class UIShapeDemo01 implements GLEventListener { final GLProfile glp = GLProfile.getGL2ES2(); final GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(4); - if( false ) { - caps.setSampleBuffers(true); - caps.setNumSamples(4); - } System.out.println("Requested: " + caps); final int renderModes = Region.COLORCHANNEL_RENDERING_BIT | Region.VBAA_RENDERING_BIT; @@ -248,12 +244,11 @@ public class UIShapeDemo01 implements GLEventListener { shape.setTransform(pmv); shape.draw(gl, renderer, sampleCount); if( once ) { - final int[] winPosSize = { 0, 0 }; System.err.println("draw.0: "+shape); - boolean ok = shape.getSurfaceSize(pmv, renderer.getViewport(), winPosSize); - System.err.println("draw.1: ok "+ok+", surfaceSize "+winPosSize[0]+" x "+winPosSize[1]); - ok = shape.objToWinCoord(pmv, renderer.getViewport(), shape.getPosition(), winPosSize); - System.err.println("draw.2: ok "+ok+", winCoord "+winPosSize[0]+" x "+winPosSize[1]); + final int[] winSize = shape.getSurfaceSize(pmv, renderer.getViewport(), new int[2]); + System.err.println("draw.1: surfaceSize "+winSize[0]+" x "+winSize[1]); + final int[] winPos = shape.shapeToWinCoord(pmv, renderer.getViewport(), shape.getPosition(), new int[2]); + System.err.println("draw.2: winCoord "+winPos[0]+" x "+winPos[1]); } pmv.glPopMatrix(); } @@ -405,14 +400,16 @@ public class UIShapeDemo01 implements GLEventListener { pmv.glPushMatrix(); button.setTransform(pmv); - final float[] objPos = new float[3]; System.err.println("\n\nButton: "+button); - button.winToObjCoord(pmv, viewport, glWinX, glWinY, objPos); - System.err.println("Button: Click: Win "+glWinX+"/"+glWinY+" -> Obj "+objPos[0]+"/"+objPos[1]+"/"+objPos[1]); + final float[] objPos = button.winToShapeCoord(pmv, viewport, glWinX, glWinY, new float[3]); + if( null != objPos ) { + System.err.println("Button: Click: Win "+glWinX+"/"+glWinY+" -> Obj "+objPos[0]+"/"+objPos[1]+"/"+objPos[1]); + } - final int[] surfaceSize = new int[2]; - button.getSurfaceSize(pmv, viewport, surfaceSize); - System.err.println("Button: Size: Pixel "+surfaceSize[0]+" x "+surfaceSize[1]); + final int[] surfaceSize = button.getSurfaceSize(pmv, viewport, new int[2]); + if( null != surfaceSize ) { + System.err.println("Button: Size: Pixel "+surfaceSize[0]+" x "+surfaceSize[1]); + } pmv.glPopMatrix(); } @@ -421,18 +418,15 @@ public class UIShapeDemo01 implements GLEventListener { crossHair.setTransform(pmv); final float[] objPosC = crossHair.getBounds().getCenter(); - final int[] objWinPos = new int[2]; System.err.println("\n\nCrossHair: "+crossHair); - if( crossHair.objToWinCoord(pmv, viewport, objPosC, objWinPos) ) { - System.err.println("CrossHair: Obj: Obj "+objPosC[0]+"/"+objPosC[1]+"/"+objPosC[1]+" -> Win "+objWinPos[0]+"/"+objWinPos[1]); - } + final int[] objWinPos = crossHair.shapeToWinCoord(pmv, viewport, objPosC, new int[2]); + System.err.println("CrossHair: Obj: Obj "+objPosC[0]+"/"+objPosC[1]+"/"+objPosC[1]+" -> Win "+objWinPos[0]+"/"+objWinPos[1]); - final float[] objPos2 = new float[3]; - crossHair.winToObjCoord(pmv, viewport, objWinPos[0], objWinPos[1], objPos2); + final float[] objPos2 = crossHair.winToShapeCoord(pmv, viewport, objWinPos[0], objWinPos[1], new float[3]); System.err.println("CrossHair: Obj: Win "+objWinPos[0]+"/"+objWinPos[1]+" -> Obj "+objPos2[0]+"/"+objPos2[1]+"/"+objPos2[1]); - final float[] winObjPos = new float[3]; - if( crossHair.winToObjCoord(pmv, viewport, glWinX, glWinY, winObjPos) ) { + final float[] winObjPos = crossHair.winToShapeCoord(pmv, viewport, glWinX, glWinY, new float[3]); + if( null != winObjPos ) { // final float[] translate = crossHair.getTranslate(); // final float[] objPosT = new float[] { objPosC[0]+translate[0], objPosC[1]+translate[1], objPosC[2]+translate[2] }; final float dx = winObjPos[0] - objPosC[0]; @@ -446,8 +440,7 @@ public class UIShapeDemo01 implements GLEventListener { } } - final int[] surfaceSize = new int[2]; - crossHair.getSurfaceSize(pmv, viewport, surfaceSize); + final int[] surfaceSize = crossHair.getSurfaceSize(pmv, viewport, new int[2]); System.err.println("CrossHair: Size: Pixel "+surfaceSize[0]+" x "+surfaceSize[1]); pmv.glPopMatrix(); diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java index 08cde27c9..816c9929d 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java @@ -119,10 +119,6 @@ public class UITypeDemo01 implements GLEventListener { final GLProfile glp = GLProfile.getGL2ES2(); final GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(4); - if( false ) { - caps.setSampleBuffers(true); - caps.setNumSamples(4); - } System.out.println("Requested: " + caps); final int renderModes = Region.COLORCHANNEL_RENDERING_BIT | Region.VBAA_RENDERING_BIT; @@ -477,18 +473,15 @@ public class UITypeDemo01 implements GLEventListener { crossHair.setTransform(pmv); final float[] objPosC = crossHair.getBounds().getCenter(); - final int[] objWinPos = new int[2]; System.err.println("\n\nCrossHair: "+crossHair); - if( crossHair.objToWinCoord(pmv, viewport, objPosC, objWinPos) ) { - System.err.println("CrossHair: Obj: Obj "+objPosC[0]+"/"+objPosC[1]+"/"+objPosC[1]+" -> Win "+objWinPos[0]+"/"+objWinPos[1]); - } + final int[] objWinPos = crossHair.shapeToWinCoord(pmv, viewport, objPosC, new int[2]); + System.err.println("CrossHair: Obj: Obj "+objPosC[0]+"/"+objPosC[1]+"/"+objPosC[1]+" -> Win "+objWinPos[0]+"/"+objWinPos[1]); - final float[] objPos2 = new float[3]; - crossHair.winToObjCoord(pmv, viewport, objWinPos[0], objWinPos[1], objPos2); + final float[] objPos2 = crossHair.winToShapeCoord(pmv, viewport, objWinPos[0], objWinPos[1], new float[3]); System.err.println("CrossHair: Obj: Win "+objWinPos[0]+"/"+objWinPos[1]+" -> Obj "+objPos2[0]+"/"+objPos2[1]+"/"+objPos2[1]); - final float[] winObjPos = new float[3]; - if( crossHair.winToObjCoord(pmv, viewport, glWinX, glWinY, winObjPos) ) { + final float[] winObjPos = crossHair.winToShapeCoord(pmv, viewport, glWinX, glWinY, new float[3]); + if( null != winObjPos ) { // final float[] translate = crossHair.getTranslate(); // final float[] objPosT = new float[] { objPosC[0]+translate[0], objPosC[1]+translate[1], objPosC[2]+translate[2] }; final float dx = winObjPos[0] - objPosC[0]; @@ -502,8 +495,7 @@ public class UITypeDemo01 implements GLEventListener { } } - final int[] surfaceSize = new int[2]; - crossHair.getSurfaceSize(pmv, viewport, surfaceSize); + final int[] surfaceSize = crossHair.getSurfaceSize(pmv, viewport, new int[2]); System.err.println("CrossHair: Size: Pixel "+surfaceSize[0]+" x "+surfaceSize[1]); pmv.glPopMatrix(); diff --git a/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java index 7e98df635..204777fde 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java +++ b/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java @@ -433,10 +433,11 @@ public final class Scene implements GLEventListener { final PMVMatrix pmv = renderer.getMatrix(); pmv.glPushMatrix(); s.setTransform(pmv); - shape[0].winToObjCoord(getMatrix(), getViewport(), glWinX, glWinY, objPos); + final boolean ok = null != shape[0].winToShapeCoord(getMatrix(), getViewport(), glWinX, glWinY, objPos); pmv.glPopMatrix(); - - runnable.run(); + if( ok ) { + runnable.run(); + } } return false; // needs to re-render to wash away our false-color glSelect } } ); @@ -482,7 +483,7 @@ public final class Scene implements GLEventListener { } /** - * Calling {@link Shape#winToObjCoord(Scene, int, int, float[])}, retrieving its object position. + * Calling {@link Shape#winToObjCoord(Scene, int, int, float[])}, retrieving its Shape object position. * @param shape * @param glWinX in GL window coordinates, origin bottom-left * @param glWinY in GL window coordinates, origin bottom-left @@ -491,8 +492,8 @@ public final class Scene implements GLEventListener { * @param objPos resulting object position * @param runnable action */ - public void winToObjCoord(final Shape shape, final int glWinX, final int glWinY, final PMVMatrix pmv, final float[] objPos, final Runnable runnable) { - if( null != shape && shape.winToObjCoord(pmvMatrixSetup, renderer.getViewport(), glWinX, glWinY, pmv, objPos) ) { + public void winToShapeCoord(final Shape shape, final int glWinX, final int glWinY, final PMVMatrix pmv, final float[] objPos, final Runnable runnable) { + if( null != shape && null != shape.winToShapeCoord(pmvMatrixSetup, renderer.getViewport(), glWinX, glWinY, pmv, objPos) ) { runnable.run(); } } @@ -732,7 +733,7 @@ public final class Scene implements GLEventListener { final PMVMatrix pmv = new PMVMatrix(); final float[] objPos = new float[3]; final Shape shape = activeShape; - winToObjCoord(shape, glWinX, glWinY, pmv, objPos, () -> { + winToShapeCoord(shape, glWinX, glWinY, pmv, objPos, () -> { shape.dispatchGestureEvent(gh, glWinX, glWinY, pmv, renderer.getViewport(), objPos); }); } @@ -781,7 +782,7 @@ public final class Scene implements GLEventListener { final void dispatchMouseEventForShape(final Shape shape, final MouseEvent e, final int glWinX, final int glWinY) { final PMVMatrix pmv = new PMVMatrix(); final float[] objPos = new float[3]; - winToObjCoord(shape, glWinX, glWinY, pmv, objPos, () -> { shape.dispatchMouseEvent(e, glWinX, glWinY, objPos); }); + winToShapeCoord(shape, glWinX, glWinY, pmv, objPos, () -> { shape.dispatchMouseEvent(e, glWinX, glWinY, objPos); }); } private class SBCMouseListener implements MouseListener { diff --git a/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java index 940e37a3b..089348476 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java @@ -428,11 +428,11 @@ public abstract class Shape { * @param pmv well formed {@link PMVMatrix}, e.g. could have been setup via {@link Scene#setupMatrix(PMVMatrix) setupMatrix(..)} and {@link #setTransform(PMVMatrix)}. * @param viewport the int[4] viewport * @param surfaceSize int[2] target surface size - * @return true for successful gluProject(..) operation, otherwise false + * @return given int[2] {@code surfaceSize} for successful gluProject(..) operation, otherwise {@code null} * @see #getSurfaceSize(com.jogamp.graph.ui.gl.Scene.PMVMatrixSetup, int[], PMVMatrix, int[]) + * @see #getSurfaceSize(Scene, PMVMatrix, int[]) */ - public boolean getSurfaceSize(final PMVMatrix pmv, final int[/*4*/] viewport, final int[/*2*/] surfaceSize) { - boolean res = false; + public int[/*2*/] getSurfaceSize(final PMVMatrix pmv, final int[/*4*/] viewport, final int[/*2*/] surfaceSize) { // System.err.println("Shape::getSurfaceSize.VP "+viewport[0]+"/"+viewport[1]+" "+viewport[2]+"x"+viewport[3]); final float[] winCoordHigh = new float[3]; final float[] winCoordLow = new float[3]; @@ -446,10 +446,10 @@ public abstract class Shape { surfaceSize[0] = (int)(winCoordHigh[0] - winCoordLow[0]); surfaceSize[1] = (int)(winCoordHigh[1] - winCoordLow[1]); // System.err.printf("Shape::surfaceSize.S: shape %d: %f x %f -> %d x %d%n", getName(), winCoordHigh[0] - winCoordLow[0], winCoordHigh[1] - winCoordLow[1], surfaceSize[0], surfaceSize[1]); - res = true; + return surfaceSize; } } - return res; + return null; } /** @@ -463,15 +463,33 @@ public abstract class Shape { * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, int, int, int, int) be setup}, * {@link #setTransform(PMVMatrix) shape-transformed} and can be reused by the caller. * @param surfaceSize int[2] target surface size - * @return true for successful gluProject(..) operation, otherwise false + * @return given int[2] {@code surfaceSize} for successful gluProject(..) operation, otherwise {@code null} * @see #getSurfaceSize(PMVMatrix, int[], int[]) + * @see #getSurfaceSize(Scene, PMVMatrix, int[]) */ - public boolean getSurfaceSize(final Scene.PMVMatrixSetup pmvMatrixSetup, final int[/*4*/] viewport, final PMVMatrix pmv, final int[/*2*/] surfaceSize) { + public int[/*2*/] getSurfaceSize(final Scene.PMVMatrixSetup pmvMatrixSetup, final int[/*4*/] viewport, final PMVMatrix pmv, final int[/*2*/] surfaceSize) { pmvMatrixSetup.set(pmv, viewport[0], viewport[1], viewport[2], viewport[3]); setTransform(pmv); return getSurfaceSize(pmv, viewport, surfaceSize); } + /** + * Retrieve surface (view) size of this shape. + * <p> + * The given {@link PMVMatrix} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix, int, int, int, int) setup} properly for this shape + * including this shape's {@link #setTransform(PMVMatrix)}. + * </p> + * @param scene {@link Scene} to retrieve {@link Scene.PMVMatrixSetup} and the viewport. + * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, int, int, int, int) be setup}, + * {@link #setTransform(PMVMatrix) shape-transformed} and can be reused by the caller. + * @param surfaceSize int[2] target surface size + * @return given int[2] {@code surfaceSize} for successful gluProject(..) operation, otherwise {@code null} + * @see #getSurfaceSize(PMVMatrix, int[], int[]) + * @see #getSurfaceSize(com.jogamp.graph.ui.gl.Scene.PMVMatrixSetup, int[], PMVMatrix, int[]) + */ + public int[/*2*/] getSurfaceSize(final Scene scene, final PMVMatrix pmv, final int[/*2*/] surfaceSize) { + return getSurfaceSize(scene.getPMVMatrixSetup(), scene.getViewport(), pmv, surfaceSize); + } /** * Map given object coordinate relative to this shape to window coordinates. @@ -484,11 +502,11 @@ public abstract class Shape { * @param viewport the int[4] viewport * @param objPos float[3] object position relative to this shape's center * @param glWinPos int[2] target window position of objPos relative to this shape - * @return true for successful gluProject(..) operation, otherwise false - * @see #objToWinCoord(com.jogamp.graph.ui.gl.Scene.PMVMatrixSetup, int[], float[], PMVMatrix, int[]) + * @return given int[2] {@code glWinPos} for successful gluProject(..) operation, otherwise {@code null} + * @see #shapeToWinCoord(com.jogamp.graph.ui.gl.Scene.PMVMatrixSetup, int[], float[], PMVMatrix, int[]) + * @see #shapeToWinCoord(Scene, float[], PMVMatrix, int[]) */ - public boolean objToWinCoord(final PMVMatrix pmv, final int[/*4*/] viewport, final float[/*3*/] objPos, final int[/*2*/] glWinPos) { - boolean res = false; + public int[/*2*/] shapeToWinCoord(final PMVMatrix pmv, final int[/*4*/] viewport, final float[/*3*/] objPos, final int[/*2*/] glWinPos) { // System.err.println("Shape::objToWinCoordgetSurfaceSize.VP "+viewport[0]+"/"+viewport[1]+" "+viewport[2]+"x"+viewport[3]); final float[] winCoord = new float[3]; @@ -497,9 +515,9 @@ public abstract class Shape { glWinPos[0] = (int)(winCoord[0]); glWinPos[1] = (int)(winCoord[1]); // System.err.printf("Shape::objToWinCoord.X: shape %d: %f / %f -> %d / %d%n", getName(), winCoord[0], winCoord[1], glWinPos[0], glWinPos[1]); - res = true; + return glWinPos; } - return res; + return null; } /** @@ -514,13 +532,33 @@ public abstract class Shape { * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, int, int, int, int) be setup}, * {@link #setTransform(PMVMatrix) shape-transformed} and can be reused by the caller. * @param glWinPos int[2] target window position of objPos relative to this shape - * @return true for successful gluProject(..) operation, otherwise false - * @see #objToWinCoord(PMVMatrix, int[], float[], int[]) + * @return given int[2] {@code glWinPos} for successful gluProject(..) operation, otherwise {@code null} + * @see #shapeToWinCoord(PMVMatrix, int[], float[], int[]) + * @see #shapeToWinCoord(Scene, float[], PMVMatrix, int[]) */ - public boolean objToWinCoord(final Scene.PMVMatrixSetup pmvMatrixSetup, final int[/*4*/] viewport, final float[/*3*/] objPos, final PMVMatrix pmv, final int[/*2*/] glWinPos) { + public int[/*2*/] shapeToWinCoord(final Scene.PMVMatrixSetup pmvMatrixSetup, final int[/*4*/] viewport, final float[/*3*/] objPos, final PMVMatrix pmv, final int[/*2*/] glWinPos) { pmvMatrixSetup.set(pmv, viewport[0], viewport[1], viewport[2], viewport[3]); setTransform(pmv); - return this.objToWinCoord(pmv, viewport, objPos, glWinPos); + return this.shapeToWinCoord(pmv, viewport, objPos, glWinPos); + } + + /** + * Map given object coordinate relative to this shape to window coordinates. + * <p> + * The given {@link PMVMatrix} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix, int, int, int, int) setup} properly for this shape + * including this shape's {@link #setTransform(PMVMatrix)}. + * </p> + * @param scene {@link Scene} to retrieve {@link Scene.PMVMatrixSetup} and the viewport. + * @param objPos float[3] object position relative to this shape's center + * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, int, int, int, int) be setup}, + * {@link #setTransform(PMVMatrix) shape-transformed} and can be reused by the caller. + * @param glWinPos int[2] target window position of objPos relative to this shape + * @return given int[2] {@code glWinPos} for successful gluProject(..) operation, otherwise {@code null} + * @see #shapeToWinCoord(PMVMatrix, int[], float[], int[]) + * @see #shapeToWinCoord(com.jogamp.graph.ui.gl.Scene.PMVMatrixSetup, int[], float[], PMVMatrix, int[]) + */ + public int[/*2*/] shapeToWinCoord(final Scene scene, final float[/*3*/] objPos, final PMVMatrix pmv, final int[/*2*/] glWinPos) { + return this.shapeToWinCoord(scene.getPMVMatrixSetup(), scene.getViewport(), objPos, pmv, glWinPos); } /** @@ -535,11 +573,11 @@ public abstract class Shape { * @param glWinX in GL window coordinates, origin bottom-left * @param glWinY in GL window coordinates, origin bottom-left * @param objPos float[3] target object position of glWinX/glWinY relative to this shape - * @return true for successful gluProject(..) and gluUnProject(..) operations, otherwise false - * @see #winToObjCoord(com.jogamp.graph.ui.gl.Scene.PMVMatrixSetup, int[], int, int, PMVMatrix, float[]) + * @return given float[3] {@code objPos} for successful gluProject(..) and gluUnProject(..) operation, otherwise {@code null} + * @see #winToShapeCoord(com.jogamp.graph.ui.gl.Scene.PMVMatrixSetup, int[], int, int, PMVMatrix, float[]) + * @see #winToShapeCoord(Scene, int, int, PMVMatrix, float[]) */ - public boolean winToObjCoord(final PMVMatrix pmv, final int[/*4*/] viewport, final int glWinX, final int glWinY, final float[/*3*/] objPos) { - boolean res = false; + public float[/*3*/] winToShapeCoord(final PMVMatrix pmv, final int[/*4*/] viewport, final int glWinX, final int glWinY, final float[/*3*/] objPos) { final float[] ctr = getBounds().getCenter(); final float[] tmp = new float[3]; @@ -547,10 +585,10 @@ public abstract class Shape { // System.err.printf("Shape::winToObjCoord.0: shape %d: obj [%15.10ff, %15.10ff, %15.10ff] -> win [%d / %d -> %7.2ff, %7.2ff, %7.2ff, diff %7.2ff x %7.2ff]%n", getName(), ctr[0], ctr[1], ctr[2], glWinX, glWinY, tmp[0], tmp[1], tmp[2], glWinX-tmp[0], glWinY-tmp[1]); if( pmv.gluUnProject(glWinX, glWinY, tmp[2], viewport, 0, objPos, 0) ) { // System.err.printf("Shape::winToObjCoord.X: shape %d: win [%d, %d, %7.2ff] -> obj [%15.10ff, %15.10ff, %15.10ff]%n", getName(), glWinX, glWinY, tmp[2], objPos[0], objPos[1], objPos[2]); - res = true; + return objPos; } } - return res; + return null; } /** @@ -561,19 +599,39 @@ public abstract class Shape { * </p> * @param pmvMatrixSetup {@link Scene.PMVMatrixSetup} to {@link Scene.PMVMatrixSetup#set(PMVMatrix, int, int, int, int) setup} given {@link PMVMatrix} {@code pmv}. * @param viewport used viewport for {@link PMVMatrix#gluUnProject(float, float, float, int[], int, float[], int)} - * @param scene {@link Scene} source of viewport and local {@link PMVMatrix} {@link Scene#setupMatrix(PMVMatrix) setupMatrix(..)}. * @param glWinX in GL window coordinates, origin bottom-left * @param glWinY in GL window coordinates, origin bottom-left * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, int, int, int, int) be setup}, * {@link #setTransform(PMVMatrix) shape-transformed} and can be reused by the caller. * @param objPos float[3] target object position of glWinX/glWinY relative to this shape - * @return true for successful gluProject(..) and gluUnProject(..) operations, otherwise false - * @see #winToObjCoord(PMVMatrix, int[], int, int, float[]) + * @return given float[3] {@code objPos} for successful gluProject(..) and gluUnProject(..) operation, otherwise {@code null} + * @see #winToShapeCoord(PMVMatrix, int[], int, int, float[]) + * @see #winToShapeCoord(Scene, int, int, PMVMatrix, float[]) */ - public boolean winToObjCoord(final Scene.PMVMatrixSetup pmvMatrixSetup, final int[/*4*/] viewport, final int glWinX, final int glWinY, final PMVMatrix pmv, final float[/*3*/] objPos) { + public float[/*3*/] winToShapeCoord(final Scene.PMVMatrixSetup pmvMatrixSetup, final int[/*4*/] viewport, final int glWinX, final int glWinY, final PMVMatrix pmv, final float[/*3*/] objPos) { pmvMatrixSetup.set(pmv, viewport[0], viewport[1], viewport[2], viewport[3]); setTransform(pmv); - return this.winToObjCoord(pmv, viewport, glWinX, glWinY, objPos); + return this.winToShapeCoord(pmv, viewport, glWinX, glWinY, objPos); + } + + /** + * Map given gl-window-coordinates to object coordinates relative to this shape and its z-coordinate. + * <p> + * The given {@link PMVMatrix} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix, int, int, int, int) setup} properly for this shape + * including this shape's {@link #setTransform(PMVMatrix)}. + * </p> + * @param scene {@link Scene} to retrieve {@link Scene.PMVMatrixSetup} and the viewport. + * @param glWinX in GL window coordinates, origin bottom-left + * @param glWinY in GL window coordinates, origin bottom-left + * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, int, int, int, int) be setup}, + * {@link #setTransform(PMVMatrix) shape-transformed} and can be reused by the caller. + * @param objPos float[3] target object position of glWinX/glWinY relative to this shape + * @return given float[3] {@code objPos} for successful gluProject(..) and gluUnProject(..) operation, otherwise {@code null} + * @see #winToShapeCoord(PMVMatrix, int[], int, int, float[]) + * @see #winToShapeCoord(com.jogamp.graph.ui.gl.Scene.PMVMatrixSetup, int[], int, int, PMVMatrix, float[]) + */ + public float[/*3*/] winToShapeCoord(final Scene scene, final int glWinX, final int glWinY, final PMVMatrix pmv, final float[/*3*/] objPos) { + return this.winToShapeCoord(scene.getPMVMatrixSetup(), scene.getViewport(), glWinX, glWinY, pmv, objPos); } public float[] getColor() { @@ -960,19 +1018,21 @@ public abstract class Shape { if( resizable && e instanceof PinchToZoomGesture.ZoomEvent ) { final PinchToZoomGesture.ZoomEvent ze = (PinchToZoomGesture.ZoomEvent) e; final float pixels = ze.getDelta() * ze.getScale(); // - final float[] objPos2 = { 0f, 0f, 0f }; final int winX2 = glWinX + Math.round(pixels); - final boolean ok = winToObjCoord(pmv, viewport, winX2, glWinY, objPos2); + final float[] objPos2 = winToShapeCoord(pmv, viewport, winX2, glWinY, new float[3]); + if( null == objPos2 ) { + return; + } final float dx = objPos2[0]; final float dy = objPos2[1]; final float sx = scale[0] + ( dx/box.getWidth() ); // bottom-right final float sy = scale[1] + ( dy/box.getHeight() ); if( DEBUG ) { - System.err.printf("DragZoom: resize %b, ok %b, obj %4d/%4d, %.3f/%.3f/%.3f %.3f/%.3f/%.3f + %.3f/%.3f -> %.3f/%.3f%n", - inResize, ok, glWinX, glWinY, objPos[0], objPos[1], objPos[2], position[0], position[1], position[2], + System.err.printf("DragZoom: resize %b, obj %4d/%4d, %.3f/%.3f/%.3f %.3f/%.3f/%.3f + %.3f/%.3f -> %.3f/%.3f%n", + inResize, glWinX, glWinY, objPos[0], objPos[1], objPos[2], position[0], position[1], position[2], dx, dy, sx, sy); } - if( ok && resize_sxy_min <= sx && resize_sxy_min <= sy ) { // avoid scale flip + if( resize_sxy_min <= sx && resize_sxy_min <= sy ) { // avoid scale flip if( DEBUG ) { System.err.printf("PinchZoom: pixels %f, obj %4d/%4d, %.3f/%.3f/%.3f %.3f/%.3f/%.3f + %.3f/%.3f -> %.3f/%.3f%n", pixels, glWinX, glWinY, objPos[0], objPos[1], objPos[2], position[0], position[1], position[2], diff --git a/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Button.java b/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Button.java index 226477f80..fb81522ad 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Button.java +++ b/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Button.java @@ -27,7 +27,6 @@ */ package com.jogamp.graph.ui.gl.shapes; -import com.jogamp.opengl.GL; import com.jogamp.opengl.GL2ES2; import com.jogamp.graph.curve.OutlineShape; @@ -114,7 +113,7 @@ public class Button extends RoundButton { final float[] ctr = box.getCenter(); final float[] ltx = new float[] { ctr[0] - lctr[0], ctr[1] - lctr[1], 0f }; - if( true || DRAW_DEBUG_BOX ) { + if( DRAW_DEBUG_BOX ) { System.err.println("RIButton: dim "+width+" x "+height+", spacing "+spacingX+", "+spacingY); System.err.println("RIButton: net-text "+lw+" x "+lh); System.err.println("RIButton: shape "+box); diff --git a/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/GLButton.java b/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/GLButton.java index 792027d7d..4ddb44606 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/GLButton.java +++ b/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/GLButton.java @@ -93,8 +93,8 @@ public class GLButton extends TexSeqButton { @Override public void draw(final GL2ES2 gl, final RegionRenderer renderer, final int[] sampleCount) { - final int[/*2*/] surfaceSize = new int[2]; - final boolean got_sz = getSurfaceSize(renderer.getMatrix(), renderer.getViewport(), surfaceSize) && 0 < surfaceSize[0] && 0 < surfaceSize[1]; + final int[/*2*/] surfaceSize = getSurfaceSize(renderer.getMatrix(), renderer.getViewport(), new int[2]); + final boolean got_sz = null != surfaceSize && 0 < surfaceSize[0] && 0 < surfaceSize[1]; if( null == fboGLAD ) { final ImageSequence imgSeq = (ImageSequence)texSeq; |