diff options
author | Sven Gothel <[email protected]> | 2023-04-08 20:23:09 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-04-08 20:23:09 +0200 |
commit | 003eb8ca1f296f287dc3d224fa19781705e10dd9 (patch) | |
tree | 22e15bd8f0a58fd3a807dcb67b416d4d13d7e2b4 /src/graphui | |
parent | fc93a9aca67d0c4a11f70601743f58723a7fddd3 (diff) |
PMVMatrix: Expose temporary storage (w/o side-effects) for efficiency; GraphUI.Shape: Efficiently reuse matPMv and temporary PMVMatrix storage
Reuse PMv in Shape.getSurfaceSize() and Shape.winToShapeCoord(),
for the latter we invert the reused PMv for mapWinToObj (i.e. UnProject).
Diffstat (limited to 'src/graphui')
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Shape.java | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java index befee55c3..0f6b0ec28 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java @@ -43,6 +43,7 @@ import com.jogamp.newt.event.PinchToZoomGesture; import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.event.MouseListener; import com.jogamp.opengl.math.FloatUtil; +import com.jogamp.opengl.math.Matrix4f; import com.jogamp.opengl.math.Quaternion; import com.jogamp.opengl.math.Recti; import com.jogamp.opengl.math.Vec2f; @@ -526,8 +527,10 @@ public abstract class Shape { final Vec3f high = box.getHigh(); final Vec3f low = box.getLow(); - if( pmv.gluProject(high, viewport, winCoordHigh) ) { - if( pmv.gluProject(low, viewport, winCoordLow) ) { + // Efficiently reuse matPMv and temporary PMVMatrix storage + final Matrix4f matPMv = pmv.mulPMvMat(pmv.getTmp1Mat()); + if( Matrix4f.mapObjToWin(high, matPMv, viewport, winCoordHigh) ) { + if( Matrix4f.mapObjToWin(low, matPMv, viewport, winCoordLow) ) { surfaceSize[0] = (int)Math.abs(winCoordHigh.x() - winCoordLow.x()); surfaceSize[1] = (int)Math.abs(winCoordHigh.y() - winCoordLow.y()); return surfaceSize; @@ -703,9 +706,14 @@ public abstract class Shape { public Vec3f winToShapeCoord(final PMVMatrix pmv, final Recti viewport, final int glWinX, final int glWinY, final Vec3f objPos) { final Vec3f ctr = box.getCenter(); - if( pmv.gluProject(ctr, viewport, objPos) ) { + // Efficiently reuse matPMv and temporary PMVMatrix storage + final Matrix4f matPMv = pmv.mulPMvMat(pmv.getTmp1Mat()); + if( Matrix4f.mapObjToWin(ctr, matPMv, viewport, objPos) ) { final float winZ = objPos.z(); - if( pmv.gluUnProject(glWinX, glWinY, winZ, viewport, objPos) ) { + if( !matPMv.invert() ) { + return null; + } + if( Matrix4f.mapWinToObj(glWinX, glWinY, winZ, matPMv, viewport, objPos, pmv.getTmp2Mat()) ) { return objPos; } } |