From 200fe22baae4047e6d22152c760662c85be54fba Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 5 Mar 2014 03:27:47 +0100 Subject: 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. --- .../com/jogamp/opengl/math/geom/AABBox.java | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/jogl/classes/com/jogamp') 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. + *

+ * If useCenterZ is true, + * 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. + *

+ *
+     *  [2] ------ [4]
+     *   |          |
+     *   |          |
+     *  [1] ------ [3]
+     * 
+ * @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()+ -- cgit v1.2.3