diff options
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl')
7 files changed, 318 insertions, 137 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/FBObject.java b/src/jogl/classes/com/jogamp/opengl/FBObject.java index 90a8dc073..33751eab9 100644 --- a/src/jogl/classes/com/jogamp/opengl/FBObject.java +++ b/src/jogl/classes/com/jogamp/opengl/FBObject.java @@ -2316,8 +2316,8 @@ public class FBObject { return "FBO[name r/w "+fbName+"/"+getReadFramebuffer()+", init "+initialized+", bound "+bound+", size "+width+"x"+height+ ", samples "+samples+"/"+maxSamples+", depth "+depth+", stencil "+stencil+ ", color attachments: "+colorAttachmentCount+"/"+maxColorAttachments+ - ": "+caps+", msaa-sink "+samplingSinkTexture+", hasSamplesSink "+(null != samplingSink)+ - ", state "+getStatusString()+", obj "+toHexString(objectHashCode())+"]"; + ": "+caps+", msaa["+samplingSinkTexture+", hasSink "+(null != samplingSink)+ + ", dirty "+samplingSinkDirty+"], state "+getStatusString()+", obj "+toHexString(objectHashCode())+"]"; } private final void updateStatus(GL gl) { diff --git a/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java b/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java index 191a83241..d2976357d 100644 --- a/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java @@ -29,23 +29,39 @@ package com.jogamp.opengl.math; import java.nio.FloatBuffer; +import jogamp.opengl.Debug; + import com.jogamp.common.os.Platform; /** * Basic Float math utility functions. * <p> * Implementation assumes linear matrix layout in column-major order - * matching OpenGL's implementation. + * matching OpenGL's implementation, translation matrix example: + * <pre> + Row-Major Order: + 1 0 0 x + 0 1 0 y + 0 0 1 z + 0 0 0 1 + * </pre> + * <pre> + Column-Major Order: + 1 0 0 0 + 0 1 0 0 + 0 0 1 0 + x y z 1 + * </pre> * </p> * <p> * Derived from ProjectFloat.java - Created 11-jan-2004 * </p> * - * @author Erik Duijs - * @author Kenneth Russell - * @author Sven Gothel + * @author Erik Duijs, Kenneth Russell, et al. */ public class FloatUtil { + public static final boolean DEBUG = Debug.debug("Math"); + private static final float[] IDENTITY_MATRIX = new float[] { 1.0f, 0.0f, 0.0f, 0.0f, @@ -558,7 +574,7 @@ public class FloatUtil { public static final float PI = 3.14159265358979323846f; - public static float abs(float a) { return (float) java.lang.Math.abs(a); } + public static float abs(float a) { return java.lang.Math.abs(a); } public static float pow(float a, float b) { return (float) java.lang.Math.pow(a, b); } diff --git a/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java b/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java index 52a59c599..3c3510b7f 100644 --- a/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java +++ b/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java @@ -56,7 +56,8 @@ public class Quaternion { */ public Quaternion(float[] vector1, float[] vector2) { final float theta = FloatUtil.acos(VectorUtil.dot(vector1, vector2)); - final float[] cross = VectorUtil.cross(vector1, vector2); + final float[] cross = new float[3]; + VectorUtil.cross(cross, vector1, vector2); fromAxis(cross, theta); } @@ -79,7 +80,7 @@ public class Quaternion { public void fromAxis(float[] vector, float angle) { final float halfangle = angle * 0.5f; final float sin = FloatUtil.sin(halfangle); - final float[] nv = VectorUtil.normalize(vector); + final float[] nv = VectorUtil.normalize(vector, vector); x = (nv[0] * sin); y = (nv[1] * sin); z = (nv[2] * sin); @@ -220,7 +221,7 @@ public class Quaternion { * Normalize a quaternion required if to be used as a rotational quaternion */ public void normalize() { - final float norme = (float) FloatUtil.sqrt(w * w + x * x + y * y + z * z); + final float norme = FloatUtil.sqrt(w * w + x * x + y * y + z * z); if (norme == 0.0f) { setIdentity(); } else { @@ -355,7 +356,7 @@ public class Quaternion { public void setFromMatrix(float[] m) { final float T = m[0] + m[4] + m[8] + 1; if (T > 0) { - final float S = 0.5f / (float) FloatUtil.sqrt(T); + final float S = 0.5f / FloatUtil.sqrt(T); w = 0.25f / S; x = (m[5] - m[7]) * S; y = (m[6] - m[2]) * S; diff --git a/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java b/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java index e1e797088..734b7459b 100644 --- a/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java @@ -52,41 +52,26 @@ public class VectorUtil { { return (vec1[0]*vec2[0] + vec1[1]*vec2[1] + vec1[2]*vec2[2]); } - /** Normalize a vector + + /** + * Normalize a vector * @param vector input vector * @return normalized vector */ - public static float[] normalize(float[] vector) + public static float[] normalize(final float[] result, float[] vector) { - final float[] newVector = new float[3]; - final float d = FloatUtil.sqrt(vector[0]*vector[0] + vector[1]*vector[1] + vector[2]*vector[2]); if(d> 0.0f) { - newVector[0] = vector[0]/d; - newVector[1] = vector[1]/d; - newVector[2] = vector[2]/d; + result[0] = vector[0]/d; + result[1] = vector[1]/d; + result[2] = vector[2]/d; } - return newVector; - } - - /** Scales a vector by param creating a new float[] for the result! - * @param vector input vector - * @param scale constant to scale by - * @return new scaled vector - * @deprecated Use {@link #scale(float[], float[], float)} - */ - public static float[] scale(float[] vector, float scale) - { - final float[] newVector = new float[3]; - - newVector[0] = vector[0] * scale; - newVector[1] = vector[1] * scale; - newVector[2] = vector[2] * scale; - return newVector; + return result; } - /** Scales a vector by param using given result float[] + /** + * Scales a vector by param using given result float[] * @param result vector for the result * @param vector input vector * @param scale single scale constant for all vector components @@ -113,67 +98,61 @@ public class VectorUtil { return result; } - /** Adds to vectors + /** + * Adds to vectors * @param v1 vector 1 * @param v2 vector 2 * @return v1 + v2 */ - public static float[] vectorAdd(float[] v1, float[] v2) + public static float[] vectorAdd(float[] result, float[] v1, float[] v2) { - final float[] newVector = new float[3]; - - newVector[0] = v1[0] + v2[0]; - newVector[1] = v1[1] + v2[1]; - newVector[2] = v1[2] + v2[2]; - return newVector; + result[0] = v1[0] + v2[0]; + result[1] = v1[1] + v2[1]; + result[2] = v1[2] + v2[2]; + return result; } - /** cross product vec1 x vec2 + /** + * cross product vec1 x vec2 * @param vec1 vector 1 * @param vec2 vecttor 2 * @return the resulting vector */ - public static float[] cross(float[] vec1, float[] vec2) + public static float[] cross(final float[] result, float[] vec1, float[] vec2) { - final float[] out = new float[3]; - - out[0] = vec2[2]*vec1[1] - vec2[1]*vec1[2]; - out[1] = vec2[0]*vec1[2] - vec2[2]*vec1[0]; - out[2] = vec2[1]*vec1[0] - vec2[0]*vec1[1]; + result[0] = vec2[2]*vec1[1] - vec2[1]*vec1[2]; + result[1] = vec2[0]*vec1[2] - vec2[2]*vec1[0]; + result[2] = vec2[1]*vec1[0] - vec2[0]*vec1[1]; - return out; + return result; } /** Column Matrix Vector multiplication * @param colMatrix column matrix (4x4) * @param vec vector(x,y,z) - * @return result new float[3] + * @return result */ - public static float[] colMatrixVectorMult(float[] colMatrix, float[] vec) + public static float[] colMatrixVectorMult(final float[] result, float[] colMatrix, float[] vec) { - final float[] out = new float[3]; - - out[0] = vec[0]*colMatrix[0] + vec[1]*colMatrix[4] + vec[2]*colMatrix[8] + colMatrix[12]; - out[1] = vec[0]*colMatrix[1] + vec[1]*colMatrix[5] + vec[2]*colMatrix[9] + colMatrix[13]; - out[2] = vec[0]*colMatrix[2] + vec[1]*colMatrix[6] + vec[2]*colMatrix[10] + colMatrix[14]; + result[0] = vec[0]*colMatrix[0] + vec[1]*colMatrix[4] + vec[2]*colMatrix[8] + colMatrix[12]; + result[1] = vec[0]*colMatrix[1] + vec[1]*colMatrix[5] + vec[2]*colMatrix[9] + colMatrix[13]; + result[2] = vec[0]*colMatrix[2] + vec[1]*colMatrix[6] + vec[2]*colMatrix[10] + colMatrix[14]; - return out; + return result; } /** Matrix Vector multiplication * @param rawMatrix column matrix (4x4) * @param vec vector(x,y,z) - * @return result new float[3] + * @return result */ - public static float[] rowMatrixVectorMult(float[] rawMatrix, float[] vec) + public static float[] rowMatrixVectorMult(final float[] result, float[] rawMatrix, float[] vec) { - final float[] out = new float[3]; - - out[0] = vec[0]*rawMatrix[0] + vec[1]*rawMatrix[1] + vec[2]*rawMatrix[2] + rawMatrix[3]; - out[1] = vec[0]*rawMatrix[4] + vec[1]*rawMatrix[5] + vec[2]*rawMatrix[6] + rawMatrix[7]; - out[2] = vec[0]*rawMatrix[8] + vec[1]*rawMatrix[9] + vec[2]*rawMatrix[10] + rawMatrix[11]; + result[0] = vec[0]*rawMatrix[0] + vec[1]*rawMatrix[1] + vec[2]*rawMatrix[2] + rawMatrix[3]; + result[1] = vec[0]*rawMatrix[4] + vec[1]*rawMatrix[5] + vec[2]*rawMatrix[6] + rawMatrix[7]; + result[2] = vec[0]*rawMatrix[8] + vec[1]*rawMatrix[9] + vec[2]*rawMatrix[10] + rawMatrix[11]; - return out; + return result; } /** Calculate the midpoint of two values @@ -186,19 +165,19 @@ public class VectorUtil { return (p1+p2)/2.0f; } - /** Calculate the midpoint of two points + /** + * Calculate the midpoint of two points * @param p1 first point * @param p2 second point * @return midpoint */ - public static float[] mid(float[] p1, float[] p2) + public static float[] mid(final float[] result, float[] p1, float[] p2) { - final float[] midPoint = new float[3]; - midPoint[0] = (p1[0] + p2[0])*0.5f; - midPoint[1] = (p1[1] + p2[1])*0.5f; - midPoint[2] = (p1[2] + p2[2])*0.5f; + result[0] = (p1[0] + p2[0])*0.5f; + result[1] = (p1[1] + p2[1])*0.5f; + result[2] = (p1[2] + p2[2])*0.5f; - return midPoint; + return result; } /** Compute the norm of a vector @@ -271,17 +250,14 @@ public class VectorUtil { } /** Compute Vector + * @param vector storage for resulting Vector V1V2 * @param v1 vertex 1 * @param v2 vertex2 2 - * @return Vector V1V2 */ - public static float[] computeVector(float[] v1, float[] v2) - { - final float[] vector = new float[3]; + public static void computeVector(float[] vector, float[] v1, float[] v2) { vector[0] = v2[0] - v1[0]; vector[1] = v2[1] - v1[1]; vector[2] = v2[2] - v1[2]; - return vector; } /** Check if vertices in triangle circumcircle @@ -292,11 +268,15 @@ public class VectorUtil { * @return true if the vertex d is inside the circle defined by the * vertices a, b, c. from paper by Guibas and Stolfi (1985). */ - public static boolean inCircle(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d){ - return (a.getX() * a.getX() + a.getY() * a.getY()) * triArea(b, c, d) - - (b.getX() * b.getX() + b.getY() * b.getY()) * triArea(a, c, d) + - (c.getX() * c.getX() + c.getY() * c.getY()) * triArea(a, b, d) - - (d.getX() * d.getX() + d.getY() * d.getY()) * triArea(a, b, c) > 0; + public static boolean inCircle(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d) { + final float[] A = a.getCoord(); + final float[] B = b.getCoord(); + final float[] C = c.getCoord(); + final float[] D = d.getCoord(); + return (A[0] * A[0] + A[1] * A[1]) * triArea(B, C, D) - + (B[0] * B[0] + B[1] * B[1]) * triArea(A, C, D) + + (C[0] * C[0] + C[1] * C[1]) * triArea(A, B, D) - + (D[0] * D[0] + D[1] * D[1]) * triArea(A, B, C) > 0; } /** Computes oriented area of a triangle @@ -306,8 +286,22 @@ public class VectorUtil { * @return compute twice the area of the oriented triangle (a,b,c), the area * is positive if the triangle is oriented counterclockwise. */ - public static float triArea(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c) { - return (b.getX() - a.getX()) * (c.getY() - a.getY()) - (b.getY() - a.getY())*(c.getX() - a.getX()); + public static float triArea(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c){ + final float[] A = a.getCoord(); + final float[] B = b.getCoord(); + final float[] C = c.getCoord(); + return (B[0] - A[0]) * (C[1] - A[1]) - (B[1] - A[1]) * (C[0] - A[0]); + } + + /** Computes oriented area of a triangle + * @param A first vertex + * @param B second vertex + * @param C third vertex + * @return compute twice the area of the oriented triangle (a,b,c), the area + * is positive if the triangle is oriented counterclockwise. + */ + public static float triArea(float[] A, float[] B, float[] C){ + return (B[0] - A[0]) * (C[1] - A[1]) - (B[1] - A[1])*(C[0] - A[0]); } /** Check if a vertex is in triangle using @@ -318,11 +312,13 @@ public class VectorUtil { * @param p the vertex in question * @return true if p is in triangle (a, b, c), false otherwise. */ - public static boolean vertexInTriangle(float[] a, float[] b, float[] c, float[] p){ + public static boolean vertexInTriangle(float[] a, float[] b, float[] c, + float[] p, + float[] ac, float[] ab, float[] ap){ // Compute vectors - final float[] ac = computeVector(a, c); //v0 - final float[] ab = computeVector(a, b); //v1 - final float[] ap = computeVector(a, p); //v2 + computeVector(ac, a, c); //v0 + computeVector(ab, a, b); //v1 + computeVector(ap, a, p); //v2 // Compute dot products final float dot00 = dot(ac, ac); @@ -340,6 +336,76 @@ public class VectorUtil { return (u >= 0) && (v >= 0) && (u + v < 1); } + /** + * Check if one of three vertices are in triangle using + * barycentric coordinates computation. + * @param a first triangle vertex + * @param b second triangle vertex + * @param c third triangle vertex + * @param p1 the vertex in question + * @param p2 the vertex in question + * @param p3 the vertex in question + * @param tmpAC + * @param tmpAB + * @param tmpAP + * @return true if p1 or p2 or p3 is in triangle (a, b, c), false otherwise. + */ + public static boolean vertexInTriangle3(float[] a, float[] b, float[] c, + float[] p1, float[] p2, float[] p3, + float[] tmpAC, float[] tmpAB, float[] tmpAP){ + // Compute vectors + computeVector(tmpAC, a, c); //v0 + computeVector(tmpAB, a, b); //v1 + + // Compute dot products + final float dotAC_AC = dot(tmpAC, tmpAC); + final float dotAC_AB = dot(tmpAC, tmpAB); + final float dotAB_AB = dot(tmpAB, tmpAB); + + // Compute barycentric coordinates + final float invDenom = 1 / (dotAC_AC * dotAB_AB - dotAC_AB * dotAC_AB); + { + computeVector(tmpAP, a, p1); //v2 + final float dotAC_AP1 = dot(tmpAC, tmpAP); + final float dotAB_AP1 = dot(tmpAB, tmpAP); + final float u1 = (dotAB_AB * dotAC_AP1 - dotAC_AB * dotAB_AP1) * invDenom; + final float v1 = (dotAC_AC * dotAB_AP1 - dotAC_AB * dotAC_AP1) * invDenom; + + // Check if point is in triangle + if ( (u1 >= 0) && (v1 >= 0) && (u1 + v1 < 1) ) { + return true; + } + } + + { + computeVector(tmpAP, a, p2); //v2 + final float dotAC_AP2 = dot(tmpAC, tmpAP); + final float dotAB_AP2 = dot(tmpAB, tmpAP); + final float u = (dotAB_AB * dotAC_AP2 - dotAC_AB * dotAB_AP2) * invDenom; + final float v = (dotAC_AC * dotAB_AP2 - dotAC_AB * dotAC_AP2) * invDenom; + + // Check if point is in triangle + if ( (u >= 0) && (v >= 0) && (u + v < 1) ) { + return true; + } + } + + { + computeVector(tmpAP, a, p3); //v2 + final float dotAC_AP3 = dot(tmpAC, tmpAP); + final float dotAB_AP3 = dot(tmpAB, tmpAP); + final float u = (dotAB_AB * dotAC_AP3 - dotAC_AB * dotAB_AP3) * invDenom; + final float v = (dotAC_AC * dotAB_AP3 - dotAC_AB * dotAC_AP3) * invDenom; + + // Check if point is in triangle + if ( (u >= 0) && (v >= 0) && (u + v < 1) ) { + return true; + } + } + + return false; + } + /** Check if points are in ccw order * @param a first vertex * @param b second vertex @@ -390,10 +456,9 @@ public class VectorUtil { * @param b vertex 2 of first segment * @param c vertex 1 of second segment * @param d vertex 2 of second segment - * @return the intersection coordinates if the segments intersect, otherwise - * returns null + * @return the intersection coordinates if the segments intersect, otherwise returns null */ - public static float[] seg2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d) { + public static float[] seg2SegIntersection(final float[] result, Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d) { final float determinant = (a.getX()-b.getX())*(c.getY()-d.getY()) - (a.getY()-b.getY())*(c.getX()-d.getX()); if (determinant == 0) @@ -409,7 +474,42 @@ public class VectorUtil { if(gamma <= 0 || gamma >= 1) return null; if(gamma1 <= 0 || gamma1 >= 1) return null; - return new float[]{xi,yi,0}; + result[0] = xi; + result[1] = yi; + result[2] = 0; + return result; + } + + /** Compute intersection between two segments + * @param a vertex 1 of first segment + * @param b vertex 2 of first segment + * @param c vertex 1 of second segment + * @param d vertex 2 of second segment + * @return true if the segments intersect, otherwise returns false + */ + public static boolean testSeg2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d) { + final float[] A = a.getCoord(); + final float[] B = b.getCoord(); + final float[] C = c.getCoord(); + final float[] D = d.getCoord(); + + final float determinant = (A[0]-B[0])*(C[1]-D[1]) - (A[1]-B[1])*(C[0]-D[0]); + + if (determinant == 0) { + return false; + } + + final float alpha = (A[0]*B[1]-A[1]*B[0]); + final float beta = (C[0]*D[1]-C[1]*D[1]); + final float xi = ((C[0]-D[0])*alpha-(A[0]-B[0])*beta)/determinant; + + final float gamma = (xi - A[0])/(B[0] - A[0]); + final float gamma1 = (xi - C[0])/(D[0] - C[0]); + if(gamma <= 0 || gamma >= 1 || gamma1 <= 0 || gamma1 >= 1) { + return false; + } + + return true; } /** Compute intersection between two lines @@ -420,7 +520,7 @@ public class VectorUtil { * @return the intersection coordinates if the lines intersect, otherwise * returns null */ - public static float[] line2lineIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d) { + public static float[] line2lineIntersection(final float[] result, Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d) { final float determinant = (a.getX()-b.getX())*(c.getY()-d.getY()) - (a.getY()-b.getY())*(c.getX()-d.getX()); if (determinant == 0) @@ -431,7 +531,10 @@ public class VectorUtil { final float xi = ((c.getX()-d.getX())*alpha-(a.getX()-b.getX())*beta)/determinant; final float yi = ((c.getY()-d.getY())*alpha-(a.getY()-b.getY())*beta)/determinant; - return new float[]{xi,yi,0}; + result[0] = xi; + result[1] = yi; + result[2] = 0; + return result; } /** Check if a segment intersects with a triangle @@ -442,14 +545,9 @@ public class VectorUtil { * @param e vertex 2 of first segment * @return true if the segment intersects at least one segment of the triangle, false otherwise */ - public static boolean tri2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d, Vert2fImmutable e){ - if(seg2SegIntersection(a, b, d, e) != null) - return true; - if(seg2SegIntersection(b, c, d, e) != null) - return true; - if(seg2SegIntersection(a, c, d, e) != null) - return true; - - return false; + public static boolean testTri2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d, Vert2fImmutable e){ + return testSeg2SegIntersection(a, b, d, e) || + testSeg2SegIntersection(b, c, d, e) || + testSeg2SegIntersection(a, c, d, e) ; } } 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 d48677da5..c28b36f82 100644 --- a/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java +++ b/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java @@ -27,7 +27,9 @@ */ package com.jogamp.opengl.math.geom; +import com.jogamp.opengl.math.FloatUtil; import com.jogamp.opengl.math.VectorUtil; +import com.jogamp.opengl.util.PMVMatrix; /** @@ -37,9 +39,10 @@ import com.jogamp.opengl.math.VectorUtil; * */ public class AABBox implements Cloneable { - private float[] low = new float[3]; - private float[] high = new float[3]; - private float[] center = new float[3]; + private static final boolean DEBUG = FloatUtil.DEBUG; + private final float[] low = new float[3]; + private final float[] high = new float[3]; + private final float[] center = new float[3]; /** Create a Axis Aligned bounding box (AABBox) * where the low and and high MAX float Values. @@ -167,20 +170,26 @@ public class AABBox implements Cloneable { */ public final void resize(float x, float y, float z) { /** test low */ - if (x < low[0]) + if (x < low[0]) { low[0] = x; - if (y < low[1]) + } + if (y < low[1]) { low[1] = y; - if (z < low[2]) + } + if (z < low[2]) { low[2] = z; + } /** test high */ - if (x > high[0]) + if (x > high[0]) { high[0] = x; - if (y > high[1]) + } + if (y > high[1]) { high[1] = y; - if (z > high[2]) + } + if (z > high[2]) { high[2] = z; + } computeCenter(); } @@ -275,26 +284,25 @@ public class AABBox implements Cloneable { return center; } - /** Scale the AABBox by a constant + /** + * Scale the AABBox by a constant * @param size a constant float value + * @param tmpV3 caller provided temporary 3-component vector */ - public final void scale(float size) { - float[] diffH = new float[3]; - diffH[0] = high[0] - center[0]; - diffH[1] = high[1] - center[1]; - diffH[2] = high[2] - center[2]; + public final void scale(float size, float[] tmpV3) { + tmpV3[0] = high[0] - center[0]; + tmpV3[1] = high[1] - center[1]; + tmpV3[2] = high[2] - center[2]; - diffH = VectorUtil.scale(diffH, size); + VectorUtil.scale(tmpV3, tmpV3, size); // in-place scale + VectorUtil.vectorAdd(high, center, tmpV3); - float[] diffL = new float[3]; - diffL[0] = low[0] - center[0]; - diffL[1] = low[1] - center[1]; - diffL[2] = low[2] - center[2]; + tmpV3[0] = low[0] - center[0]; + tmpV3[1] = low[1] - center[1]; + tmpV3[2] = low[2] - center[2]; - diffL = VectorUtil.scale(diffL, size); - - high = VectorUtil.vectorAdd(center, diffH); - low = VectorUtil.vectorAdd(center, diffL); + VectorUtil.scale(tmpV3, tmpV3, size); // in-place scale + VectorUtil.vectorAdd(low, center, tmpV3); } public final float getMinX() { @@ -351,9 +359,66 @@ 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 performed. + * </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) { + // System.err.printf("AABBox.mapToWindow.0: view[%d, %d, %d, %d], this %s%n", view[0], view[1], view[2], view[3], toString()); + float objZ = useCenterZ ? center[2] : getMinZ(); + pmv.gluProject(getMinX(), getMinY(), objZ, view, 0, tmpV3, 0); + // System.err.printf("AABBox.mapToWindow.p1: %f, %f, %f -> %f, %f, %f%n", getMinX(), getMinY(), objZ, tmpV3[0], tmpV3[1], tmpV3[2]); + // System.err.printf("AABBox.mapToWindow.p1: %s%n", pmv.toString()); + result.reset(); + result.resize(tmpV3, 0); + pmv.gluProject(getMinX(), getMaxY(), objZ, view, 0, tmpV3, 0); + // System.err.printf("AABBox.mapToWindow.p2: %f, %f, %f -> %f, %f, %f%n", getMinX(), getMaxY(), objZ, tmpV3[0], tmpV3[1], tmpV3[2]); + result.resize(tmpV3, 0); + pmv.gluProject(getMaxX(), getMinY(), objZ, view, 0, tmpV3, 0); + // System.err.printf("AABBox.mapToWindow.p3: %f, %f, %f -> %f, %f, %f%n", getMaxX(), getMinY(), objZ, tmpV3[0], tmpV3[1], tmpV3[2]); + result.resize(tmpV3, 0); + pmv.gluProject(getMaxX(), getMaxY(), objZ, view, 0, tmpV3, 0); + // System.err.printf("AABBox.mapToWindow.p4: %f, %f, %f -> %f, %f, %f%n", getMaxX(), getMaxY(), objZ, tmpV3[0], tmpV3[1], tmpV3[2]); + 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); + } + if( DEBUG ) { + System.err.printf("AABBox.mapToWindow: view[%d, %d], this %s -> %s%n", view[0], view[1], toString(), result.toString()); + } + return result; + } + @Override public final String toString() { - return "[ "+low[0]+"/"+low[1]+"/"+low[1]+" .. "+high[0]+"/"+high[0]+"/"+high[0]+", ctr "+ - center[0]+"/"+center[1]+"/"+center[1]+" ]"; + return "[ dim "+getWidth()+" x "+getHeight()+" x "+getDepth()+ + ", box "+low[0]+" / "+low[1]+" / "+low[2]+" .. "+high[0]+" / "+high[1]+" / "+high[2]+ + ", ctr "+center[0]+" / "+center[1]+" / "+center[2]+" ]"; } } diff --git a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java index 218897ffe..270bf34f6 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java +++ b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java @@ -65,6 +65,7 @@ import com.jogamp.opengl.math.geom.Frustum; * <p> * All matrices are provided in column-major order, * as specified in the OpenGL fixed function pipeline, i.e. compatibility profile. + * See {@link FloatUtil}. * </p> * <p> * PMVMatrix can supplement {@link GL2ES2} applications w/ the @@ -486,7 +487,7 @@ public class PMVMatrix implements GLMatrixFunc { public final void glGetFloatv(int matrixGetName, FloatBuffer params) { int pos = params.position(); if(matrixGetName==GL_MATRIX_MODE) { - params.put((float)matrixMode); + params.put(matrixMode); } else { final FloatBuffer matrix = glGetMatrixf(matrixGetName); params.put(matrix); // matrix -> params @@ -498,7 +499,7 @@ public class PMVMatrix implements GLMatrixFunc { @Override public final void glGetFloatv(int matrixGetName, float[] params, int params_offset) { if(matrixGetName==GL_MATRIX_MODE) { - params[params_offset]=(float)matrixMode; + params[params_offset]=matrixMode; } else { final FloatBuffer matrix = glGetMatrixf(matrixGetName); matrix.get(params, params_offset, 16); // matrix -> params diff --git a/src/jogl/classes/com/jogamp/opengl/util/av/AudioSink.java b/src/jogl/classes/com/jogamp/opengl/util/av/AudioSink.java index b964245ad..f4ea29084 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/av/AudioSink.java +++ b/src/jogl/classes/com/jogamp/opengl/util/av/AudioSink.java @@ -133,7 +133,7 @@ public interface AudioSink { * @param sampleCount sample count per frame and channel */ public final float getSamplesDuration(int sampleCount) { - return ( 1000f * (float) sampleCount ) / (float)sampleRate; + return ( 1000f * sampleCount ) / sampleRate; } /** @@ -152,7 +152,7 @@ public interface AudioSink { * @param frameDuration duration per frame in milliseconds. */ public final int getFrameCount(int millisecs, float frameDuration) { - return Math.max(1, (int) ( (float)millisecs / frameDuration + 0.5f )); + return Math.max(1, (int) ( millisecs / frameDuration + 0.5f )); } /** @@ -187,7 +187,7 @@ public interface AudioSink { * <p> * Byte Count -> Sample Count * </p> - * @param sampleCount sample count + * @param byteCount number of bytes */ public final int getBytesSampleCount(int byteCount) { return ( byteCount << 3 ) / sampleSize; |