aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutBox01.java43
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutGrid01.java44
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo00.java21
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01.java16
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01b.java25
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java33
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo10.java24
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo11.java19
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java41
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/Scene.java151
10 files changed, 188 insertions, 229 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutBox01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutBox01.java
index 494c8396a..8d8a995d9 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutBox01.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutBox01.java
@@ -36,7 +36,6 @@ import com.jogamp.graph.font.FontSet;
import com.jogamp.graph.ui.Group;
import com.jogamp.graph.ui.Scene;
import com.jogamp.graph.ui.Shape;
-import com.jogamp.graph.ui.Scene.PMVMatrixSetup;
import com.jogamp.graph.ui.layout.BoxLayout;
import com.jogamp.graph.ui.layout.Margin;
import com.jogamp.graph.ui.layout.Padding;
@@ -52,13 +51,10 @@ import com.jogamp.opengl.GL;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.demos.util.CommandlineOptions;
-import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
import com.jogamp.opengl.math.FloatUtil;
-import com.jogamp.opengl.math.Recti;
import com.jogamp.opengl.math.Vec3f;
import com.jogamp.opengl.math.geom.AABBox;
import com.jogamp.opengl.util.Animator;
-import com.jogamp.opengl.util.PMVMatrix;
/**
* Res independent {@link Shape}s in a {@link Group} using a {@link BoxLayout}, contained within a Scene attached to GLWindow.
@@ -70,38 +66,6 @@ import com.jogamp.opengl.util.PMVMatrix;
public class UILayoutBox01 {
static CommandlineOptions options = new CommandlineOptions(1280, 720, Region.VBAA_RENDERING_BIT);
- /**
- * Our PMVMatrixSetup:
- * - gluPerspective like Scene's default
- * - no normal scale to 1, keep a longer distance to near plane for rotation effects. We scale Shapes
- */
- public static class MyPMVMatrixSetup implements PMVMatrixSetup {
- static float Z_DIST = -1f;
- @Override
- public void set(final PMVMatrix pmv, final Recti viewport) {
- final float ratio = (float)viewport.width()/(float)viewport.height();
- pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmv.glLoadIdentity();
- pmv.gluPerspective(Scene.DEFAULT_ANGLE, ratio, Scene.DEFAULT_ZNEAR, Scene.DEFAULT_ZFAR);
- pmv.glTranslatef(0f, 0f, Z_DIST); // Scene.DEFAULT_SCENE_DIST);
-
- pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
- pmv.glLoadIdentity();
- }
-
- @Override
- public void setPlaneBox(final AABBox planeBox, final PMVMatrix pmv, final Recti viewport) {
- final float orthoDist = -Z_DIST; // Scene.DEFAULT_SCENE_DIST;
- final Vec3f obj00Coord = new Vec3f();
- final Vec3f obj11Coord = new Vec3f();
-
- Scene.winToPlaneCoord(pmv, viewport, Scene.DEFAULT_ZNEAR, Scene.DEFAULT_ZFAR, viewport.x(), viewport.y(), orthoDist, obj00Coord);
- Scene.winToPlaneCoord(pmv, viewport, Scene.DEFAULT_ZNEAR, Scene.DEFAULT_ZFAR, viewport.width(), viewport.height(), orthoDist, obj11Coord);
-
- planeBox.setSize( obj00Coord, obj11Coord );
- }
- };
-
static final boolean reLayout = false;
public static void main(final String[] args) throws IOException {
@@ -110,6 +74,8 @@ public class UILayoutBox01 {
for (idx[0] = 0; idx[0] < args.length; ++idx[0]) {
if( options.parse(args, idx) ) {
continue;
+ } else if (args[idx[0]].equals("-no_relayout")) {
+ reLayout = false;
}
}
}
@@ -143,8 +109,8 @@ public class UILayoutBox01 {
});
- final Scene scene = new Scene();
- scene.setPMVMatrixSetup(new MyPMVMatrixSetup());
+ final Scene scene = new Scene(options.graphAASamples);
+ scene.setPMVMatrixSetup(new Scene.DefaultPMVMatrixSetup(-1f));
scene.setClearParams(new float[] { 1f, 1f, 1f, 1f}, GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
scene.setFrustumCullingEnabled(true);
scene.attachInputListenerTo(window);
@@ -182,6 +148,7 @@ public class UILayoutBox01 {
System.err.println("SceneBox "+sceneBox);
final float sxy = 1/8f * sceneBox.getWidth();
+ System.err.println("Scale xy "+sxy);
float nextPos = 0;
final Group groupA0 = new Group(new BoxLayout( new Padding(0.15f, 0.15f) ) );
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutGrid01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutGrid01.java
index 00b41cda5..8fe989344 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutGrid01.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutGrid01.java
@@ -36,7 +36,6 @@ import com.jogamp.graph.font.FontSet;
import com.jogamp.graph.ui.Group;
import com.jogamp.graph.ui.Scene;
import com.jogamp.graph.ui.Shape;
-import com.jogamp.graph.ui.Scene.PMVMatrixSetup;
import com.jogamp.graph.ui.layout.Alignment;
import com.jogamp.graph.ui.layout.Gap;
import com.jogamp.graph.ui.layout.GridLayout;
@@ -50,14 +49,11 @@ import com.jogamp.opengl.GL;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.demos.util.CommandlineOptions;
-import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
import com.jogamp.opengl.math.FloatUtil;
-import com.jogamp.opengl.math.Recti;
import com.jogamp.opengl.math.Vec3f;
import com.jogamp.opengl.math.Vec4f;
import com.jogamp.opengl.math.geom.AABBox;
import com.jogamp.opengl.util.Animator;
-import com.jogamp.opengl.util.PMVMatrix;
/**
* Res independent {@link Shape}s in a {@link Group} using a {@link GridLayout}, contained within a Scene attached to GLWindow.
@@ -69,39 +65,7 @@ import com.jogamp.opengl.util.PMVMatrix;
public class UILayoutGrid01 {
static CommandlineOptions options = new CommandlineOptions(1280, 720, Region.VBAA_RENDERING_BIT);
- /**
- * Our PMVMatrixSetup:
- * - gluPerspective like Scene's default
- * - no normal scale to 1, keep a longer distance to near plane for rotation effects. We scale Shapes
- */
- public static class MyPMVMatrixSetup implements PMVMatrixSetup {
- static float Z_DIST = -1f;
- @Override
- public void set(final PMVMatrix pmv, final Recti viewport) {
- final float ratio = (float)viewport.width()/(float)viewport.height();
- pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmv.glLoadIdentity();
- pmv.gluPerspective(Scene.DEFAULT_ANGLE, ratio, Scene.DEFAULT_ZNEAR, Scene.DEFAULT_ZFAR);
- pmv.glTranslatef(0f, 0f, Z_DIST); // Scene.DEFAULT_SCENE_DIST);
-
- pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
- pmv.glLoadIdentity();
- }
-
- @Override
- public void setPlaneBox(final AABBox planeBox, final PMVMatrix pmv, final Recti viewport) {
- final float orthoDist = -Z_DIST; // Scene.DEFAULT_SCENE_DIST;
- final Vec3f obj00Coord = new Vec3f();
- final Vec3f obj11Coord = new Vec3f();
-
- Scene.winToPlaneCoord(pmv, viewport, Scene.DEFAULT_ZNEAR, Scene.DEFAULT_ZFAR, viewport.x(), viewport.y(), orthoDist, obj00Coord);
- Scene.winToPlaneCoord(pmv, viewport, Scene.DEFAULT_ZNEAR, Scene.DEFAULT_ZFAR, viewport.width(), viewport.height(), orthoDist, obj11Coord);
-
- planeBox.setSize( obj00Coord, obj11Coord );
- }
- };
-
- static final boolean reLayout = false;
+ static boolean reLayout = true;
static final int reLayoutSleep = 500;
public static void main(final String[] args) throws IOException {
@@ -110,6 +74,8 @@ public class UILayoutGrid01 {
for (idx[0] = 0; idx[0] < args.length; ++idx[0]) {
if( options.parse(args, idx) ) {
continue;
+ } else if (args[idx[0]].equals("-no_relayout")) {
+ reLayout = false;
}
}
}
@@ -143,8 +109,8 @@ public class UILayoutGrid01 {
});
- final Scene scene = new Scene();
- scene.setPMVMatrixSetup(new MyPMVMatrixSetup());
+ final Scene scene = new Scene(options.graphAASamples);
+ scene.setPMVMatrixSetup(new Scene.DefaultPMVMatrixSetup(-1f));
scene.setClearParams(new float[] { 1f, 1f, 1f, 1f}, GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
scene.setFrustumCullingEnabled(true);
scene.attachInputListenerTo(window);
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 ddc1b72f6..08e5ba7fd 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo00.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo00.java
@@ -44,6 +44,8 @@ import com.jogamp.opengl.GL;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.demos.util.CommandlineOptions;
+import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
+import com.jogamp.opengl.math.Recti;
import com.jogamp.opengl.math.geom.AABBox;
import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.PMVMatrix;
@@ -76,6 +78,7 @@ public class UISceneDemo00 {
System.err.println("Shape bounds "+shape.getBounds(reqGLP));
final Scene scene = new Scene(options.graphAASamples);
+ scene.setPMVMatrixSetup(new MyPMVMatrixSetup());
scene.setClearParams(new float[] { 1f, 1f, 1f, 1f}, GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
scene.addShape(shape);
@@ -166,4 +169,22 @@ public class UISceneDemo00 {
window.destroy();
}
}
+
+ static class MyPMVMatrixSetup extends Scene.DefaultPMVMatrixSetup {
+ @Override
+ public void set(final PMVMatrix pmv, final Recti viewport) {
+ super.set(pmv, viewport);
+
+ // Scale (back) to have normalized plane dimensions, 1 for the greater of width and height.
+ final AABBox planeBox0 = new AABBox();
+ setPlaneBox(planeBox0, pmv, viewport);
+ final float sx = planeBox0.getWidth();
+ final float sy = planeBox0.getHeight();
+ final float sxy = sx > sy ? sx : sy;
+ pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ pmv.glScalef(sxy, sxy, 1f);
+ pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ }
+ };
+
}
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 5aa5869cd..83092d366 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01.java
@@ -178,17 +178,10 @@ public class UISceneDemo01 {
}
}
- static class MyPMVMatrixSetup implements PMVMatrixSetup {
+ static class MyPMVMatrixSetup extends Scene.DefaultPMVMatrixSetup {
@Override
public void set(final PMVMatrix pmv, final Recti viewport) {
- final float ratio = (float)viewport.width()/(float)viewport.height();
- pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmv.glLoadIdentity();
- pmv.gluPerspective(Scene.DEFAULT_ANGLE, ratio, Scene.DEFAULT_ZNEAR, Scene.DEFAULT_ZFAR);
- pmv.glTranslatef(0f, 0f, Scene.DEFAULT_SCENE_DIST);
-
- pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
- pmv.glLoadIdentity();
+ super.set(pmv, viewport);
// Scale (back) to have normalized plane dimensions, 100 for the greater of width and height.
final AABBox planeBox0 = new AABBox();
@@ -200,11 +193,6 @@ public class UISceneDemo01 {
pmv.glScalef(sxy / 100f, sxy / 100f, 1f);
pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
}
-
- @Override
- public void setPlaneBox(final AABBox planeBox, final PMVMatrix pmv, final Recti viewport) {
- Scene.getDefaultPMVMatrixSetup().setPlaneBox(planeBox, pmv, viewport);
- }
};
static Shape makeShape(final Font font, final int renderModes) {
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01b.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01b.java
index 37ecac50c..106944449 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01b.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01b.java
@@ -36,7 +36,6 @@ import com.jogamp.graph.font.FontFactory;
import com.jogamp.graph.font.FontSet;
import com.jogamp.graph.ui.Scene;
import com.jogamp.graph.ui.Shape;
-import com.jogamp.graph.ui.Scene.PMVMatrixSetup;
import com.jogamp.graph.ui.shapes.Button;
import com.jogamp.graph.ui.shapes.GLButton;
import com.jogamp.newt.event.MouseEvent;
@@ -47,9 +46,7 @@ import com.jogamp.opengl.GL;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.demos.util.CommandlineOptions;
-import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
import com.jogamp.opengl.math.FloatUtil;
-import com.jogamp.opengl.math.Recti;
import com.jogamp.opengl.math.geom.AABBox;
import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.PMVMatrix;
@@ -58,7 +55,7 @@ import com.jogamp.opengl.util.PMVMatrix;
* Res independent Shape, Scene attached to GLWindow showing simple linear Shape movement.
* <p>
* This variation of {@link UISceneDemo00} uses a {@link GLButton} shape with animating and rotating gears
- * and sets up an own {@link Scene.PMVMatrixSetup} with a plane dimension of 100.
+ * using the default {@link Scene.PMVMatrixSetup}.
* </p>
* <p>
* Pass '-keep' to main-function to keep running after animation,
@@ -93,7 +90,6 @@ public class UISceneDemo01b {
final Scene scene = new Scene(options.graphAASamples);
scene.setClearParams(new float[] { 1f, 1f, 1f, 1f}, GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- scene.setPMVMatrixSetup(new MyPMVMatrixSetup());
scene.addShape(shape);
final Animator animator = new Animator(0 /* w/o AWT */);
@@ -218,23 +214,4 @@ public class UISceneDemo01b {
window.destroy();
}
}
-
- static class MyPMVMatrixSetup implements PMVMatrixSetup {
- @Override
- public void set(final PMVMatrix pmv, final Recti viewport) {
- final float ratio = (float)viewport.width()/(float)viewport.height();
- pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmv.glLoadIdentity();
- pmv.gluPerspective(Scene.DEFAULT_ANGLE, ratio, Scene.DEFAULT_ZNEAR, Scene.DEFAULT_ZFAR);
- pmv.glTranslatef(0f, 0f, Scene.DEFAULT_SCENE_DIST);
-
- pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
- pmv.glLoadIdentity();
- }
-
- @Override
- public void setPlaneBox(final AABBox planeBox, final PMVMatrix pmv, final Recti viewport) {
- Scene.getDefaultPMVMatrixSetup().setPlaneBox(planeBox, pmv, viewport);
- }
- };
}
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java
index 810fcdb87..b288ddb48 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java
@@ -44,7 +44,6 @@ import com.jogamp.graph.ui.Group;
import com.jogamp.graph.ui.Scene;
import com.jogamp.graph.ui.Shape;
import com.jogamp.graph.ui.AnimGroup;
-import com.jogamp.graph.ui.Scene.PMVMatrixSetup;
import com.jogamp.graph.ui.layout.Alignment;
import com.jogamp.graph.ui.layout.Gap;
import com.jogamp.graph.ui.layout.GridLayout;
@@ -70,15 +69,12 @@ import com.jogamp.opengl.JoglVersion;
import com.jogamp.opengl.demos.graph.FontSetDemos;
import com.jogamp.opengl.demos.util.CommandlineOptions;
import com.jogamp.opengl.demos.util.MiscUtils;
-import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
import com.jogamp.opengl.math.FloatUtil;
import com.jogamp.opengl.math.Quaternion;
-import com.jogamp.opengl.math.Recti;
import com.jogamp.opengl.math.Vec3f;
import com.jogamp.opengl.math.Vec4f;
import com.jogamp.opengl.math.geom.AABBox;
import com.jogamp.opengl.util.Animator;
-import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.opengl.util.av.GLMediaPlayer;
import com.jogamp.opengl.util.av.GLMediaPlayerFactory;
import com.jogamp.opengl.util.av.GLMediaPlayer.GLMediaEventListener;
@@ -184,7 +180,6 @@ public class UISceneDemo03 {
final Scene scene = new Scene(options.graphAASamples);
scene.setClearParams(new float[] { 1f, 1f, 1f, 1f }, GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- scene.setPMVMatrixSetup( new MyPMVMatrixSetup(Scene.DEFAULT_SCENE_DIST) );
scene.setDebugBorderBox(options.debugBoxThickness);
final AnimGroup animGroup = new AnimGroup(null);
@@ -817,32 +812,4 @@ public class UISceneDemo03 {
}
}
};
-
- /**
- * Our PMVMatrixSetup:
- * - gluPerspective like Scene's default
- * - no normal scale to 1, keep distance to near plane for rotation effects.
- */
- public static class MyPMVMatrixSetup implements PMVMatrixSetup {
- private final float scene_dist;
- public MyPMVMatrixSetup(final float scene_dist) {
- this.scene_dist = scene_dist;
- }
- @Override
- public void set(final PMVMatrix pmv, final Recti viewport) {
- final float ratio = (float) viewport.width() / (float) viewport.height();
- pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmv.glLoadIdentity();
- pmv.gluPerspective(Scene.DEFAULT_ANGLE, ratio, Scene.DEFAULT_ZNEAR, Scene.DEFAULT_ZFAR);
- pmv.glTranslatef(0f, 0f, scene_dist);
-
- pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
- pmv.glLoadIdentity();
- }
-
- @Override
- public void setPlaneBox(final AABBox planeBox, final PMVMatrix pmv, final Recti viewport) {
- Scene.getDefaultPMVMatrixSetup().setPlaneBox(planeBox, pmv, viewport);
- }
- };
}
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo10.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo10.java
index 2459cbbf6..00a4854a6 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo10.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo10.java
@@ -56,6 +56,7 @@ import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.demos.es2.GearsES2;
import com.jogamp.opengl.demos.util.CommandlineOptions;
+import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
import com.jogamp.opengl.math.Recti;
import com.jogamp.opengl.math.Vec3f;
import com.jogamp.opengl.math.geom.AABBox;
@@ -123,6 +124,7 @@ public class UISceneDemo10 {
// Scene for Shape ...
final Scene scene = new Scene(options.graphAASamples);
+ scene.setPMVMatrixSetup(new MyPMVMatrixSetup());
scene.setClearParams(new float[] { 1f, 1f, 1f, 1f}, GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
shape.onMove(new Shape.Listener() {
@@ -190,8 +192,7 @@ public class UISceneDemo10 {
// - Scale the shape to the sceneBox, i.e. normalizing to screen-size 1x1
scene.waitUntilDisplayed();
- final AABBox sceneBox = scene.getBounds();
- shape.scale(sceneBox.getWidth(), sceneBox.getWidth(), 1f); // scale shape to sceneBox
+ System.err.println("m1.1 Scene "+scene.getBounds());
System.err.println("m1.1 "+shape);
try { Thread.sleep(1000); } catch (final InterruptedException e1) { }
@@ -212,7 +213,7 @@ public class UISceneDemo10 {
@SuppressWarnings("unused")
static Shape makeShape(final Window window, final Font font, final int renderModes) {
- final float sw = 0.10f;
+ final float sw = 0.25f;
final float sh = sw / 2.5f;
if( false ) {
@@ -267,4 +268,21 @@ public class UISceneDemo10 {
return b;
}
}
+ static class MyPMVMatrixSetup extends Scene.DefaultPMVMatrixSetup {
+ @Override
+ public void set(final PMVMatrix pmv, final Recti viewport) {
+ super.set(pmv, viewport);
+
+ // Scale (back) to have normalized plane dimensions, 1 for the greater of width and height.
+ final AABBox planeBox0 = new AABBox();
+ setPlaneBox(planeBox0, pmv, viewport);
+ final float sx = planeBox0.getWidth();
+ final float sy = planeBox0.getHeight();
+ final float sxy = sx > sy ? sx : sy;
+ pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ pmv.glScalef(sxy, sxy, 1f);
+ pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ }
+ };
+
}
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo11.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo11.java
index 79e8c8271..eb5c4d3e2 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo11.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo11.java
@@ -48,6 +48,8 @@ import com.jogamp.opengl.GL;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.demos.util.CommandlineOptions;
+import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
+import com.jogamp.opengl.math.Recti;
import com.jogamp.opengl.math.geom.AABBox;
import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.PMVMatrix;
@@ -97,6 +99,7 @@ public class UISceneDemo11 {
groupA0.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; });
final Scene scene = new Scene(options.graphAASamples);
+ scene.setPMVMatrixSetup(new MyPMVMatrixSetup());
scene.setClearParams(new float[] { 1f, 1f, 1f, 1f}, GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
scene.addShape(groupA0);
scene.setFrustumCullingEnabled(true);
@@ -203,4 +206,20 @@ public class UISceneDemo11 {
window.destroy();
}
}
+ static class MyPMVMatrixSetup extends Scene.DefaultPMVMatrixSetup {
+ @Override
+ public void set(final PMVMatrix pmv, final Recti viewport) {
+ super.set(pmv, viewport);
+
+ // Scale (back) to have normalized plane dimensions, 1 for the greater of width and height.
+ final AABBox planeBox0 = new AABBox();
+ setPlaneBox(planeBox0, pmv, viewport);
+ final float sx = planeBox0.getWidth();
+ final float sy = planeBox0.getHeight();
+ final float sxy = sx > sy ? sx : sy;
+ pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ pmv.glScalef(sxy, sxy, 1f);
+ pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ }
+ };
}
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java
index 799933ba0..c9aa8078d 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java
@@ -48,7 +48,6 @@ import com.jogamp.graph.ui.GraphShape;
import com.jogamp.graph.ui.Group;
import com.jogamp.graph.ui.Scene;
import com.jogamp.graph.ui.Shape;
-import com.jogamp.graph.ui.Scene.PMVMatrixSetup;
import com.jogamp.graph.ui.layout.Alignment;
import com.jogamp.graph.ui.layout.Gap;
import com.jogamp.graph.ui.layout.GridLayout;
@@ -86,9 +85,7 @@ import com.jogamp.opengl.demos.graph.FontSetDemos;
import com.jogamp.opengl.demos.graph.MSAATool;
import com.jogamp.opengl.demos.util.CommandlineOptions;
import com.jogamp.opengl.demos.util.MiscUtils;
-import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
import com.jogamp.opengl.math.FloatUtil;
-import com.jogamp.opengl.math.Recti;
import com.jogamp.opengl.math.Vec3f;
import com.jogamp.opengl.math.geom.AABBox;
import com.jogamp.opengl.util.Animator;
@@ -311,8 +308,8 @@ public class UISceneDemo20 implements GLEventListener {
} catch (final URISyntaxException e1) {
throw new RuntimeException(e1);
}
- scene = new Scene();
- scene.setPMVMatrixSetup(new MyPMVMatrixSetup());
+ scene = new Scene(options.graphAASamples);
+ scene.setPMVMatrixSetup(new Scene.DefaultPMVMatrixSetup(-1f));
scene.getRenderer().setHintMask(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED);
// scene.setSampleCount(3); // easy on embedded devices w/ just 3 samples (default is 4)?
scene.setDebugBorderBox(options.debugBoxThickness);
@@ -1187,38 +1184,4 @@ public class UISceneDemo20 implements GLEventListener {
shapeEvent.shape.getRotation().rotateByEuler( rot.scale( 2f ) );
}
};
-
- /**
- * Our PMVMatrixSetup:
- * - gluPerspective like Scene's default
- * - no normal scale to 1, keep a longer distance to near plane for rotation effects. We scale Shapes
- */
- public static class MyPMVMatrixSetup implements PMVMatrixSetup {
- static float Z_DIST = -1f;
- @Override
- public void set(final PMVMatrix pmv, final Recti viewport) {
- final float ratio = (float)viewport.width()/(float)viewport.height();
- pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmv.glLoadIdentity();
- pmv.gluPerspective(Scene.DEFAULT_ANGLE, ratio, Scene.DEFAULT_ZNEAR, Scene.DEFAULT_ZFAR);
- pmv.glTranslatef(0f, 0f, Z_DIST);
-
- pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
- pmv.glLoadIdentity();
- }
-
- @Override
- public void setPlaneBox(final AABBox planeBox, final PMVMatrix pmv, final Recti viewport) {
- // Scene.getDefaultPMVMatrixSetup().setPlaneBox(planeBox, pmv, viewport);
- final float orthoDist = -Z_DIST; // Scene.DEFAULT_SCENE_DIST;
- final Vec3f obj00Coord = new Vec3f();
- final Vec3f obj11Coord = new Vec3f();
-
- Scene.winToPlaneCoord(pmv, viewport, Scene.DEFAULT_ZNEAR, Scene.DEFAULT_ZFAR, viewport.x(), viewport.y(), orthoDist, obj00Coord);
- Scene.winToPlaneCoord(pmv, viewport, Scene.DEFAULT_ZNEAR, Scene.DEFAULT_ZFAR, viewport.width(), viewport.height(), orthoDist, obj11Coord);
-
- planeBox.setSize( obj00Coord, obj11Coord );
- }
- };
-
}
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/Scene.java
index acde820f7..1de608d12 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Scene.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Scene.java
@@ -716,23 +716,20 @@ public final class Scene implements Container, GLEventListener {
* Custom implementations can be set via {@link Scene#setPMVMatrixSetup(PMVMatrixSetup)}.
* </p>
* <p>
- * 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>
+ * The default implementation is {@link Scene.DefaultPMVMatrixSetup}.
+ * @see DefaultPMVMatrixSetup
+ * @see Scene#setPMVMatrixSetup(PMVMatrixSetup)
*/
public static interface PMVMatrixSetup {
+ /** Returns scene distance on z-axis to projection. */
+ float getSceneDist();
+ /** Returns fov projection angle in radians, shall be {@code 0} for orthogonal projection. */
+ float getAngle();
+ /** Returns projection z-near value. */
+ float getZNear();
+ /** Returns projection z-far value. */
+ float getZFar();
+
/**
* Setup {@link PMVMatrix}'s {@link GLMatrixFunc#GL_PROJECTION} and {@link GLMatrixFunc#GL_MODELVIEW}.
* <p>
@@ -764,9 +761,6 @@ public final class Scene implements Container, 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; }
-
/**
* Setup {@link PMVMatrix} {@link GLMatrixFunc#GL_PROJECTION} and {@link GLMatrixFunc#GL_MODELVIEW}
* by calling {@link #getPMVMatrixSetup()}'s {@link PMVMatrixSetup#set(PMVMatrix, Recti)}.
@@ -1157,41 +1151,120 @@ public final class Scene implements Container, GLEventListener {
}
}
- private static final PMVMatrixSetup defaultPMVMatrixSetup = new PMVMatrixSetup() {
+ /**
+ * Default implementation of {@link Scene.PMVMatrixSetup},
+ * implementing {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti)} as follows:
+ * <ul>
+ * <li>{@link GLMatrixFunc#GL_PROJECTION} Matrix
+ * <ul>
+ * <li>Identity</li>
+ * <li>Perspective {@link #getAngle()} with {@link #getZNear()} and {@link #getZFar()}</li>
+ * <li>Translated to given {@link #getSceneDist()}</li>
+ * </ul></li>
+ * <li>{@link GLMatrixFunc#GL_MODELVIEW} Matrix
+ * <ul>
+ * <li>identity</li>
+ * </ul></li>
+ * </ul>
+ * </p>
+ * @see DefaultPMVMatrixSetup#DefaultPMVMatrixSetup()
+ * @see Scene#setPMVMatrixSetup(PMVMatrixSetup)
+ * @see Scene.PMVMatrixSetup
+ */
+ public static class DefaultPMVMatrixSetup implements PMVMatrixSetup {
+ /** Scene distance on z-axis to projection. */
+ private final float scene_dist;
+ /** Projection angle in radians. */
+ private final float angle;
+ /** Projection z-near value. */
+ private final float zNear;
+ /** Projection z-far value. */
+ private final float zFar;
+
+ /**
+ * Custom {@link DefaultPMVMatrixSetup} instance
+ * @param scene_dist scene distance on z-axix
+ * @param zNear projection z-near value
+ * @param zFar projection z-far value
+ * @param angle projection angle in radians
+ * @see DefaultPMVMatrixSetup
+ * @see Scene#setPMVMatrixSetup(PMVMatrixSetup)
+ * @see Scene.PMVMatrixSetup
+ */
+ public DefaultPMVMatrixSetup(final float scene_dist, final float zNear, final float zFar, final float angle) {
+ if( !( zNear > 0 && zFar > zNear ) ) {
+ throw new IllegalArgumentException("zNear is "+zNear+", but must be > 0 and < zFar, zFar "+zFar);
+ }
+ this.scene_dist = scene_dist;
+ this.zNear = zNear;
+ this.zFar = zFar;
+ this.angle = angle;
+ }
+ /**
+ * Custom {@link DefaultPMVMatrixSetup} instance using given {@code scene_dist}, {@code zNear}, {@code zFar} and {@link Scene#DEFAULT_ANGLE}.
+ * @param scene_dist scene distance on z-axix
+ * @param zNear projection z-near value
+ * @param zFar projection z-far value
+ * @see DefaultPMVMatrixSetup
+ * @see Scene#setPMVMatrixSetup(PMVMatrixSetup)
+ * @see Scene.PMVMatrixSetup
+ */
+ public DefaultPMVMatrixSetup(final float scene_dist, final float zNear, final float zFar) {
+ this(scene_dist, zNear, zFar, Scene.DEFAULT_ANGLE);
+ }
+ /**
+ * Custom {@link DefaultPMVMatrixSetup} instance using given {@code scene_dist} and {@link Scene#DEFAULT_ZNEAR}, {@link Scene#DEFAULT_ZFAR}, {@link Scene#DEFAULT_ANGLE}.
+ * @param scene_dist scene distance on z-axix
+ * @see DefaultPMVMatrixSetup
+ * @see Scene#setPMVMatrixSetup(PMVMatrixSetup)
+ * @see Scene.PMVMatrixSetup
+ */
+ public DefaultPMVMatrixSetup(final float scene_dist) {
+ this(scene_dist, Scene.DEFAULT_ZNEAR, Scene.DEFAULT_ZFAR, Scene.DEFAULT_ANGLE);
+ }
+ /**
+ * Default {@link DefaultPMVMatrixSetup} instance using {@link Scene#DEFAULT_SCENE_DIST}, {@link Scene#DEFAULT_ZNEAR}, {@link Scene#DEFAULT_ZFAR}, {@link Scene#DEFAULT_ANGLE}.
+ * @see DefaultPMVMatrixSetup
+ * @see Scene#setPMVMatrixSetup(PMVMatrixSetup)
+ * @see Scene.PMVMatrixSetup
+ */
+ public DefaultPMVMatrixSetup() {
+ this(Scene.DEFAULT_SCENE_DIST, Scene.DEFAULT_ZNEAR, Scene.DEFAULT_ZFAR, Scene.DEFAULT_ANGLE);
+ }
+
@Override
public void set(final PMVMatrix pmv, final Recti viewport) {
- final float ratio = (float)viewport.width()/(float)viewport.height();
+ final float ratio = (float) viewport.width() / (float) viewport.height();
pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
pmv.glLoadIdentity();
- pmv.gluPerspective(DEFAULT_ANGLE, ratio, DEFAULT_ZNEAR, DEFAULT_ZFAR);
- pmv.glTranslatef(0f, 0f, DEFAULT_SCENE_DIST);
+ pmv.gluPerspective(angle, ratio, zNear, zFar);
+ pmv.glTranslatef(0f, 0f, scene_dist);
pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
pmv.glLoadIdentity();
-
- // Scale (back) to have normalized plane dimensions, 1 for the greater of width and height.
- final AABBox planeBox0 = new AABBox();
- setPlaneBox(planeBox0, pmv, viewport);
- final float sx = planeBox0.getWidth();
- final float sy = planeBox0.getHeight();
- final float sxy = sx > sy ? sx : sy;
- pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmv.glScalef(sxy, sxy, 1f);
- pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
}
@Override
public void setPlaneBox(final AABBox planeBox, final PMVMatrix pmv, final Recti viewport) {
- final float orthoDist = -DEFAULT_SCENE_DIST;
- final Vec3f obj00Coord = new Vec3f();
- final Vec3f obj11Coord = new Vec3f();
+ final float orthoDist = -scene_dist;
+ final Vec3f obj00Coord = new Vec3f();
+ final Vec3f obj11Coord = new Vec3f();
- winToPlaneCoord(pmv, viewport, DEFAULT_ZNEAR, DEFAULT_ZFAR, viewport.x(), viewport.y(), orthoDist, obj00Coord);
- winToPlaneCoord(pmv, viewport, DEFAULT_ZNEAR, DEFAULT_ZFAR, viewport.width(), viewport.height(), orthoDist, obj11Coord);
+ winToPlaneCoord(pmv, viewport, zNear, zFar, viewport.x(), viewport.y(), orthoDist, obj00Coord);
+ winToPlaneCoord(pmv, viewport, zNear, zFar, viewport.width(), viewport.height(), orthoDist, obj11Coord);
- planeBox.setSize( obj00Coord, obj11Coord );
+ planeBox.setSize( obj00Coord, obj11Coord );
}
+
+ @Override
+ public float getSceneDist() { return scene_dist; }
+ @Override
+ public float getAngle() { return angle; }
+ @Override
+ public float getZNear() { return zNear; }
+ @Override
+ public float getZFar() { return zFar; }
};
- private PMVMatrixSetup pmvMatrixSetup = defaultPMVMatrixSetup;
+ private PMVMatrixSetup pmvMatrixSetup = new DefaultPMVMatrixSetup();
}