aboutsummaryrefslogtreecommitdiffstats
path: root/src/demos/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-03-19 15:34:24 +0100
committerSven Gothel <[email protected]>2023-03-19 15:34:24 +0100
commit01d35625f848ed3a97fae750ff2e8928f9d6538a (patch)
tree8688e14c313db83d0cfff1aa24ecd4ff876ea55d /src/demos/com/jogamp
parent8eb70fb10a4f81c93dbc4ed12571a67ffbc1649a (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/demos/com/jogamp')
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01.java18
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo02.java41
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java43
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java20
4 files changed, 47 insertions, 75 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();