aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/math/geom
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-04-07 08:46:18 +0200
committerSven Gothel <[email protected]>2023-04-07 08:46:18 +0200
commit84a6d63205ec49ddfb36b57fe2888425ecda3a5a (patch)
tree354cec2ac14a8932a01122c5234926e774ef874e /src/jogl/classes/com/jogamp/opengl/math/geom
parent10b60e10ece3cbc3e0b8a68ac73229371530e0ba (diff)
PMVMatrix rewrite using Matrix4f, providing SyncMatrix4f* for GLUniformData; Utilize Vec3f, Recti, .. throughout API (Matrix4f, AABBox, .. Graph*)
Big Easter Cleanup - Net -214 lines of code, despite new classes. - GLUniformData buffer can be synced w/ underlying data via SyncAction/SyncBuffer, e.g. SyncMatrix4f + SyncMatrices4f - PMVMatrix rewrite using Matrix4f and providing SyncMatrix4f/Matrices4f to sync w/ GLUniformData - Additional SyncMatrix4f16 + SyncMatrices4f16 covering Matrix4f sync w/ GLUniformData w/o PMVMatrix - Utilize Vec3f, Recti, .. throughout API (Matrix4f, AABBox, .. Graph*) - Moved FloatUtil -> Matrix4f, kept a few basic matrix ops for ProjectFloat - Most, if not all, float[] and int[] should have been moved to proper classes - int[] -> Recti for viewport rectangle - Matrix4f and PMVMatrix is covered by math unit tests (as was FloatUtil before) -> save Passed all unit tests on AMD64 GNU/Linux
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/math/geom')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java113
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/geom/Frustum.java96
2 files changed, 60 insertions, 149 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 77e1bfc59..ad521de2a 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java
@@ -32,6 +32,7 @@ import com.jogamp.opengl.math.FloatUtil;
import com.jogamp.opengl.math.Matrix4f;
import com.jogamp.opengl.math.Quaternion;
import com.jogamp.opengl.math.Ray;
+import com.jogamp.opengl.math.Recti;
import com.jogamp.opengl.math.Vec3f;
import com.jogamp.opengl.util.PMVMatrix;
@@ -718,41 +719,34 @@ public class AABBox {
throw new InternalError("hashCode not designed");
}
- public AABBox transform(final AABBox result, final float[/*16*/] mat4, final int mat4_off,
- final float[] vec3Tmp0, final float[] vec3Tmp1) {
- result.reset();
- FloatUtil.multMatrixVec3(mat4, mat4_off, low.get(vec3Tmp0), vec3Tmp1);
- result.resize(vec3Tmp1);
-
- FloatUtil.multMatrixVec3(mat4, mat4_off, high.get(vec3Tmp0), vec3Tmp1);
- result.resize(vec3Tmp1);
-
- result.computeCenter();
- return result;
- }
-
- public AABBox transformMv(final AABBox result, final PMVMatrix pmv,
- final float[] vec3Tmp0, final float[] vec3Tmp1) {
- result.reset();
- pmv.multMvMatVec3f(low.get(vec3Tmp0), vec3Tmp1);
- result.resize(vec3Tmp1);
-
- pmv.multMvMatVec3f(high.get(vec3Tmp0), vec3Tmp1);
- result.resize(vec3Tmp1);
-
- result.computeCenter();
- return result;
+ /**
+ * Transform this box using the given {@link Matrix4f} into {@code out}
+ * @param mat transformation {@link Matrix4f}
+ * @param out the resulting {@link AABBox}
+ * @return the resulting {@link AABBox} for chaining
+ */
+ public AABBox transform(final Matrix4f mat, final AABBox out) {
+ final Vec3f tmp = new Vec3f();
+ out.reset();
+ out.resize( mat.mulVec3f(low, tmp) );
+ out.resize( mat.mulVec3f(high, tmp) );
+ out.computeCenter();
+ return out;
}
- public AABBox transform(final AABBox result, final Matrix4f mat,
- final Vec3f vec3Tmp) {
- result.reset();
- result.resize( mat.mulVec3f(low, vec3Tmp) );
-
- result.resize( mat.mulVec3f(high, vec3Tmp) );
-
- result.computeCenter();
- return result;
+ /**
+ * Transform this box using the {@link PMVMatrix#getMvMat() modelview} of the given {@link PMVMatrix} into {@code out}
+ * @param pmv transformation {@link PMVMatrix}
+ * @param out the resulting {@link AABBox}
+ * @return the resulting {@link AABBox} for chaining
+ */
+ public AABBox transformMv(final PMVMatrix pmv, final AABBox out) {
+ final Vec3f tmp = new Vec3f();
+ out.reset();
+ out.resize( pmv.mulMvMatVec3f(low, tmp) );
+ out.resize( pmv.mulMvMatVec3f(high, tmp) );
+ out.computeCenter();
+ return out;
}
/**
@@ -771,56 +765,51 @@ public class AABBox {
* | |
* .y() ------ [3]
* </pre>
- * @param mat4PMv P x Mv matrix
- * @param view
+ * @param mat4PMv [projection] x [modelview] matrix, i.e. P x Mv
+ * @param viewport viewport rectangle
* @param useCenterZ
* @param vec3Tmp0 3 component vector for temp storage
* @param vec4Tmp1 4 component vector for temp storage
* @param vec4Tmp2 4 component vector for temp storage
* @return
*/
- public AABBox mapToWindow(final AABBox result, final float[/*16*/] mat4PMv, final int[] view, final boolean useCenterZ,
- final float[] vec3Tmp0, final float[] vec4Tmp1, final float[] vec4Tmp2) {
+ public AABBox mapToWindow(final AABBox result, final Matrix4f mat4PMv, final Recti viewport, final boolean useCenterZ) {
+ final Vec3f tmp = new Vec3f();
+ final Vec3f winPos = new Vec3f();
{
- // System.err.printf("AABBox.mapToWindow.0: view[%d, %d, %d, %d], this %s%n", view.x(), view.y(), view.z(), view[3], toString());
final float objZ = useCenterZ ? center.z() : getMinZ();
- FloatUtil.mapObjToWin(getMinX(), getMinY(), objZ, mat4PMv, view, vec3Tmp0, vec4Tmp1, vec4Tmp2);
- // System.err.printf("AABBox.mapToWindow.p1: %f, %f, %f -> %f, %f, %f%n", getMinX(), getMinY(), objZ, vec3Tmp0.x(), vec3Tmp0.y(), vec3Tmp0.z());
- // System.err.println("AABBox.mapToWindow.p1:");
- // System.err.println(FloatUtil.matrixToString(null, " mat4PMv", "%10.5f", mat4PMv, 0, 4, 4, false /* rowMajorOrder */));
-
result.reset();
- result.resize(vec3Tmp0);
- FloatUtil.mapObjToWin(getMinX(), getMaxY(), objZ, mat4PMv, view, vec3Tmp0, vec4Tmp1, vec4Tmp2);
- // System.err.printf("AABBox.mapToWindow.p2: %f, %f, %f -> %f, %f, %f%n", getMinX(), getMaxY(), objZ, vec3Tmp0.x(), vec3Tmp0.y(), vec3Tmp0.z());
- result.resize(vec3Tmp0);
+ Matrix4f.mapObjToWin(tmp.set(getMinX(), getMinY(), objZ), mat4PMv, viewport, winPos);
+ result.resize(winPos);
- FloatUtil.mapObjToWin(getMaxX(), getMinY(), objZ, mat4PMv, view, vec3Tmp0, vec4Tmp1, vec4Tmp2);
- // System.err.printf("AABBox.mapToWindow.p3: %f, %f, %f -> %f, %f, %f%n", getMaxX(), getMinY(), objZ, vec3Tmp0.x(), vec3Tmp0.y(), vec3Tmp0.z());
- result.resize(vec3Tmp0);
+ Matrix4f.mapObjToWin(tmp.set(getMinX(), getMaxY(), objZ), mat4PMv, viewport, winPos);
+ result.resize(winPos);
- FloatUtil.mapObjToWin(getMaxX(), getMaxY(), objZ, mat4PMv, view, vec3Tmp0, vec4Tmp1, vec4Tmp2);
- // System.err.printf("AABBox.mapToWindow.p4: %f, %f, %f -> %f, %f, %f%n", getMaxX(), getMaxY(), objZ, vec3Tmp0.x(), vec3Tmp0.y(), vec3Tmp0.z());
- result.resize(vec3Tmp0);
+ Matrix4f.mapObjToWin(tmp.set(getMaxX(), getMaxY(), objZ), mat4PMv, viewport, winPos);
+ result.resize(winPos);
+
+ Matrix4f.mapObjToWin(tmp.set(getMaxX(), getMinY(), objZ), mat4PMv, viewport, winPos);
+ result.resize(winPos);
}
if( !useCenterZ ) {
final float objZ = getMaxZ();
- FloatUtil.mapObjToWin(getMinX(), getMinY(), objZ, mat4PMv, view, vec3Tmp0, vec4Tmp1, vec4Tmp2);
- result.resize(vec3Tmp0);
- FloatUtil.mapObjToWin(getMinX(), getMaxY(), objZ, mat4PMv, view, vec3Tmp0, vec4Tmp1, vec4Tmp2);
- result.resize(vec3Tmp0);
+ Matrix4f.mapObjToWin(tmp.set(getMinX(), getMinY(), objZ), mat4PMv, viewport, winPos);
+ result.resize(winPos);
+
+ Matrix4f.mapObjToWin(tmp.set(getMinX(), getMaxY(), objZ), mat4PMv, viewport, winPos);
+ result.resize(winPos);
- FloatUtil.mapObjToWin(getMaxX(), getMinY(), objZ, mat4PMv, view, vec3Tmp0, vec4Tmp1, vec4Tmp2);
- result.resize(vec3Tmp0);
+ Matrix4f.mapObjToWin(tmp.set(getMaxX(), getMaxY(), objZ), mat4PMv, viewport, winPos);
+ result.resize(winPos);
- FloatUtil.mapObjToWin(getMaxX(), getMaxY(), objZ, mat4PMv, view, vec3Tmp0, vec4Tmp1, vec4Tmp2);
- result.resize(vec3Tmp0);
+ Matrix4f.mapObjToWin(tmp.set(getMaxX(), getMinY(), objZ), mat4PMv, viewport, winPos);
+ result.resize(winPos);
}
if( DEBUG ) {
- System.err.printf("AABBox.mapToWindow: view[%d, %d], this %s -> %s%n", view[0], view[1], toString(), result.toString());
+ System.err.printf("AABBox.mapToWindow: view[%s], this %s -> %s%n", viewport, toString(), result.toString());
}
return result;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/math/geom/Frustum.java b/src/jogl/classes/com/jogamp/opengl/math/geom/Frustum.java
index 4d098cb72..f72154827 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/geom/Frustum.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/geom/Frustum.java
@@ -37,7 +37,7 @@ import com.jogamp.opengl.math.geom.Frustum.FovDesc;
/**
* Providing frustum {@link #getPlanes() planes} derived by different inputs
- * ({@link #updateByPMV(float[], int) P*MV}, ..) used to classify objects
+ * ({@link #updateFrustumPlanes(float[], int) P*MV}, ..) used to classify objects
* <ul>
* <li> {@link #classifyPoint(float[]) point} </li>
* <li> {@link #classifySphere(float[], float) sphere} </li>
@@ -120,7 +120,7 @@ public class Frustum {
* Use one of the <code>update(..)</code> methods to set the {@link #getPlanes() planes}.
* </p>
* @see #updateByPlanes(Plane[])
- * @see #updateByPMV(float[], int)
+ * @see #updateFrustumPlanes(float[], int)
*/
public Frustum() {
for (int i = 0; i < 6; ++i) {
@@ -162,11 +162,6 @@ public class Frustum {
}
/** Return distance of plane to given point, see {@link #distanceTo(float, float, float)}. */
- public final float distanceTo(final float[] p) {
- return n.x() * p[0] + n.y() * p[1] + n.z() * p[2] + d;
- }
-
- /** Return distance of plane to given point, see {@link #distanceTo(float, float, float)}. */
public final float distanceTo(final Vec3f p) {
return n.x() * p.x() + n.y() * p.y() + n.z() * p.z() + d;
}
@@ -254,87 +249,14 @@ public class Frustum {
/**
* Calculate the frustum planes in world coordinates
- * using the passed float[16] as premultiplied P*MV (column major order).
+ * using the passed premultiplied P*MV (column major order) matrix.
* <p>
* Frustum plane's normals will point to the inside of the viewing frustum,
* as required by this class.
* </p>
*/
- public void updateByPMV(final float[] pmv, final int pmv_off) {
- // Left: a = m41 + m11, b = m42 + m12, c = m43 + m13, d = m44 + m14 - [1..4] column-major
- // Left: a = m30 + m00, b = m31 + m01, c = m32 + m02, d = m33 + m03 - [0..3] column-major
- {
- final Plane p = planes[LEFT];
- final Vec3f p_n = p.n;
- p_n.set( pmv[ pmv_off + 3 + 0 * 4 ] + pmv[ pmv_off + 0 + 0 * 4 ],
- pmv[ pmv_off + 3 + 1 * 4 ] + pmv[ pmv_off + 0 + 1 * 4 ],
- pmv[ pmv_off + 3 + 2 * 4 ] + pmv[ pmv_off + 0 + 2 * 4 ] );
- p.d = pmv[ pmv_off + 3 + 3 * 4 ] + pmv[ pmv_off + 0 + 3 * 4 ];
- }
-
- // Right: a = m41 - m11, b = m42 - m12, c = m43 - m13, d = m44 - m14 - [1..4] column-major
- // Right: a = m30 - m00, b = m31 - m01, c = m32 - m02, d = m33 - m03 - [0..3] column-major
- {
- final Plane p = planes[RIGHT];
- final Vec3f p_n = p.n;
- p_n.set( pmv[ pmv_off + 3 + 0 * 4 ] - pmv[ pmv_off + 0 + 0 * 4 ],
- pmv[ pmv_off + 3 + 1 * 4 ] - pmv[ pmv_off + 0 + 1 * 4 ],
- pmv[ pmv_off + 3 + 2 * 4 ] - pmv[ pmv_off + 0 + 2 * 4 ] );
- p.d = pmv[ pmv_off + 3 + 3 * 4 ] - pmv[ pmv_off + 0 + 3 * 4 ];
- }
-
- // Bottom: a = m41 + m21, b = m42 + m22, c = m43 + m23, d = m44 + m24 - [1..4] column-major
- // Bottom: a = m30 + m10, b = m31 + m11, c = m32 + m12, d = m33 + m13 - [0..3] column-major
- {
- final Plane p = planes[BOTTOM];
- final Vec3f p_n = p.n;
- p_n.set( pmv[ pmv_off + 3 + 0 * 4 ] + pmv[ pmv_off + 1 + 0 * 4 ],
- pmv[ pmv_off + 3 + 1 * 4 ] + pmv[ pmv_off + 1 + 1 * 4 ],
- pmv[ pmv_off + 3 + 2 * 4 ] + pmv[ pmv_off + 1 + 2 * 4 ] );
- p.d = pmv[ pmv_off + 3 + 3 * 4 ] + pmv[ pmv_off + 1 + 3 * 4 ];
- }
-
- // Top: a = m41 - m21, b = m42 - m22, c = m43 - m23, d = m44 - m24 - [1..4] column-major
- // Top: a = m30 - m10, b = m31 - m11, c = m32 - m12, d = m33 - m13 - [0..3] column-major
- {
- final Plane p = planes[TOP];
- final Vec3f p_n = p.n;
- p_n.set( pmv[ pmv_off + 3 + 0 * 4 ] - pmv[ pmv_off + 1 + 0 * 4 ],
- pmv[ pmv_off + 3 + 1 * 4 ] - pmv[ pmv_off + 1 + 1 * 4 ],
- pmv[ pmv_off + 3 + 2 * 4 ] - pmv[ pmv_off + 1 + 2 * 4 ] );
- p.d = pmv[ pmv_off + 3 + 3 * 4 ] - pmv[ pmv_off + 1 + 3 * 4 ];
- }
-
- // Near: a = m41 + m31, b = m42 + m32, c = m43 + m33, d = m44 + m34 - [1..4] column-major
- // Near: a = m30 + m20, b = m31 + m21, c = m32 + m22, d = m33 + m23 - [0..3] column-major
- {
- final Plane p = planes[NEAR];
- final Vec3f p_n = p.n;
- p_n.set( pmv[ pmv_off + 3 + 0 * 4 ] + pmv[ pmv_off + 2 + 0 * 4 ],
- pmv[ pmv_off + 3 + 1 * 4 ] + pmv[ pmv_off + 2 + 1 * 4 ],
- pmv[ pmv_off + 3 + 2 * 4 ] + pmv[ pmv_off + 2 + 2 * 4 ] );
- p.d = pmv[ pmv_off + 3 + 3 * 4 ] + pmv[ pmv_off + 2 + 3 * 4 ];
- }
-
- // Far: a = m41 - m31, b = m42 - m32, c = m43 - m33, d = m44 - m34 - [1..4] column-major
- // Far: a = m30 - m20, b = m31 - m21, c = m32 + m22, d = m33 + m23 - [0..3] column-major
- {
- final Plane p = planes[FAR];
- final Vec3f p_n = p.n;
- p_n.set( pmv[ pmv_off + 3 + 0 * 4 ] - pmv[ pmv_off + 2 + 0 * 4 ],
- pmv[ pmv_off + 3 + 1 * 4 ] - pmv[ pmv_off + 2 + 1 * 4 ],
- pmv[ pmv_off + 3 + 2 * 4 ] - pmv[ pmv_off + 2 + 2 * 4 ] );
- p.d = pmv[ pmv_off + 3 + 3 * 4 ] - pmv[ pmv_off + 2 + 3 * 4 ];
- }
-
- // Normalize all planes
- for (int i = 0; i < 6; ++i) {
- final Plane p = planes[i];
- final Vec3f p_n = p.n;
- final float invLen = 1f / p_n.length();
- p_n.scale(invLen);
- p.d *= invLen;
- }
+ public void updateFrustumPlanes(final Matrix4f pmv) {
+ pmv.updateFrustumPlanes(this);
}
private static final boolean isOutsideImpl(final Plane p, final AABBox box) {
@@ -380,7 +302,7 @@ public class Frustum {
* @param p the point
* @return {@link Location} of point related to frustum planes
*/
- public final Location classifyPoint(final float[] p) {
+ public final Location classifyPoint(final Vec3f p) {
Location res = Location.INSIDE;
for (int i = 0; i < 6; ++i) {
@@ -400,7 +322,7 @@ public class Frustum {
* @param p the point
* @return true if outside of the frustum, otherwise inside or on a plane
*/
- public final boolean isPointOutside(final float[] p) {
+ public final boolean isPointOutside(final Vec3f p) {
return Location.OUTSIDE == classifyPoint(p);
}
@@ -411,7 +333,7 @@ public class Frustum {
* @param radius radius of the sphere
* @return {@link Location} of point related to frustum planes
*/
- public final Location classifySphere(final float[] p, final float radius) {
+ public final Location classifySphere(final Vec3f p, final float radius) {
Location res = Location.INSIDE; // fully inside
for (int i = 0; i < 6; ++i) {
@@ -434,7 +356,7 @@ public class Frustum {
* @param radius radius of the sphere
* @return true if outside of the frustum, otherwise inside or intersecting
*/
- public final boolean isSphereOutside(final float[] p, final float radius) {
+ public final boolean isSphereOutside(final Vec3f p, final float radius) {
return Location.OUTSIDE == classifySphere(p, radius);
}