diff options
Diffstat (limited to 'src/jogl/classes')
-rw-r--r-- | src/jogl/classes/com/jogamp/math/Matrix4f.java | 34 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/math/Quaternion.java | 24 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/math/geom/Frustum.java | 16 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/math/util/PMVMatrix4f.java | 2 |
4 files changed, 34 insertions, 42 deletions
diff --git a/src/jogl/classes/com/jogamp/math/Matrix4f.java b/src/jogl/classes/com/jogamp/math/Matrix4f.java index 06e20ed01..f4d5160cd 100644 --- a/src/jogl/classes/com/jogamp/math/Matrix4f.java +++ b/src/jogl/classes/com/jogamp/math/Matrix4f.java @@ -86,7 +86,7 @@ import com.jogamp.math.geom.Frustum.Plane; * @see com.jogamp.math.util.PMVMatrix4f * @see FloatUtil */ -public class Matrix4f { +public final class Matrix4f { /** * Creates a new identity matrix. @@ -1179,12 +1179,11 @@ public class Matrix4f { * Returns the rotation [m00 .. m22] fields converted to a Quaternion. * @param res resulting Quaternion * @return the resulting Quaternion for chaining. - * @see Quaternion#setFromMatrix(float, float, float, float, float, float, float, float, float) + * @see Quaternion#setFromMat(float, float, float, float, float, float, float, float, float) * @see #setToRotation(Quaternion) */ public final Quaternion getRotation(final Quaternion res) { - res.setFromMatrix(m00, m01, m02, m10, m11, m12, m20, m21, m22); - return res; + return res.setFromMat(m00, m01, m02, m10, m11, m12, m20, m21, m22); } /** @@ -1331,20 +1330,19 @@ public class Matrix4f { /** * Calculate the frustum planes in world coordinates - * using this premultiplied P*MV (column major order) matrix. + * using this column major order matrix, usually a projection (P) or premultiplied P*MV matrix. * <p> * Frustum plane's normals will point to the inside of the viewing frustum, * as required by the {@link Frustum} class. * </p> - * @see Frustum#updateFrustumPlanes(Matrix4f) + * @see Frustum#setFromMat(Matrix4f) */ - public Frustum updateFrustumPlanes(final Frustum frustum) { + public Frustum getFrustum(final Frustum frustum) { // 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 Frustum.Plane p = frustum.getPlanes()[Frustum.LEFT]; - final Vec3f p_n = p.n; - p_n.set( m30 + m00, + p.n.set( m30 + m00, m31 + m01, m32 + m02 ); p.d = m33 + m03; @@ -1354,8 +1352,7 @@ public class Matrix4f { // Right: a = m30 - m00, b = m31 - m01, c = m32 - m02, d = m33 - m03 - [0..3] column-major { final Frustum.Plane p = frustum.getPlanes()[Frustum.RIGHT]; - final Vec3f p_n = p.n; - p_n.set( m30 - m00, + p.n.set( m30 - m00, m31 - m01, m32 - m02 ); p.d = m33 - m03; @@ -1365,8 +1362,7 @@ public class Matrix4f { // Bottom: a = m30m10, b = m31m11, c = m32m12, d = m33m13 - [0..3] column-major { final Frustum.Plane p = frustum.getPlanes()[Frustum.BOTTOM]; - final Vec3f p_n = p.n; - p_n.set( m30 + m10, + p.n.set( m30 + m10, m31 + m11, m32 + m12 ); p.d = m33 + m13; @@ -1376,8 +1372,7 @@ public class Matrix4f { // Top: a = m30 - m10, b = m31 - m11, c = m32 - m12, d = m33 - m13 - [0..3] column-major { final Frustum.Plane p = frustum.getPlanes()[Frustum.TOP]; - final Vec3f p_n = p.n; - p_n.set( m30 - m10, + p.n.set( m30 - m10, m31 - m11, m32 - m12 ); p.d = m33 - m13; @@ -1387,8 +1382,7 @@ public class Matrix4f { // Near: a = m30m20, b = m31m21, c = m32m22, d = m33m23 - [0..3] column-major { final Frustum.Plane p = frustum.getPlanes()[Frustum.NEAR]; - final Vec3f p_n = p.n; - p_n.set( m30 + m20, + p.n.set( m30 + m20, m31 + m21, m32 + m22 ); p.d = m33 + m23; @@ -1398,8 +1392,7 @@ public class Matrix4f { // Far: a = m30 - m20, b = m31 - m21, c = m32m22, d = m33m23 - [0..3] column-major { final Frustum.Plane p = frustum.getPlanes()[Frustum.FAR]; - final Vec3f p_n = p.n; - p_n.set( m30 - m20, + p.n.set( m30 - m20, m31 - m21, m32 - m22 ); p.d = m33 - m23; @@ -2128,8 +2121,7 @@ public class Matrix4f { if( 0 >= growSize ) { throw new IndexOutOfBoundsException("Out of fixed stack size: "+this); } - final float[] newBuffer = - new float[buffer.length + growSize]; + final float[] newBuffer = new float[buffer.length + Math.max(length, growSize)]; System.arraycopy(buffer, 0, newBuffer, 0, position); buffer = newBuffer; } diff --git a/src/jogl/classes/com/jogamp/math/Quaternion.java b/src/jogl/classes/com/jogamp/math/Quaternion.java index 038745a51..f7a348b20 100644 --- a/src/jogl/classes/com/jogamp/math/Quaternion.java +++ b/src/jogl/classes/com/jogamp/math/Quaternion.java @@ -42,7 +42,7 @@ package com.jogamp.math; * See <a href="http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/index.htm">euclideanspace.com-Quaternion</a> * </p> */ -public class Quaternion { +public final class Quaternion { private float x, y, z, w; /** @@ -947,11 +947,11 @@ public class Quaternion { * </p> * * @return this quaternion for chaining. - * @see #setFromMatrix(Matrix4f) + * @see #setFromMat(Matrix4f) */ - public Quaternion setFromMatrix(final float m00, final float m01, final float m02, - final float m10, final float m11, final float m12, - final float m20, final float m21, final float m22) { + public Quaternion setFromMat(final float m00, final float m01, final float m02, + final float m10, final float m11, final float m12, + final float m20, final float m21, final float m22) { // Note: Other implementations uses 'T' w/o '+1f' and compares 'T >= 0' while adding missing 1f in sqrt expr. // However .. this causes setLookAt(..) to fail and actually violates the 'trace definition'. @@ -992,7 +992,7 @@ public class Quaternion { } /** - * Compute the quaternion from a 3x3 column rotation matrix + * Compute the quaternion from a 3x3 column rotation matrix from {@link Matrix4f} instance * <p> * See <a href="ftp://ftp.cis.upenn.edu/pub/graphics/shoemake/quatut.ps.Z">Graphics Gems Code</a>,<br/> * <a href="http://mathworld.wolfram.com/MatrixTrace.html">MatrixTrace</a>. @@ -1003,9 +1003,9 @@ public class Quaternion { * * @return this quaternion for chaining. * @see Matrix4f#getRotation(Quaternion) - * @see #setFromMatrix(float, float, float, float, float, float, float, float, float) + * @see #setFromMat(float, float, float, float, float, float, float, float, float) */ - public Quaternion setFromMatrix(final Matrix4f m) { + public Quaternion setFromMat(final Matrix4f m) { return m.getRotation(this); } @@ -1021,8 +1021,8 @@ public class Quaternion { * @param matrix float[16] store for the resulting normalized column matrix 4x4 * @return the given matrix store * @see <a href="http://web.archive.org/web/20041029003853/http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q54">Matrix-FAQ Q54</a> - * @see #setFromMatrix(Matrix4f) - * @see #setFromMatrix(float, float, float, float, float, float, float, float, float) + * @see #setFromMat(Matrix4f) + * @see #setFromMat(float, float, float, float, float, float, float, float, float) */ public final float[] toMatrix(final float[] matrix) { // pre-multiply scaled-reciprocal-magnitude to reduce multiplications @@ -1086,7 +1086,7 @@ public class Quaternion { * @param matrix store for the resulting normalized column matrix 4x4 * @return the given matrix store * @see <a href="http://web.archive.org/web/20041029003853/http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q54">Matrix-FAQ Q54</a> - * @see #setFromMatrix(float, float, float, float, float, float, float, float, float) + * @see #setFromMat(float, float, float, float, float, float, float, float, float) * @see Matrix4f#setToRotation(Quaternion) */ public final Matrix4f toMatrix(final Matrix4f matrix) { @@ -1105,7 +1105,7 @@ public class Quaternion { * @return this quaternion for chaining. */ public final Quaternion setFromAxes(final Vec3f xAxis, final Vec3f yAxis, final Vec3f zAxis) { - return setFromMatrix(xAxis.x(), yAxis.x(), zAxis.x(), + return setFromMat(xAxis.x(), yAxis.x(), zAxis.x(), xAxis.y(), yAxis.y(), zAxis.y(), xAxis.z(), yAxis.z(), zAxis.z()); } diff --git a/src/jogl/classes/com/jogamp/math/geom/Frustum.java b/src/jogl/classes/com/jogamp/math/geom/Frustum.java index 6efc2529c..7d35fab97 100644 --- a/src/jogl/classes/com/jogamp/math/geom/Frustum.java +++ b/src/jogl/classes/com/jogamp/math/geom/Frustum.java @@ -78,7 +78,7 @@ import com.jogamp.math.Vec4f; * </pre> * </p> */ -public class Frustum { +public final class Frustum { /** * {@link Frustum} description by {@link #fovhv} and {@link #zNear}, {@link #zFar}. */ @@ -345,7 +345,7 @@ public class Frustum { * <li>The given {@link FovDesc} will be transformed * into the given perspective matrix (column major order) first, * see {@link Matrix4f#setToPerspective(FovHVHalves, float, float)}.</li> - * <li>Then the perspective matrix is used to {@link Matrix4f#updateFrustumPlanes(Frustum)} this instance.</li> + * <li>Then the perspective matrix is used to {@link Matrix4f#getFrustum(Frustum)} this instance.</li> * </ul> * </p> * <p> @@ -357,26 +357,26 @@ public class Frustum { * @param fovDesc {@link Frustum} {@link FovDesc} * @return given matrix for chaining * @see Matrix4f#setToPerspective(FovHVHalves, float, float) - * @see Matrix4f#updateFrustumPlanes(Frustum) + * @see Matrix4f#getFrustum(Frustum) * @see Matrix4f#getFrustum(Frustum, FovDesc) */ public Matrix4f updateByFovDesc(final Matrix4f m, final FovDesc fovDesc) { m.setToPerspective(fovDesc.fovhv, fovDesc.zNear, fovDesc.zFar); - m.updateFrustumPlanes(this); + setFromMat(m); return m; } /** * Calculate the frustum planes in world coordinates - * using the passed premultiplied P*MV (column major order) matrix. + * using the passed column major order matrix, usually a projection (P) or premultiplied P*MV matrix. * <p> * Frustum plane's normals will point to the inside of the viewing frustum, * as required by this class. * </p> - * @see Matrix4f#updateFrustumPlanes(Frustum) + * @see Matrix4f#getFrustum(Frustum) */ - public Frustum updateFrustumPlanes(final Matrix4f pmv) { - return pmv.updateFrustumPlanes(this); + public Frustum setFromMat(final Matrix4f pmv) { + return pmv.getFrustum(this); } /** diff --git a/src/jogl/classes/com/jogamp/math/util/PMVMatrix4f.java b/src/jogl/classes/com/jogamp/math/util/PMVMatrix4f.java index 7d02904be..650289d1f 100644 --- a/src/jogl/classes/com/jogamp/math/util/PMVMatrix4f.java +++ b/src/jogl/classes/com/jogamp/math/util/PMVMatrix4f.java @@ -1259,7 +1259,7 @@ public class PMVMatrix4f { if( null == frustum ) { frustum = new Frustum(); } - getPMv().updateFrustumPlanes(frustum); + frustum.setFromMat(getPMv()); dirtyBits &= ~FRUSTUM; } return frustum; |