diff options
author | Sven Gothel <[email protected]> | 2014-03-05 03:27:47 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-03-05 03:27:47 +0100 |
commit | 200fe22baae4047e6d22152c760662c85be54fba (patch) | |
tree | db68e97610a7f39ea555bdb852d85eff2b549c40 /src/jogl/classes/com/jogamp/opengl/math | |
parent | 79156e080ef919857f1624543e37b62794fb5a64 (diff) |
Bug 801: Fix 183e1bc1868699b99eb9f9c8bf18d646d1120a48 'window box' Calculation
Commit 183e1bc1868699b99eb9f9c8bf18d646d1120a48 only mapped object's bbox max/min points
to window space, which is wrong due to possible rotation in 3d space.
This commit adds AABBox.mapToWindow(..) method,
which correctly either uses 4 points of the bbox in 3d space (using center-z)
or all 8-points and creating a new bounding box.
The resulting width and height of this window bbox gives the
maximum amount of rectangular pixels for AA.
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/math')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java b/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java index 81928888c..d0566b54e 100644 --- a/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java +++ b/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java @@ -28,6 +28,7 @@ package com.jogamp.opengl.math.geom; import com.jogamp.opengl.math.VectorUtil; +import com.jogamp.opengl.util.PMVMatrix; /** @@ -350,6 +351,53 @@ public class AABBox implements Cloneable { VectorUtil.checkEquality(high, other.high) ; } + /** + * Assume this bounding box as being in object space and + * compute the window bounding box. + * <p> + * If <code>useCenterZ</code> is <code>true</code>, + * only 4 {@link PMVMatrix#gluProject(float, float, float, int[], int, float[], int) gluProject} + * operations are made on points [1..4] using {@link #getCenter()}'s z-value. + * Otherwise 8 {@link PMVMatrix#gluProject(float, float, float, int[], int, float[], int) gluProject} + * operation on all 8 points are made. + * </p> + * <pre> + * [2] ------ [4] + * | | + * | | + * [1] ------ [3] + * </pre> + * @param pmv + * @param view + * @param useCenterZ + * @param tmpV3 TODO + * @return + */ + public AABBox mapToWindow(final AABBox result, final PMVMatrix pmv, final int[] view, final boolean useCenterZ, float[] tmpV3) { + float objZ = useCenterZ ? center[2] : getMinZ(); + pmv.gluProject(getMinX(), getMinY(), objZ, view, 0, tmpV3, 0); + result.reset(); + result.resize(tmpV3, 0); + pmv.gluProject(getMinX(), getMaxY(), objZ, view, 0, tmpV3, 0); + result.resize(tmpV3, 0); + pmv.gluProject(getMaxX(), getMinY(), objZ, view, 0, tmpV3, 0); + result.resize(tmpV3, 0); + pmv.gluProject(getMaxX(), getMaxY(), objZ, view, 0, tmpV3, 0); + result.resize(tmpV3, 0); + if( !useCenterZ ) { + objZ = getMaxZ(); + pmv.gluProject(getMinX(), getMinY(), objZ, view, 0, tmpV3, 0); + result.resize(tmpV3, 0); + pmv.gluProject(getMinX(), getMaxY(), objZ, view, 0, tmpV3, 0); + result.resize(tmpV3, 0); + pmv.gluProject(getMaxX(), getMinY(), objZ, view, 0, tmpV3, 0); + result.resize(tmpV3, 0); + pmv.gluProject(getMaxX(), getMaxY(), objZ, view, 0, tmpV3, 0); + result.resize(tmpV3, 0); + } + return result; + } + @Override public final String toString() { return "[ dim "+getWidth()+" x "+getHeight()+" x "+getDepth()+ |