diff options
author | Sven Gothel <[email protected]> | 2023-04-07 08:46:18 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-04-07 08:46:18 +0200 |
commit | 84a6d63205ec49ddfb36b57fe2888425ecda3a5a (patch) | |
tree | 354cec2ac14a8932a01122c5234926e774ef874e /src/graphui/classes/com/jogamp | |
parent | 10b60e10ece3cbc3e0b8a68ac73229371530e0ba (diff) |
PMVMatrix rewrite using Matrix4f, providing SyncMatrix4f* for GLUniformData; Utilize Vec3f, Recti, .. throughout API (Matrix4f, AABBox, .. Graph*)
Big Easter Cleanup
- Net -214 lines of code, despite new classes.
- GLUniformData buffer can be synced w/ underlying data via SyncAction/SyncBuffer, e.g. SyncMatrix4f + SyncMatrices4f
- PMVMatrix rewrite using Matrix4f and providing SyncMatrix4f/Matrices4f to sync w/ GLUniformData
- Additional SyncMatrix4f16 + SyncMatrices4f16 covering Matrix4f sync w/ GLUniformData w/o PMVMatrix
- Utilize Vec3f, Recti, .. throughout API (Matrix4f, AABBox, .. Graph*)
- Moved FloatUtil -> Matrix4f, kept a few basic matrix ops for ProjectFloat
- Most, if not all, float[] and int[] should have been moved to proper classes
- int[] -> Recti for viewport rectangle
- Matrix4f and PMVMatrix is covered by math unit tests (as was FloatUtil before) -> save
Passed all unit tests on AMD64 GNU/Linux
Diffstat (limited to 'src/graphui/classes/com/jogamp')
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Group.java | 10 | ||||
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Scene.java | 122 | ||||
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Shape.java | 130 |
3 files changed, 117 insertions, 145 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Group.java b/src/graphui/classes/com/jogamp/graph/ui/Group.java index 8174b279c..cfc8dd534 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Group.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Group.java @@ -159,7 +159,7 @@ public class Group extends Shape implements Container { pmv.glPushMatrix(); shape.setTransform(pmv); - if( !doFrustumCulling || !pmv.glGetFrustum().isAABBoxOutside( shape.getBounds() ) ) { + if( !doFrustumCulling || !pmv.getFrustum().isAABBoxOutside( shape.getBounds() ) ) { if( null == rgba ) { shape.drawToSelect(gl, renderer, sampleCount); } else { @@ -177,8 +177,6 @@ public class Group extends Shape implements Container { layout(); final PMVMatrix pmv = new PMVMatrix(); final AABBox tmpBox = new AABBox(); - final float[] vec3Tmp0 = new float[3]; - final float[] vec3Tmp1 = new float[3]; for(final Shape s : shapes) { // s.validateImpl(glp, gl); if( null != gl ) { @@ -188,7 +186,7 @@ public class Group extends Shape implements Container { } pmv.glPushMatrix(); s.setTransform(pmv); - s.getBounds().transformMv(tmpBox, pmv, vec3Tmp0, vec3Tmp0); + s.getBounds().transformMv(pmv, tmpBox); pmv.glPopMatrix(); box.resize(tmpBox); } @@ -218,10 +216,8 @@ public class Group extends Shape implements Container { if( null == shape ) { return res; } - final float[] vec3Tmp0 = new float[3]; - final float[] vec3Tmp1 = new float[3]; forOne(pmv, shape, () -> { - shape.getBounds().transformMv(res, pmv, vec3Tmp0, vec3Tmp1); + shape.getBounds().transformMv(pmv, res); }); return res; } diff --git a/src/graphui/classes/com/jogamp/graph/ui/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/Scene.java index ac3bbe146..e1ee538ab 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Scene.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Scene.java @@ -60,6 +60,8 @@ import com.jogamp.newt.event.GestureHandler.GestureEvent; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.math.FloatUtil; import com.jogamp.opengl.math.Ray; +import com.jogamp.opengl.math.Recti; +import com.jogamp.opengl.math.Vec2f; import com.jogamp.opengl.math.Vec3f; import com.jogamp.opengl.math.geom.AABBox; import com.jogamp.opengl.util.GLPixelStorageModes; @@ -178,7 +180,7 @@ public final class Scene implements Container, GLEventListener { /** Returns the {@link GL#glClear(int) glClear(..)} mask, see {@link #setClearParams(float[], int)}. */ public final int getClearMask() { return clearMask; } - /** Enable or disable {@link PMVMatrix#glGetFrustum()} culling per {@link Shape}. Default is disabled. */ + /** Enable or disable {@link PMVMatrix#getFrustum()} culling per {@link Shape}. Default is disabled. */ public final void setFrustumCullingEnabled(final boolean v) { doFrustumCulling = v; } /** Return whether {@link #setFrustumCullingEnabled(boolean) frustum culling} is enabled. */ @@ -324,8 +326,8 @@ public final class Scene implements Container, GLEventListener { public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { renderer.reshapeNotify(x, y, width, height); - setupMatrix(renderer.getMatrix(), x, y, width, height); - pmvMatrixSetup.setPlaneBox(planeBox, renderer.getMatrix(), x, y, width, height); + setupMatrix(renderer.getMatrix(), renderer.getViewport()); + pmvMatrixSetup.setPlaneBox(planeBox, renderer.getMatrix(), renderer.getViewport()); } @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -374,7 +376,7 @@ public final class Scene implements Container, GLEventListener { pmv.glPushMatrix(); shape.setTransform(pmv); - if( !doFrustumCulling || !pmv.glGetFrustum().isAABBoxOutside( shape.getBounds() ) ) { + if( !doFrustumCulling || !pmv.getFrustum().isAABBoxOutside( shape.getBounds() ) ) { if( glSelect ) { final float color = ( i + 1f ) / ( shapeCount + 2f ); // FIXME @@ -452,7 +454,7 @@ public final class Scene implements Container, GLEventListener { * <p> * Method performs on current thread and returns after probing every {@link Shape}. * </p> - * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, int, int, int, int) be setup}, + * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) be setup}, * {@link Shape#setTransform(PMVMatrix) shape-transformed} and can be reused by the caller and runnable. * @param glWinX window X coordinate, bottom-left origin * @param glWinY window Y coordinate, bottom-left origin @@ -471,7 +473,7 @@ public final class Scene implements Container, GLEventListener { gl.glReadPixels( x, y, 1, 1, GL2ES2.GL_DEPTH_COMPONENT, GL.GL_FLOAT, winZRB); winZ1 = winZRB.get(0); // dir */ - final int[] viewport = getViewport(); + final Recti viewport = getViewport(); final Ray ray = new Ray(); shape[0] = null; @@ -494,9 +496,6 @@ public final class Scene implements Container, GLEventListener { }); return shape[0]; } - private final float[] dpyTmp1V3 = new float[3]; - private final float[] dpyTmp2V3 = new float[3]; - private final float[] dpyTmp3V3 = new float[3]; /** * Attempt to pick a {@link Shape} using the OpenGL false color rendering. @@ -579,7 +578,7 @@ public final class Scene implements Container, GLEventListener { * @param shape * @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}, + * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) be setup}, * {@link Shape#setTransform(PMVMatrix) shape-transformed} and can be reused by the caller and runnable. * @param objPos resulting object position * @param runnable action @@ -588,7 +587,7 @@ public final class Scene implements Container, GLEventListener { if( null == shape ) { return; } - final int[] viewport = getViewport(); + final Recti viewport = getViewport(); setupMatrix(pmv); forOne(pmv, shape, () -> { if( null != shape.winToShapeCoord(pmv, viewport, glWinX, glWinY, objPos) ) { @@ -605,7 +604,7 @@ public final class Scene implements Container, GLEventListener { } setupMatrix(pmv); forOne(pmv, shape, () -> { - shape.getBounds().transformMv(res, pmv, new float[3], new float[3]); + shape.getBounds().transformMv(pmv, res); }); return res; } @@ -660,7 +659,7 @@ public final class Scene implements Container, GLEventListener { } /** - * Interface providing {@link #set(PMVMatrix, int, int, int, int) a method} to + * Interface providing {@link #set(PMVMatrix, Recti) a method} to * setup {@link PMVMatrix}'s {@link GLMatrixFunc#GL_PROJECTION} and {@link GLMatrixFunc#GL_MODELVIEW}. * <p> * At the end of operations, the {@link GLMatrixFunc#GL_MODELVIEW} matrix has to be selected. @@ -699,26 +698,20 @@ public final class Scene implements Container, GLEventListener { * At the end of operations, the {@link GLMatrixFunc#GL_MODELVIEW} matrix is selected. * </p> * @param pmv the {@link PMVMatrix} to setup - * @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 + * @param viewport Rect4i viewport */ - void set(PMVMatrix pmv, final int x, final int y, final int width, final int height); + void set(PMVMatrix pmv, Recti viewport); /** * Optional method to set the {@link Scene#getBounds()} {@link AABBox}, maybe a {@code nop} if not desired. * <p> - * Will be called by {@link Scene#reshape(GLAutoDrawable, int, int, int, int)} after {@link #set(PMVMatrix, int, int, int, int)}. + * Will be called by {@link Scene#reshape(GLAutoDrawable, int, int, int, int)} after {@link #set(PMVMatrix, Recti)}. * </p> * @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 + * @param pmv the {@link PMVMatrix}, already setup via {@link #set(PMVMatrix, Recti)}. + * @param viewport Rect4i viewport */ - void setPlaneBox(final AABBox planeBox, final PMVMatrix pmv, int x, int y, final int width, final int height); + void setPlaneBox(final AABBox planeBox, final PMVMatrix pmv, Recti viewport); } /** Return the default or {@link #setPMVMatrixSetup(PMVMatrixSetup)} {@link PMVMatrixSetup}. */ @@ -732,32 +725,29 @@ public final class Scene implements Container, GLEventListener { /** * Setup {@link PMVMatrix} {@link GLMatrixFunc#GL_PROJECTION} and {@link GLMatrixFunc#GL_MODELVIEW} - * by calling {@link #getPMVMatrixSetup()}'s {@link PMVMatrixSetup#set(PMVMatrix, int, int, int, int)}. + * by calling {@link #getPMVMatrixSetup()}'s {@link PMVMatrixSetup#set(PMVMatrix, Recti)}. * @param pmv the {@link PMVMatrix} to setup - * @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 + * @param Recti viewport */ - public void setupMatrix(final PMVMatrix pmv, final int x, final int y, final int width, final int height) { - pmvMatrixSetup.set(pmv, x, y, width, height); + public void setupMatrix(final PMVMatrix pmv, final Recti viewport) { + pmvMatrixSetup.set(pmv, viewport); } /** * Setup {@link PMVMatrix} {@link GLMatrixFunc#GL_PROJECTION} and {@link GLMatrixFunc#GL_MODELVIEW} - * using implicit {@link #getViewport()} surface dimension by calling {@link #getPMVMatrixSetup()}'s {@link PMVMatrixSetup#set(PMVMatrix, int, int, int, int)}. + * using implicit {@link #getViewport()} surface dimension by calling {@link #getPMVMatrixSetup()}'s {@link PMVMatrixSetup#set(PMVMatrix, Recti)}. * @param pmv the {@link PMVMatrix} to setup */ public void setupMatrix(final PMVMatrix pmv) { - final int[] viewport = renderer.getViewport(); - setupMatrix(pmv, viewport[0], viewport[1], viewport[2], viewport[3]); + final Recti viewport = renderer.getViewport(); + setupMatrix(pmv, viewport); } /** Copies the current int[4] viewport in given target and returns it for chaining. It is set after initial {@link #reshape(GLAutoDrawable, int, int, int, int)}. */ - public final int[/*4*/] getViewport(final int[/*4*/] target) { return renderer.getViewport(target); } + public final Recti getViewport(final Recti target) { return renderer.getViewport(target); } /** Borrows the current int[4] viewport w/o copying. It is set after initial {@link #reshape(GLAutoDrawable, int, int, int, int)}. */ - public int[/*4*/] getViewport() { return renderer.getViewport(); } + public Recti getViewport() { return renderer.getViewport(); } /** Returns the {@link #getViewport()}'s width, set after initial {@link #reshape(GLAutoDrawable, int, int, int, int)}. */ public int getWidth() { return renderer.getWidth(); } @@ -776,7 +766,7 @@ public final class Scene implements Container, GLEventListener { * {@link AABBox#getWidth()} and {@link AABBox#getHeight()} define scene's dimension covered by surface size. * </p> * <p> - * {@link AABBox} is setup via {@link #getPMVMatrixSetup()}'s {@link PMVMatrixSetup#setPlaneBox(AABBox, PMVMatrix, int, int, int, int)}. + * {@link AABBox} is setup via {@link #getPMVMatrixSetup()}'s {@link PMVMatrixSetup#setPlaneBox(AABBox, PMVMatrix, Recti)}. * </p> * <p> * The default {@link PMVMatrixSetup} implementation scales to normalized plane dimensions, 1 for the greater of width and height. @@ -796,12 +786,12 @@ public final class Scene implements Container, GLEventListener { * @param objPos float[3] storage for object coord result * @param winZ */ - public static void winToPlaneCoord(final PMVMatrix pmv, final int[] viewport, + public static void winToPlaneCoord(final PMVMatrix pmv, final Recti viewport, final float zNear, final float zFar, final float winX, final float winY, final float objOrthoZ, - final float[] objPos) { + final Vec3f objPos) { final float winZ = FloatUtil.getOrthoWinZ(objOrthoZ, zNear, zFar); - pmv.gluUnProject(winX, winY, winZ, viewport, 0, objPos, 0); + pmv.gluUnProject(winX, winY, winZ, viewport, objPos); } /** @@ -811,19 +801,19 @@ public final class Scene implements Container, GLEventListener { * @param zNear custom {@link #DEFAULT_ZNEAR} * @param zFar custom {@link #DEFAULT_ZFAR} * @param objOrthoDist custom {@link #DEFAULT_SCENE_DIST} - * @param objSceneSize float[2] storage for object surface size result + * @param objSceneSize Vec2f storage for object surface size result */ - public void surfaceToPlaneSize(final int[] viewport, final float zNear, final float zFar, final float objOrthoDist, final float[/*2*/] objSceneSize) { + public void surfaceToPlaneSize(final Recti viewport, final float zNear, final float zFar, final float objOrthoDist, final Vec2f objSceneSize) { final PMVMatrix pmv = new PMVMatrix(); - setupMatrix(pmv, viewport[0], viewport[1], viewport[2], viewport[3]); + setupMatrix(pmv, viewport); { - final float[] obj00Coord = new float[3]; - final float[] obj11Coord = new float[3]; + final Vec3f obj00Coord = new Vec3f(); + final Vec3f obj11Coord = new Vec3f(); - winToPlaneCoord(pmv, viewport, DEFAULT_ZNEAR, DEFAULT_ZFAR, viewport[0], viewport[1], objOrthoDist, obj00Coord); - winToPlaneCoord(pmv, viewport, DEFAULT_ZNEAR, DEFAULT_ZFAR, viewport[2], viewport[3], objOrthoDist, obj11Coord); - objSceneSize[0] = obj11Coord[0] - obj00Coord[0]; - objSceneSize[1] = obj11Coord[1] - obj00Coord[1]; + winToPlaneCoord(pmv, viewport, DEFAULT_ZNEAR, DEFAULT_ZFAR, viewport.x(), viewport.y(), objOrthoDist, obj00Coord); + winToPlaneCoord(pmv, viewport, DEFAULT_ZNEAR, DEFAULT_ZFAR, viewport.width(), viewport.height(), objOrthoDist, obj11Coord); + objSceneSize.set( obj11Coord.x() - obj00Coord.x(), + obj11Coord.y() - obj00Coord.y() ); } } @@ -831,9 +821,9 @@ public final class Scene implements Container, GLEventListener { * Map given window surface-size to object coordinates relative to this scene using * the default {@link PMVMatrixSetup}, i.e. {@link #DEFAULT_ZNEAR}, {@link #DEFAULT_ZFAR} and {@link #DEFAULT_SCENE_DIST} * @param viewport viewport rectangle - * @param objSceneSize float[2] storage for object surface size result + * @param objSceneSize Vec2f storage for object surface size result */ - public void surfaceToPlaneSize(final int[] viewport, final float[/*2*/] objSceneSize) { + public void surfaceToPlaneSize(final Recti viewport, final Vec2f objSceneSize) { surfaceToPlaneSize(viewport, DEFAULT_ZNEAR, DEFAULT_ZFAR, -DEFAULT_SCENE_DIST, objSceneSize); } @@ -1090,8 +1080,8 @@ public final class Scene implements Container, GLEventListener { 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; + 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(DEFAULT_ANGLE, ratio, DEFAULT_ZNEAR, DEFAULT_ZFAR); @@ -1102,7 +1092,7 @@ public final class Scene implements Container, GLEventListener { // 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); + setPlaneBox(planeBox0, pmv, viewport); final float sx = planeBox0.getWidth(); final float sy = planeBox0.getHeight(); final float sxy = sx > sy ? sx : sy; @@ -1112,21 +1102,15 @@ public final class Scene implements Container, GLEventListener { } @Override - public void setPlaneBox(final AABBox planeBox, final PMVMatrix pmv, final int x, final int y, final int width, final int height) { + public void setPlaneBox(final AABBox planeBox, final PMVMatrix pmv, final Recti viewport) { 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, 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 - obj00Coord[2], // lz - obj11Coord[0], // hx - obj11Coord[1], // hy - obj11Coord[2] );// hz } + 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); + + planeBox.setSize( obj00Coord, obj11Coord ); } }; private PMVMatrixSetup pmvMatrixSetup = defaultPMVMatrixSetup; diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java index 658d7848d..5e7201bdc 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java @@ -44,6 +44,7 @@ import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.event.MouseListener; import com.jogamp.opengl.math.FloatUtil; import com.jogamp.opengl.math.Quaternion; +import com.jogamp.opengl.math.Recti; import com.jogamp.opengl.math.Vec2f; import com.jogamp.opengl.math.Vec3f; import com.jogamp.opengl.math.geom.AABBox; @@ -515,23 +516,20 @@ public abstract class Shape { * @param viewport the int[4] viewport * @param surfaceSize int[2] target surface size * @return given int[2] {@code surfaceSize} for successful gluProject(..) operation, otherwise {@code null} - * @see #getSurfaceSize(com.jogamp.graph.ui.Scene.PMVMatrixSetup, int[], PMVMatrix, int[]) + * @see #getSurfaceSize(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, PMVMatrix, int[]) * @see #getSurfaceSize(Scene, PMVMatrix, int[]) */ - public int[/*2*/] getSurfaceSize(final PMVMatrix pmv, final int[/*4*/] viewport, final int[/*2*/] surfaceSize) { + public int[/*2*/] getSurfaceSize(final PMVMatrix pmv, final Recti 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]; + final Vec3f winCoordHigh = new Vec3f(); + final Vec3f winCoordLow = new Vec3f(); final Vec3f high = box.getHigh(); final Vec3f low = box.getLow(); - if( pmv.gluProject(high.x(), high.y(), high.z(), viewport, 0, winCoordHigh, 0) ) { - // System.err.printf("Shape::surfaceSize.H: shape %d: obj [%f, %f, %f] -> win [%f, %f, %f]%n", getName(), high[0], high[1], high[2], winCoordHigh[0], winCoordHigh[1], winCoordHigh[2]); - if( pmv.gluProject(low.x(), low.y(), low.z(), viewport, 0, winCoordLow, 0) ) { - // System.err.printf("Shape::surfaceSize.L: shape %d: obj [%f, %f, %f] -> win [%f, %f, %f]%n", getName(), low[0], low[1], low[2], winCoordLow[0], winCoordLow[1], winCoordLow[2]); - 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]); + if( pmv.gluProject(high, viewport, winCoordHigh) ) { + if( pmv.gluProject(low, viewport, winCoordLow) ) { + surfaceSize[0] = (int)(winCoordHigh.x() - winCoordLow.x()); + surfaceSize[1] = (int)(winCoordHigh.y() - winCoordLow.y()); return surfaceSize; } } @@ -541,20 +539,20 @@ public abstract class Shape { /** * 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 + * The given {@link PMVMatrix} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) setup} properly for this shape * including this shape's {@link #setTransform(PMVMatrix)}. * </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#gluProject(float, float, float, int[], int, float[], int)} - * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, int, int, int, int) be setup}, + * @param pmvMatrixSetup {@link Scene.PMVMatrixSetup} to {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) setup} given {@link PMVMatrix} {@code pmv}. + * @param viewport used viewport for {@link PMVMatrix#gluProject(float, float, float, int[], float[])} + * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) 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(PMVMatrix, Recti, int[]) * @see #getSurfaceSize(Scene, PMVMatrix, int[]) */ - 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]); + public int[/*2*/] getSurfaceSize(final Scene.PMVMatrixSetup pmvMatrixSetup, final Recti viewport, final PMVMatrix pmv, final int[/*2*/] surfaceSize) { + pmvMatrixSetup.set(pmv, viewport); setTransform(pmv); return getSurfaceSize(pmv, viewport, surfaceSize); } @@ -562,16 +560,16 @@ public abstract class Shape { /** * 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 + * The given {@link PMVMatrix} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) 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}, + * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) 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.Scene.PMVMatrixSetup, int[], PMVMatrix, int[]) + * @see #getSurfaceSize(PMVMatrix, Recti, int[]) + * @see #getSurfaceSize(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, PMVMatrix, int[]) */ public int[/*2*/] getSurfaceSize(final Scene scene, final PMVMatrix pmv, final int[/*2*/] surfaceSize) { return getSurfaceSize(scene.getPMVMatrixSetup(), scene.getViewport(), pmv, surfaceSize); @@ -580,11 +578,11 @@ public abstract class Shape { /** * Retrieve pixel per scaled shape-coordinate unit, i.e. [px]/[obj]. * <p> - * The given {@link PMVMatrix} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix, int, int, int, int) setup} properly for this shape + * The given {@link PMVMatrix} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) 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}, + * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) be setup}, * {@link #setTransform(PMVMatrix) shape-transformed} and can be reused by the caller. * @param pixPerShape float[2] pixel per scaled shape-coordinate unit result storage * @return given float[2] {@code pixPerShape} for successful gluProject(..) operation, otherwise {@code null} @@ -604,11 +602,11 @@ public abstract class Shape { /** * Retrieve pixel per scaled shape-coordinate unit, i.e. [px]/[obj]. - * @param shapeSizePx int[2] shape size in pixel as retrieved via e.g. {@link #getSurfaceSize(com.jogamp.graph.ui.Scene.PMVMatrixSetup, int[], PMVMatrix, int[])} + * @param shapeSizePx int[2] shape size in pixel as retrieved via e.g. {@link #getSurfaceSize(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, PMVMatrix, int[])} * @param pixPerShape float[2] pixel scaled per shape-coordinate unit result storage * @return given float[2] {@code pixPerShape} * @see #getPixelPerShapeUnit(Scene, PMVMatrix, float[]) - * @see #getSurfaceSize(com.jogamp.graph.ui.Scene.PMVMatrixSetup, int[], PMVMatrix, int[]) + * @see #getSurfaceSize(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, PMVMatrix, int[]) * @see #getScaledWidth() * @see #getScaledHeight() */ @@ -626,22 +624,20 @@ public abstract class Shape { * including this shape's {@link #setTransform(PMVMatrix)}. * </p> * @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 viewport the viewport * @param objPos object position relative to this shape's center * @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(com.jogamp.graph.ui.Scene.PMVMatrixSetup, int[], float[], PMVMatrix, int[]) + * @see #shapeToWinCoord(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, float[], PMVMatrix, int[]) * @see #shapeToWinCoord(Scene, float[], PMVMatrix, int[]) */ - public int[/*2*/] shapeToWinCoord(final PMVMatrix pmv, final int[/*4*/] viewport, final Vec3f objPos, final int[/*2*/] glWinPos) { + public int[/*2*/] shapeToWinCoord(final PMVMatrix pmv, final Recti viewport, final Vec3f 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]; + final Vec3f winCoord = new Vec3f(); - if( pmv.gluProject(objPos.x(), objPos.y(), objPos.z(), viewport, 0, winCoord, 0) ) { - // System.err.printf("Shape::objToWinCoord.0: shape %d: obj [%f, %f, %f] -> win [%f, %f, %f]%n", getName(), objPos[0], objPos[1], objPos[2], winCoord[0], winCoord[1], winCoord[2]); - 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]); + if( pmv.gluProject(objPos, viewport, winCoord) ) { + glWinPos[0] = (int)(winCoord.x()); + glWinPos[1] = (int)(winCoord.y()); return glWinPos; } return null; @@ -650,21 +646,21 @@ public abstract class Shape { /** * 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 + * The given {@link PMVMatrix} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) setup} properly for this shape * including this shape's {@link #setTransform(PMVMatrix)}. * </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#gluProject(float, float, float, int[], int, float[], int)} + * @param pmvMatrixSetup {@link Scene.PMVMatrixSetup} to {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) setup} given {@link PMVMatrix} {@code pmv}. + * @param viewport used viewport for {@link PMVMatrix#gluProject(Vec3f, Recti, Vec3f)} * @param objPos 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}, + * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) 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(PMVMatrix, Recti, float[], int[]) * @see #shapeToWinCoord(Scene, float[], PMVMatrix, int[]) */ - public int[/*2*/] shapeToWinCoord(final Scene.PMVMatrixSetup pmvMatrixSetup, final int[/*4*/] viewport, final Vec3f objPos, final PMVMatrix pmv, final int[/*2*/] glWinPos) { - pmvMatrixSetup.set(pmv, viewport[0], viewport[1], viewport[2], viewport[3]); + public int[/*2*/] shapeToWinCoord(final Scene.PMVMatrixSetup pmvMatrixSetup, final Recti viewport, final Vec3f objPos, final PMVMatrix pmv, final int[/*2*/] glWinPos) { + pmvMatrixSetup.set(pmv, viewport); setTransform(pmv); return this.shapeToWinCoord(pmv, viewport, objPos, glWinPos); } @@ -672,17 +668,17 @@ public abstract class Shape { /** * 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 + * The given {@link PMVMatrix} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) 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 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}, + * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) 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.Scene.PMVMatrixSetup, int[], float[], PMVMatrix, int[]) + * @see #shapeToWinCoord(PMVMatrix, Recti, float[], int[]) + * @see #shapeToWinCoord(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, float[], PMVMatrix, int[]) */ public int[/*2*/] shapeToWinCoord(final Scene scene, final Vec3f objPos, final PMVMatrix pmv, final int[/*2*/] glWinPos) { return this.shapeToWinCoord(scene.getPMVMatrixSetup(), scene.getViewport(), objPos, pmv, glWinPos); @@ -696,24 +692,20 @@ public abstract class Shape { * including this shape's {@link #setTransform(PMVMatrix)}. * </p> * @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 viewport the Rect4i viewport * @param glWinX in GL window coordinates, origin bottom-left * @param glWinY in GL window coordinates, origin bottom-left * @param objPos target object position of glWinX/glWinY relative to this shape * @return given {@code objPos} for successful gluProject(..) and gluUnProject(..) operation, otherwise {@code null} - * @see #winToShapeCoord(com.jogamp.graph.ui.Scene.PMVMatrixSetup, int[], int, int, PMVMatrix, float[]) + * @see #winToShapeCoord(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, int, int, PMVMatrix, float[]) * @see #winToShapeCoord(Scene, int, int, PMVMatrix, float[]) */ - public Vec3f winToShapeCoord(final PMVMatrix pmv, final int[/*4*/] viewport, final int glWinX, final int glWinY, final Vec3f objPos) { + public Vec3f winToShapeCoord(final PMVMatrix pmv, final Recti viewport, final int glWinX, final int glWinY, final Vec3f objPos) { final Vec3f ctr = box.getCenter(); - final float[] tmp = new float[3]; - - if( pmv.gluProject(ctr.x(), ctr.y(), ctr.z(), viewport, 0, tmp, 0) ) { - // 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]); - final float winZ = tmp[2]; - if( pmv.gluUnProject(glWinX, glWinY, winZ, viewport, 0, objPos.get(tmp), 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]); - objPos.set(tmp); + + if( pmv.gluProject(ctr, viewport, objPos) ) { + final float winZ = objPos.z(); + if( pmv.gluUnProject(glWinX, glWinY, winZ, viewport, objPos) ) { return objPos; } } @@ -723,22 +715,22 @@ public abstract class Shape { /** * 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 + * The given {@link PMVMatrix} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) setup} properly for this shape * including this shape's {@link #setTransform(PMVMatrix)}. * </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 pmvMatrixSetup {@link Scene.PMVMatrixSetup} to {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) setup} given {@link PMVMatrix} {@code pmv}. + * @param viewport used viewport for {@link PMVMatrix#gluUnProject(float, float, float, Recti, Vec3f)} * @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}, + * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) be setup}, * {@link #setTransform(PMVMatrix) shape-transformed} and can be reused by the caller. * @param objPos target object position of glWinX/glWinY relative to this shape * @return given {@code objPos} for successful gluProject(..) and gluUnProject(..) operation, otherwise {@code null} - * @see #winToShapeCoord(PMVMatrix, int[], int, int, float[]) + * @see #winToShapeCoord(PMVMatrix, Recti, int, int, float[]) * @see #winToShapeCoord(Scene, int, int, PMVMatrix, float[]) */ - public Vec3f winToShapeCoord(final Scene.PMVMatrixSetup pmvMatrixSetup, final int[/*4*/] viewport, final int glWinX, final int glWinY, final PMVMatrix pmv, final Vec3f objPos) { - pmvMatrixSetup.set(pmv, viewport[0], viewport[1], viewport[2], viewport[3]); + public Vec3f winToShapeCoord(final Scene.PMVMatrixSetup pmvMatrixSetup, final Recti viewport, final int glWinX, final int glWinY, final PMVMatrix pmv, final Vec3f objPos) { + pmvMatrixSetup.set(pmv, viewport); setTransform(pmv); return this.winToShapeCoord(pmv, viewport, glWinX, glWinY, objPos); } @@ -746,18 +738,18 @@ public abstract class Shape { /** * 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 + * The given {@link PMVMatrix} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) 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}, + * @param pmv a new {@link PMVMatrix} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix, Recti) be setup}, * {@link #setTransform(PMVMatrix) shape-transformed} and can be reused by the caller. * @param objPos target object position of glWinX/glWinY relative to this shape * @return given {@code objPos} for successful gluProject(..) and gluUnProject(..) operation, otherwise {@code null} - * @see #winToShapeCoord(PMVMatrix, int[], int, int, float[]) - * @see #winToShapeCoord(com.jogamp.graph.ui.Scene.PMVMatrixSetup, int[], int, int, PMVMatrix, float[]) + * @see #winToShapeCoord(PMVMatrix, Recti, int, int, float[]) + * @see #winToShapeCoord(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, int, int, PMVMatrix, float[]) */ public Vec3f winToShapeCoord(final Scene scene, final int glWinX, final int glWinY, final PMVMatrix pmv, final Vec3f objPos) { return this.winToShapeCoord(scene.getPMVMatrixSetup(), scene.getViewport(), glWinX, glWinY, pmv, objPos); @@ -1182,7 +1174,7 @@ public abstract class Shape { * @param viewport the viewport * @param objPos object position of mouse event relative to this shape */ - /* pp */ final void dispatchGestureEvent(final GestureEvent e, final int glWinX, final int glWinY, final PMVMatrix pmv, final int[] viewport, final Vec3f objPos) { + /* pp */ final void dispatchGestureEvent(final GestureEvent e, final int glWinX, final int glWinY, final PMVMatrix pmv, final Recti viewport, final Vec3f objPos) { if( interactive && resizable && e instanceof PinchToZoomGesture.ZoomEvent ) { final PinchToZoomGesture.ZoomEvent ze = (PinchToZoomGesture.ZoomEvent) e; final float pixels = ze.getDelta() * ze.getScale(); // |