From 15e60161787224e85172685f74dc0ac195969b51 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 5 Apr 2023 09:42:28 +0200 Subject: 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 .. --- .../jogamp/opengl/util/stereo/EyeParameter.java | 17 +++++---- .../util/stereo/LocationSensorParameter.java | 9 +++-- .../jogamp/opengl/util/stereo/StereoDevice.java | 15 ++++---- .../com/jogamp/opengl/util/stereo/StereoUtil.java | 44 ++++++++++------------ .../com/jogamp/opengl/util/stereo/ViewerPose.java | 20 ++++++---- .../stereo/generic/GenericStereoDeviceFactory.java | 7 ++-- 6 files changed, 59 insertions(+), 53 deletions(-) (limited to 'src/jogl/classes/com/jogamp/opengl/util/stereo') diff --git a/src/jogl/classes/com/jogamp/opengl/util/stereo/EyeParameter.java b/src/jogl/classes/com/jogamp/opengl/util/stereo/EyeParameter.java index 43a6cfc58..e0f465da7 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/stereo/EyeParameter.java +++ b/src/jogl/classes/com/jogamp/opengl/util/stereo/EyeParameter.java @@ -1,5 +1,5 @@ /** - * Copyright 2014 JogAmp Community. All rights reserved. + * Copyright 2014-2023 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -28,6 +28,7 @@ package com.jogamp.opengl.util.stereo; import com.jogamp.opengl.math.FovHVHalves; +import com.jogamp.opengl.math.Vec3f; /** * Constant single eye parameter of the viewer, relative to its {@link ViewerPose}. @@ -36,8 +37,8 @@ public final class EyeParameter { /** Eye number, 0 for the left eye and 1 for the right eye. */ public final int number; - /** float[3] eye position vector used to define eye height in meter relative to actor. */ - public final float[] positionOffset; + /** eye position vector used to define eye height in meter relative to actor. */ + public final Vec3f positionOffset; /** Field of view in both directions, may not be centered, either {@link FovHVHalves#inTangents} or radians. */ public final FovHVHalves fovhv; @@ -51,18 +52,18 @@ public final class EyeParameter { /** Z-axis eye relief in meter. */ public final float eyeReliefZ; - public EyeParameter(final int number, final float[] positionOffset, final FovHVHalves fovhv, + public EyeParameter(final int number, final Vec3f positionOffset, final FovHVHalves fovhv, final float distNoseToPupil, final float verticalDelta, final float eyeRelief) { this.number = number; - this.positionOffset = new float[3]; - System.arraycopy(positionOffset, 0, this.positionOffset, 0, 3); + this.positionOffset = new Vec3f(positionOffset); this.fovhv = fovhv; this.distNoseToPupilX = distNoseToPupil; this.distMiddleToPupilY = verticalDelta; this.eyeReliefZ = eyeRelief; } + @Override public final String toString() { - return "EyeParam[num "+number+", posOff["+positionOffset[0]+", "+positionOffset[1]+", "+positionOffset[2]+"], "+fovhv+ - ", distPupil[noseX "+distNoseToPupilX+", middleY "+distMiddleToPupilY+", reliefZ "+eyeReliefZ+"]]"; + return "EyeParam[num "+number+", posOff["+positionOffset+"], "+fovhv+ + ", distPupil[noseX "+distNoseToPupilX+", middleY "+distMiddleToPupilY+", reliefZ "+eyeReliefZ+"]]"; } } \ No newline at end of file diff --git a/src/jogl/classes/com/jogamp/opengl/util/stereo/LocationSensorParameter.java b/src/jogl/classes/com/jogamp/opengl/util/stereo/LocationSensorParameter.java index b795927cd..6294adee1 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/stereo/LocationSensorParameter.java +++ b/src/jogl/classes/com/jogamp/opengl/util/stereo/LocationSensorParameter.java @@ -1,5 +1,5 @@ /** - * Copyright 2015 JogAmp Community. All rights reserved. + * Copyright 2015-2023 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -27,6 +27,7 @@ */ package com.jogamp.opengl.util.stereo; +import com.jogamp.opengl.math.Matrix4f; import com.jogamp.opengl.math.geom.Frustum; /** @@ -38,13 +39,15 @@ public final class LocationSensorParameter { /** The {@link Frustum}'s {@link Frustum.FovDesc} description of the location sensor. */ public final Frustum.FovDesc frustumDesc; /** The {@link Frustum}'s float[16] projection matrix of the location sensor. */ - public final float[] frustumProjMat; + public final Matrix4f frustumProjMat; public LocationSensorParameter(final Frustum.FovDesc fovDesc) { this.frustumDesc = fovDesc; this.frustum = new Frustum(); - this.frustumProjMat = frustum.updateByFovDesc(new float[16], 0, true, fovDesc); + this.frustumProjMat = frustum.updateByFovDesc(new Matrix4f(), fovDesc); } + + @Override public final String toString() { return "LocationSensor["+frustumDesc+"]"; } diff --git a/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoDevice.java b/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoDevice.java index b6112650a..85e752302 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoDevice.java +++ b/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoDevice.java @@ -1,5 +1,5 @@ /** - * Copyright 2014 JogAmp Community. All rights reserved. + * Copyright 2014-2023 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -33,6 +33,7 @@ import com.jogamp.nativewindow.util.PointImmutable; import jogamp.opengl.Debug; import com.jogamp.opengl.math.FovHVHalves; +import com.jogamp.opengl.math.Vec3f; /** * Interface describing a native stereoscopic device @@ -94,7 +95,7 @@ public interface StereoDevice { public int getRequiredRotation(); /** - * Return the device default eye position offset for {@link #createRenderer(int, int, float[], FovHVHalves[], float)}. + * Return the device default eye position offset for {@link #createRenderer(int, int, Vec3f, FovHVHalves[], float)}. *

* Result is an array of float values for *