diff options
author | Sven Gothel <[email protected]> | 2023-08-01 13:59:02 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-08-01 13:59:02 +0200 |
commit | 7d9bfe58e6ef48e5c7d3da322dbc558285791af9 (patch) | |
tree | 26718bebe42667f54b93527cdc3460aca83c2077 /src/graphui/classes/com | |
parent | b2e62fee23dcb8cfab4293fd5bfefcf22cdd2b14 (diff) |
GraphUI: Add Shape.getSurfacePort(..): Similar to getSurfaceSize(..) but returns the whole Recti viewport of the shape
Diffstat (limited to 'src/graphui/classes/com')
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Shape.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java index ba1e50b1c..0a68cfaf1 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java @@ -588,6 +588,37 @@ public abstract class Shape { } /** + * Retrieve surface (view) port of this shape, i.e. lower x/y position and size. + * <p> + * The given {@link PMVMatrix} has to be setup properly for this object, + * i.e. its {@link GLMatrixFunc#GL_PROJECTION} and {@link GLMatrixFunc#GL_MODELVIEW} for the surrounding scene + * 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 surfacePort Recti target surface port + * @return given Recti {@code surfacePort} for successful gluProject(..) operation, otherwise {@code null} + */ + public Recti getSurfacePort(final PMVMatrix pmv, final Recti viewport, final Recti surfacePort) { + final Vec3f winCoordHigh = new Vec3f(); + final Vec3f winCoordLow = new Vec3f(); + final Vec3f high = box.getHigh(); + final Vec3f low = box.getLow(); + + final Matrix4f matPMv = pmv.getPMvMat(); + if( Matrix4f.mapObjToWin(high, matPMv, viewport, winCoordHigh) ) { + if( Matrix4f.mapObjToWin(low, matPMv, viewport, winCoordLow) ) { + surfacePort.setX( (int)Math.abs( winCoordLow.x() ) ); + surfacePort.setY( (int)Math.abs( winCoordLow.y() ) ); + surfacePort.setWidth( (int)Math.abs( winCoordHigh.x() - winCoordLow.x() ) ); + surfacePort.setHeight( (int)Math.abs( winCoordHigh.y() - winCoordLow.y() ) ); + return surfacePort; + } + } + return null; + } + + /** * Retrieve surface (view) size of this shape. * <p> * The given {@link PMVMatrix} has to be setup properly for this object, |