From 0b476231be5cf4a42e7030d7e0f88589811c1c88 Mon Sep 17 00:00:00 2001
From: Sven Gothel
- * The default implementation is described below - *
- *- * {@link GLMatrixFunc#GL_PROJECTION} is setup using perspective {@link Scene#DEFAULT_ANGLE} with {@link Scene#DEFAULT_ZNEAR} and {@link Scene#DEFAULT_ZFAR}. - *
- *- * Further {@link GLMatrixFunc#GL_MODELVIEW} is translated to given {@link Scene#DEFAULT_SCENE_DIST}. + * The default implementation is described below: + *
* Will be called by {@link Scene#reshape(GLAutoDrawable, int, int, int, int)} after {@link #set(PMVMatrix, int, int, int, int)}. *
- * @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}. *@@ -650,6 +664,9 @@ public final class Scene implements GLEventListener { *
* {@link AABBox} is setup via {@link #getPMVMatrixSetup()}'s {@link PMVMatrixSetup#setPlaneBox(AABBox, PMVMatrix, int, int, int, int)}. *
+ *+ * The default {@link PMVMatrixSetup} implementation scales to normalized plane dimensions, 1 for the greater of width and height. + *
*/ 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 -- cgit v1.2.3