summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo00.java25
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java50
2 files changed, 59 insertions, 16 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo00.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo00.java
index 76ee7389d..d7677ecbd 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo00.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo00.java
@@ -52,6 +52,13 @@ import com.jogamp.opengl.util.PMVMatrix;
/**
* Res independent Shape, in Scene attached to GLWindow showing simple linear Shape movement within one main function.
+ * <p>
+ * The shape is created using the normalized scene's default bounding box, normalized to 1 for the greater of width and height.
+ * </p>
+ * <p>
+ * Pass '-keep' to main-function to keep running after animation,
+ * then user can test Shape drag-move and drag-resize w/ 1-pointer.
+ * </p>
*/
public class UISceneDemo00 {
public static void main(final String[] args) throws IOException {
@@ -59,13 +66,22 @@ public class UISceneDemo00 {
final int renderModes = Region.VBAA_RENDERING_BIT;
final GLProfile glp = GLProfile.getGL2ES2();
+ boolean keepRunning = false;
+ if( 0 != args.length ) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-keep")) {
+ keepRunning = true;
+ }
+ }
+ }
+
//
// Resolution independent, no screen size
//
final Font font = FontFactory.get(FontFactory.UBUNTU).get(FontSet.FAMILY_LIGHT, FontSet.STYLE_SERIF);
System.err.println("Font: "+font.getFullFamilyName());
- final Shape shape = new Button(SVertex.factory(), renderModes, font, "+", 0.10f, 0.10f/2.5f);
+ final Shape shape = new Button(SVertex.factory(), renderModes, font, "+", 0.10f, 0.10f/2.5f); // normalized: 1 is 100% surface size (width and/or height)
System.err.println("Shape bounds "+shape.getBounds(glp));
final Scene scene = new Scene();
@@ -99,12 +115,11 @@ public class UISceneDemo00 {
//
// After initial display we can use screen resolution post initial Scene.reshape(..)
// However, in this example we merely use the resolution to
- // - Scale the shape to the sceneBox, i.e. normalizing to screen-size 1x1
// - Compute the animation values with DPI
scene.waitUntilDisplayed();
final AABBox sceneBox = scene.getBounds();
- shape.scale(sceneBox.getWidth(), sceneBox.getWidth(), 1f); // scale shape to sceneBox, normalizing to screen-size 1x1
+ System.err.println("SceneBox "+sceneBox);
try { Thread.sleep(1000); } catch (final InterruptedException e1) { }
//
@@ -156,6 +171,8 @@ public class UISceneDemo00 {
final float has_dur_s = ( ( Clock.currentNanos() / 1000 ) - t0_us ) / 1e6f; // [us]
System.err.printf("Actual travel-duration %.3f s, delay %.3f s%n", has_dur_s, has_dur_s-exp_dur_s);
try { Thread.sleep(1000); } catch (final InterruptedException e1) { }
- window.destroy();
+ if( !keepRunning ) {
+ window.destroy();
+ }
}
}
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 d5468f388..47411f60f 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java
@@ -540,13 +540,20 @@ public final class Scene implements GLEventListener {
* Custom implementations can be set via {@link Scene#setPMVMatrixSetup(PMVMatrixSetup)}.
* </p>
* <p>
- * The default implementation is described below
- * </p>
- * <p>
- * {@link GLMatrixFunc#GL_PROJECTION} is setup using perspective {@link Scene#DEFAULT_ANGLE} with {@link Scene#DEFAULT_ZNEAR} and {@link Scene#DEFAULT_ZFAR}.
- * </p>
- * <p>
- * Further {@link GLMatrixFunc#GL_MODELVIEW} is translated to given {@link Scene#DEFAULT_SCENE_DIST}.
+ * The default implementation is described below:
+ * <ul>
+ * <li>{@link GLMatrixFunc#GL_PROJECTION} Matrix
+ * <ul>
+ * <li>Identity</li>
+ * <li>Perspective {@link Scene#DEFAULT_ANGLE} with {@link Scene#DEFAULT_ZNEAR} and {@link Scene#DEFAULT_ZFAR}</li>
+ * <li>Translated to given {@link Scene#DEFAULT_SCENE_DIST}</li>
+ * <li>Scale (back) to have normalized {@link Scene#getBounds() plane dimensions}, 1 for the greater of width and height.</li>
+ * </ul></li>
+ * <li>{@link GLMatrixFunc#GL_MODELVIEW} Matrix
+ * <ul>
+ * <li>identity</li>
+ * </ul></li>
+ * </ul>
* </p>
*/
public static interface PMVMatrixSetup {
@@ -571,8 +578,12 @@ public final class Scene implements GLEventListener {
* <p>
* Will be called by {@link Scene#reshape(GLAutoDrawable, int, int, int, int)} after {@link #set(PMVMatrix, int, int, int, int)}.
* </p>
- * @param x TODO
- * @param y TODO
+ * @param planeBox the {@link AABBox} to define
+ * @param pmv the {@link PMVMatrix}, already setup via {@link #set(PMVMatrix, int, int, int, int)}.
+ * @param x lower left corner of the viewport rectangle
+ * @param y lower left corner of the viewport rectangle
+ * @param width width of the viewport rectangle
+ * @param height height of the viewport rectangle
*/
void setPlaneBox(final AABBox planeBox, final PMVMatrix pmv, int x, int y, final int width, final int height);
}
@@ -583,6 +594,9 @@ public final class Scene implements GLEventListener {
/** Set a custom {@link PMVMatrixSetup}. */
public final void setPMVMatrixSetup(final PMVMatrixSetup setup) { pmvMatrixSetup = setup; }
+ /** Return the default {@link PMVMatrixSetup}. */
+ public static PMVMatrixSetup getDefaultPMVMatrixSetup() { return defaultPMVMatrixSetup; }
+
/**
* Reshape scene using {@link #setupMatrix(PMVMatrix, int, int, int, int)} using {@link PMVMatrixSetup}.
* <p>
@@ -650,6 +664,9 @@ public final class Scene implements GLEventListener {
* <p>
* {@link AABBox} is setup via {@link #getPMVMatrixSetup()}'s {@link PMVMatrixSetup#setPlaneBox(AABBox, PMVMatrix, int, int, int, int)}.
* </p>
+ * <p>
+ * The default {@link PMVMatrixSetup} implementation scales to normalized plane dimensions, 1 for the greater of width and height.
+ * </p>
*/
public AABBox getBounds() { return planeBox; }
@@ -913,7 +930,7 @@ public final class Scene implements GLEventListener {
return String.format("%03.1f/%03.1f fps, %.1f ms/f", lfps, tfps, td);
}
- private final PMVMatrixSetup defaultPMVMatrixSetup = new PMVMatrixSetup() {
+ private static final PMVMatrixSetup defaultPMVMatrixSetup = new PMVMatrixSetup() {
@Override
public void set(final PMVMatrix pmv, final int x, final int y, final int width, final int height) {
final float ratio = (float)width/(float)height;
@@ -922,6 +939,14 @@ public final class Scene implements GLEventListener {
pmv.gluPerspective(DEFAULT_ANGLE, ratio, DEFAULT_ZNEAR, DEFAULT_ZFAR);
pmv.glTranslatef(0f, 0f, DEFAULT_SCENE_DIST);
+ // Scale (back) to have normalized plane dimensions, 1 for the greater of width and height.
+ final AABBox planeBox0 = new AABBox();
+ setPlaneBox(planeBox0, pmv, x, y, width, height);
+ final float sx = planeBox0.getWidth();
+ final float sy = planeBox0.getHeight();
+ final float sxy = sx > sy ? sx : sy;
+ pmv.glScalef(sxy, sxy, 1f);
+
pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
pmv.glLoadIdentity();
}
@@ -931,9 +956,10 @@ public final class Scene implements GLEventListener {
final float orthoDist = -DEFAULT_SCENE_DIST;
final float[] obj00Coord = new float[3];
final float[] obj11Coord = new float[3];
+ final int[] viewport = { x, y, width, height };
- winToPlaneCoord(pmv, getViewport(), DEFAULT_ZNEAR, DEFAULT_ZFAR, x, y, orthoDist, obj00Coord);
- winToPlaneCoord(pmv, getViewport(), DEFAULT_ZNEAR, DEFAULT_ZFAR, width, height, orthoDist, obj11Coord);
+ winToPlaneCoord(pmv, viewport, DEFAULT_ZNEAR, DEFAULT_ZFAR, x, y, orthoDist, obj00Coord);
+ winToPlaneCoord(pmv, viewport, DEFAULT_ZNEAR, DEFAULT_ZFAR, width, height, orthoDist, obj11Coord);
planeBox.setSize( obj00Coord[0], // lx
obj00Coord[1], // ly