diff options
author | Sven Gothel <[email protected]> | 2023-04-05 09:42:28 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-04-05 09:42:28 +0200 |
commit | 15e60161787224e85172685f74dc0ac195969b51 (patch) | |
tree | 68f3b44be2b340cfb7903996cea4820512049463 /src/jogl/classes/com/jogamp/graph | |
parent | 603233b19373bfa157dd033132bff809af6a123f (diff) |
Math: Complete Matrix4f w/ Vec[234]f and adopt it throughout Quaternion, Ray, AABBox, Frustum, Stereo*, ... adding hook to PMVMatrix
Motivation was to simplify matrix + vector math usage, ease review and avoid usage bugs.
Matrix4f implementation uses dedicated float fields instead of an array.
Performance didn't increase much,
as JVM >= 11(?) has some optimizations to drop the array bounds check.
AMD64 + OpenJDK17
- Matrix4f.mul(a, b) got a roughly ~10% enhancement over FloatUtil.multMatrix(a, b, dest)
- Matrix4f.mul(b) roughly ~3% slower than FloatUtil.multMatrix(a, b, dest)
- FloatUtil.multMatrix(a, a_off, b, b_off, dest) is considerable slower than all
- Matrix4f.invert(..) roughly ~3% slower than FloatUtil.invertMatrix(..)
RaspberryPi 4b aarch64 + OpenJDK17
- Matrix4f.mul(a, b) got a roughly ~10% enhancement over FloatUtil.multMatrix(a, b, dest)
- Matrix4f.mul(b) roughly ~20% slower than FloatUtil.multMatrix(a, b)
- FloatUtil.multMatrix(a, a_off, b, b_off, dest) is considerable slower than all
- Matrix4f.invert(..) roughly ~4% slower than FloatUtil.invertMatrix(..)
Conclusion
- Matrix4f.mul(b) needs to be revised (esp for aarch64)
- Matrix4f.invert(..) should also not be slower ..
Diffstat (limited to 'src/jogl/classes/com/jogamp/graph')
-rw-r--r-- | src/jogl/classes/com/jogamp/graph/font/Font.java | 6 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/graph/geom/plane/AffineTransform.java | 52 |
2 files changed, 44 insertions, 14 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java index 4399bbad7..3d7e9f6a1 100644 --- a/src/jogl/classes/com/jogamp/graph/font/Font.java +++ b/src/jogl/classes/com/jogamp/graph/font/Font.java @@ -29,6 +29,7 @@ package com.jogamp.graph.font; import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.geom.plane.AffineTransform; +import com.jogamp.opengl.math.Vec3f; import com.jogamp.opengl.math.geom.AABBox; /** @@ -151,7 +152,7 @@ public interface Font { * @param dest AABBox instance set to this metrics boundary in font em-size [0..1] * @return the given and set AABBox 'dest' in font units */ - AABBox getBounds(final AABBox dest, final float[] tmpV3); + AABBox getBounds(final AABBox dest); } /** @@ -193,10 +194,9 @@ public interface Font { /** * Return the AABBox in font em-size [0..1], copying into given dest. * @param dest AABBox instance set to this metrics boundary in font em-size [0..1] - * @param tmpV3 caller provided temporary 3-component vector * @return the given and set AABBox 'dest' in font em-size [0..1] */ - AABBox getBounds(final AABBox dest, float[] tmpV3); + AABBox getBounds(final AABBox dest); /** * Return the AABBox in font em-size [0..1], creating a new copy. diff --git a/src/jogl/classes/com/jogamp/graph/geom/plane/AffineTransform.java b/src/jogl/classes/com/jogamp/graph/geom/plane/AffineTransform.java index 62cda0322..74036f97d 100644 --- a/src/jogl/classes/com/jogamp/graph/geom/plane/AffineTransform.java +++ b/src/jogl/classes/com/jogamp/graph/geom/plane/AffineTransform.java @@ -16,6 +16,7 @@ */ /** * @author Denis M. Kishenko + * @author Sven Gothel, (c) 2010-2023 */ package com.jogamp.graph.geom.plane; @@ -23,6 +24,8 @@ package com.jogamp.graph.geom.plane; import com.jogamp.graph.geom.Vertex; import com.jogamp.opengl.math.FloatUtil; +import com.jogamp.opengl.math.Vec2f; +import com.jogamp.opengl.math.Vec3f; import com.jogamp.opengl.math.geom.AABBox; public class AffineTransform implements Cloneable { @@ -53,17 +56,17 @@ public class AffineTransform implements Cloneable { /** * The values of transformation matrix */ - float m00; - float m10; - float m01; - float m11; - float m02; - float m12; + private float m00; + private float m10; + private float m01; + private float m11; + private float m02; + private float m12; /** * The transformation <code>type</code> */ - transient int type; + private transient int type; public AffineTransform() { setToIdentity(); @@ -404,10 +407,10 @@ public class AffineTransform implements Cloneable { * @return dst for chaining */ public final AABBox transform(final AABBox src, final AABBox dst) { - final float[] srcLo = src.getLow(); - final float[] srcHi = src.getHigh(); - dst.setSize(srcLo[0] * m00 + srcLo[1] * m01 + m02, srcLo[0] * m10 + srcLo[1] * m11 + m12, srcLo[2], - srcHi[0] * m00 + srcHi[1] * m01 + m02, srcHi[0] * m10 + srcHi[1] * m11 + m12, srcHi[2]); + final Vec3f lo = src.getLow(); + final Vec3f hi = src.getHigh(); + dst.setSize(lo.x() * m00 + lo.y() * m01 + m02, lo.x() * m10 + lo.y() * m11 + m12, lo.z(), + hi.x() * m00 + hi.y() * m01 + m02, hi.x() * m10 + hi.y() * m11 + m12, hi.z()); return dst; } @@ -475,6 +478,33 @@ public class AffineTransform implements Cloneable { } /** + * @param src source of transformation + * @param dst destination of transformation, maybe be equal to <code>src</code> + * @return dst for chaining + */ + public final Vec2f transform(final Vec2f src, final Vec2f dst) { + final float x = src.x(); + final float y = src.y(); + dst.setX( x * m00 + y * m01 + m02 ); + dst.setY( x * m10 + y * m11 + m12 ); + return dst; + } + + /** + * @param src source of transformation + * @param dst destination of transformation, maybe be equal to <code>src</code> + * @return dst for chaining + */ + public final Vec3f transform(final Vec3f src, final Vec3f dst) { + final float x = src.x(); + final float y = src.y(); + dst.setX( x * m00 + y * m01 + m02 ); + dst.setY( x * m10 + y * m11 + m12 ); + dst.setZ( src.z() ); // just copy z + return dst; + } + + /** * * @param src * @param dst |