Skip to content

Commit

Permalink
Bug 801: AffineTransform: Remove Serializable, make methods final; Fl…
Browse files Browse the repository at this point in the history
…oatUtil: Add DEBUG and description about Row-Major and Column-Major Order. AABBOX: Use FloatUtil.DEBUG for mapToWindow(..)
  • Loading branch information
sgothel committed Mar 6, 2014
1 parent 0799ac2 commit 68eb9f1
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 82 deletions.
26 changes: 21 additions & 5 deletions src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java
Expand Up @@ -29,23 +29,39 @@

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,
Expand Down Expand Up @@ -558,7 +574,7 @@ public static StringBuilder matrixToString(StringBuilder sb, String rowPrefix, S

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); }

Expand Down
31 changes: 24 additions & 7 deletions src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java
Expand Up @@ -27,6 +27,7 @@
*/
package com.jogamp.opengl.math.geom;

import com.jogamp.opengl.math.FloatUtil;
import com.jogamp.opengl.math.VectorUtil;
import com.jogamp.opengl.util.PMVMatrix;

Expand All @@ -38,6 +39,7 @@
*
*/
public class AABBox implements Cloneable {
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];
Expand Down Expand Up @@ -168,20 +170,26 @@ public final void resize(AABBox newBox) {
*/
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();
}
Expand Down Expand Up @@ -359,7 +367,7 @@ public final boolean equals(Object obj) {
* 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.
* operation on all 8 points are performed.
* </p>
* <pre>
* [2] ------ [4]
Expand All @@ -374,15 +382,21 @@ public final boolean equals(Object obj) {
* @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();
Expand All @@ -395,6 +409,9 @@ public AABBox mapToWindow(final AABBox result, final PMVMatrix pmv, final int[]
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;
}

Expand Down
5 changes: 3 additions & 2 deletions src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java
Expand Up @@ -65,6 +65,7 @@
* <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
Expand Down Expand Up @@ -486,7 +487,7 @@ public final void glMatrixMode(final int matrixName) {
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
Expand All @@ -498,7 +499,7 @@ public final void glGetFloatv(int matrixGetName, FloatBuffer params) {
@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
Expand Down

0 comments on commit 68eb9f1

Please sign in to comment.