From 53966f92042d44483cb44f6c6b3c95a6a1fdd325 Mon Sep 17 00:00:00 2001
From: Sven Gothel
Date: Sat, 18 Jul 2015 03:50:02 +0200
Subject: Bug 1151 - Working OculusVR SDK 0.5.0.1 on GNU/Linux w/ Positional
Tracker (DK2)
Note: The ovrd server must run, otherwise no device is being detected.
General Stereo API Changes:
- EyePose -> ViewerPose
- We only use the viewer pose and derive the pupile position
via EyeParameter.
- Hence we reduce complexity.
- A single ViewerPose will be maintained by StereoDeviceRenderer
- position is in meter, allowing StereoGLEventListener to scale
device independent.
- StereoDevice receives knowledge of certain sensors,
to be queried and used for start-sensors.
OVR:
- Simply apply the above general changes
- Build: Remove [more] unused API entries for SDK rendering
---
.../com/jogamp/opengl/util/stereo/EyePose.java | 69 ---------------
.../opengl/util/stereo/StereoClientRenderer.java | 7 +-
.../jogamp/opengl/util/stereo/StereoDevice.java | 76 +++++++++++++++--
.../opengl/util/stereo/StereoDeviceRenderer.java | 22 ++---
.../opengl/util/stereo/StereoGLEventListener.java | 6 +-
.../com/jogamp/opengl/util/stereo/StereoUtil.java | 41 +++++++--
.../com/jogamp/opengl/util/stereo/ViewerPose.java | 74 +++++++++++++++++
.../stereo/generic/GenericStereoDeviceConfig.java | 13 ++-
.../stereo/generic/GenericStereoDeviceFactory.java | 3 +
.../opengl/util/stereo/GenericStereoDevice.java | 56 ++++++++++---
.../util/stereo/GenericStereoDeviceRenderer.java | 46 +++++-----
.../jogamp/opengl/oculusvr/OVRStereoDevice.java | 93 +++++++++++++++++----
.../opengl/oculusvr/OVRStereoDeviceFactory.java | 8 +-
.../opengl/oculusvr/OVRStereoDeviceRenderer.java | 97 ++++++++++++----------
.../classes/jogamp/opengl/oculusvr/OVRUtil.java | 37 +++++++++
.../junit/jogl/acore/TestVersionSemanticsNOUI.java | 8 +-
.../opengl/test/junit/jogl/demos/es2/GearsES2.java | 11 ++-
.../junit/jogl/demos/es2/av/MovieSBSStereo.java | 14 ++--
.../test/junit/jogl/stereo/StereoDemo01.java | 8 +-
19 files changed, 478 insertions(+), 211 deletions(-)
delete mode 100644 src/jogl/classes/com/jogamp/opengl/util/stereo/EyePose.java
create mode 100644 src/jogl/classes/com/jogamp/opengl/util/stereo/ViewerPose.java
(limited to 'src')
diff --git a/src/jogl/classes/com/jogamp/opengl/util/stereo/EyePose.java b/src/jogl/classes/com/jogamp/opengl/util/stereo/EyePose.java
deleted file mode 100644
index aa64ff130..000000000
--- a/src/jogl/classes/com/jogamp/opengl/util/stereo/EyePose.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * Copyright 2014 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:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package com.jogamp.opengl.util.stereo;
-
-import com.jogamp.opengl.math.Quaternion;
-
-/**
- * Position and orientation of one eye.
- */
-public final class EyePose {
- /** Eye number, 0
for the left eye and 1
for the right eye. */
- public final int number;
-
- /** float[3] eye position vector. */
- public final float[] position;
-
- /** Eye orientation */
- public final Quaternion orientation;
-
- public EyePose(final int number) {
- this.number = number;
- this.position = new float[3];
- this.orientation = new Quaternion();
- }
- public EyePose(final int number, final float[] position, final Quaternion orientation) {
- this(number);
- set(position, orientation);
- }
-
- /** Set position and orientation of this instance. */
- public final void set(final float[] position, final Quaternion orientation) {
- System.arraycopy(position, 0, this.position, 0, 3);
- this.orientation.set(orientation);
- }
- /** Set position and orientation of this instance. */
- public final void setPosition(final float posX, final float posY, final float posZ) {
- position[0] = posX;
- position[1] = posY;
- position[2] = posZ;
- }
- public final String toString() {
- return "EyePose[num "+number+", pos["+position[0]+", "+position[1]+", "+position[2]+"], "+orientation+"]";
- }
-}
\ No newline at end of file
diff --git a/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoClientRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoClientRenderer.java
index b1a38ab06..8ecd8b8f7 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoClientRenderer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoClientRenderer.java
@@ -189,10 +189,7 @@ public class StereoClientRenderer implements GLEventListener {
final int[] eyeOrder = deviceRenderer.getDevice().getEyeRenderOrder();
final int eyeCount = eyeOrder.length;
- // Update eye pos upfront to have same (almost) results
- for(int eyeNum=0; eyeNum
+ * Implementation shall {@link #stopSensors() stop sensors} and free all resources.
+ *
+ */
public void dispose();
/**
@@ -96,12 +116,58 @@ public interface StereoDevice {
*/
public FovHVHalves[] getDefaultFOV();
- /** Start or stop sensors. Returns true if action was successful, otherwise false. */
- public boolean startSensors(boolean start);
+ /**
+ * Start desired and required sensors. Returns true if action was successful, otherwise false.
+ *
+ * Method fails if required sensors are not {@link #getSupportedSensorBits() supported}.
+ *
+ * @param desiredSensorBits the desired optional sensors
+ * @param requiredSensorBits the required sensors
+ * @see #stopSensors()
+ * @see #getSensorsStarted()
+ * @see #getSupportedSensorBits()
+ * @see #getEnabledSensorBits()
+ */
+ public boolean startSensors(int desiredSensorBits, int requiredSensorBits);
+
+ /**
+ * Stop sensors. Returns true if action was successful, otherwise false.
+ * @see #startSensors(int, int)
+ * @see #getSensorsStarted()
+ * @see #getSupportedSensorBits()
+ * @see #getEnabledSensorBits()
+ */
+ public boolean stopSensors();
- /** Return true if sensors have been started, false otherwise */
+ /**
+ * Return true if sensors have been started, false otherwise.
+ * @see #startSensors(int, int)
+ * @see #stopSensors()
+ * @see #getSupportedSensorBits()
+ * @see #getEnabledSensorBits()
+ */
public boolean getSensorsStarted();
+ /**
+ * Returns the supported sensor capability bits, e.g. {@link #SENSOR_ORIENTATION}, {@link #SENSOR_POSITION}
+ * of the {@link StereoDevice}.
+ * @see #startSensors(int, int)
+ * @see #stopSensors()
+ * @see #getSensorsStarted()
+ * @see #getEnabledSensorBits()
+ */
+ public int getSupportedSensorBits();
+
+ /**
+ * Returns the actual used sensor capability bits, e.g. {@link #SENSOR_ORIENTATION}, {@link #SENSOR_POSITION}
+ * in case the {@link #getSupportedSensorBits() device supports} them and if they are enabled.
+ * @see #startSensors(int, int)
+ * @see #stopSensors()
+ * @see #getSensorsStarted()
+ * @see #getSupportedSensorBits()
+ */
+ public int getEnabledSensorBits();
+
/**
* Returns an array of the preferred eye rendering order.
* The array length reflects the supported eye count.
@@ -112,7 +178,7 @@ public interface StereoDevice {
public int[] getEyeRenderOrder();
/**
- * Returns the supported distortion compensation by the {@link StereoDeviceRenderer},
+ * Returns the supported distortion compensation of the {@link StereoDeviceRenderer},
* e.g. {@link StereoDeviceRenderer#DISTORTION_BARREL}, {@link StereoDeviceRenderer#DISTORTION_CHROMATIC}, etc.
* @see StereoDeviceRenderer#getDistortionBits()
* @see #createRenderer(int, int, float[], FovHVHalves[], float, int)
diff --git a/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoDeviceRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoDeviceRenderer.java
index 2078a00a2..0d6539634 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoDeviceRenderer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoDeviceRenderer.java
@@ -42,10 +42,10 @@ import com.jogamp.opengl.math.FovHVHalves;
*
* - device.{@link #beginFrame(GL)}
* - For both eyes:
- * - device.{@link #updateEyePose(int)}
+ * - device.{@link #updateViewerPose(int)}
* - if device.{@link #ppAvailable()}: Set the render target, e.g. FBO
* - Set the viewport using {@link Eye#getViewport()}
- * - {@link StereoGLEventListener#reshapeForEye(com.jogamp.opengl.GLAutoDrawable, int, int, int, int, EyeParameter, EyePose) upstream.reshapeEye(..)}
+ * - {@link StereoGLEventListener#reshapeForEye(com.jogamp.opengl.GLAutoDrawable, int, int, int, int, EyeParameter, ViewerPose) upstream.reshapeEye(..)}
* - {@link StereoGLEventListener#display(com.jogamp.opengl.GLAutoDrawable, int) upstream.display(..)}.
*
* - Reset the viewport
@@ -89,7 +89,7 @@ public interface StereoDeviceRenderer {
/**
* Distortion Bit: Timewarp distortion technique to predict
- * {@link EyePose} movement to reduce latency.
+ * {@link ViewerPose} movement to reduce latency.
*
* FIXME: Explanation needs refinement!
*
@@ -113,10 +113,6 @@ public interface StereoDeviceRenderer {
* Returns the {@link EyeParameter} of this eye.
*/
public EyeParameter getEyeParameter();
- /**
- * Returns the last {@link EyePose} of this eye.
- */
- public EyePose getLastEyePose();
}
/**
@@ -125,10 +121,14 @@ public interface StereoDeviceRenderer {
public Eye getEye(final int eyeNum);
/**
- * Updates the {@link Eye#getLastEyePose()}
- * for the denoted eyeNum
.
+ * Updates the {@link ViewerPose} and returns it.
+ */
+ public ViewerPose updateViewerPose();
+
+ /**
+ * Returns the last {@link ViewerPose}.
*/
- public EyePose updateEyePose(final int eyeNum);
+ public ViewerPose getLastViewerPose();
/**
* Returns used distortion compensation bits, e.g. {@link #DISTORTION_BARREL},
@@ -219,7 +219,7 @@ public interface StereoDeviceRenderer {
/**
* Begin stereoscopic post-processing, see {@link #ppAvailable()}.
*
- * {@link #updateEyePose(int)} for both eyes must be called upfront
+ * {@link #updateViewerPose(int)} for both eyes must be called upfront
* when rendering upstream {@link StereoGLEventListener}.
*
*
diff --git a/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoGLEventListener.java b/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoGLEventListener.java
index c1a06796c..59f38f2af 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoGLEventListener.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoGLEventListener.java
@@ -51,7 +51,7 @@ public interface StereoGLEventListener extends CustomGLEventListener {
*
*
* The client shall also update it's projection- and modelview matrices according
- * to the given {@link EyeParameter} and {@link EyePose}.
+ * to the given {@link EyeParameter} and {@link ViewerPose}.
*
*
* For efficiency the GL viewport has already been updated
@@ -64,11 +64,11 @@ public interface StereoGLEventListener extends CustomGLEventListener {
* @param width viewport width in pixel units
* @param height viewport height in pixel units
* @param eyeParam constant eye parameter, i.e. FOV and IPD
- * @param eyePose current eye position and orientation
+ * @param viewerPose current viewer position and orientation
* @see FloatUtil#makePerspective(float[], int, boolean, com.jogamp.opengl.math.FloatUtil.FovHVHalves, float, float)
*/
public void reshapeForEye(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height,
- final EyeParameter eyeParam, final EyePose eyePose);
+ final EyeParameter eyeParam, final ViewerPose viewerPose);
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoUtil.java b/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoUtil.java
index b0ca4ddb2..b6f76a343 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoUtil.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/stereo/StereoUtil.java
@@ -97,23 +97,51 @@ public class StereoUtil {
return sb.toString();
}
+ /** See {@link StereoDevice#getSupportedSensorBits()} and {@link StereoDevice#getEnabledSensorBits()}. */
+ public static boolean usesOrientationSensor(final int sensorBits) { return 0 != ( sensorBits & StereoDevice.SENSOR_ORIENTATION ) ; }
+ /** See {@link StereoDevice#getSupportedSensorBits()} and {@link StereoDevice#getEnabledSensorBits()}. */
+ public static boolean usesYawCorrectionSensor(final int sensorBits) { return 0 != ( sensorBits & StereoDevice.SENSOR_YAW_CORRECTION ) ; }
+ /** See {@link StereoDevice#getSupportedSensorBits()} and {@link StereoDevice#getEnabledSensorBits()}. */
+ public static boolean usesPositionSensor(final int sensorBits) { return 0 != ( sensorBits & StereoDevice.SENSOR_POSITION ) ; }
+
+ /** See {@link StereoDevice#getSupportedSensorBits()} and {@link StereoDevice#getEnabledSensorBits()}. */
+ public static String sensorBitsToString(final int sensorBits) {
+ boolean appendComma = false;
+ final StringBuilder sb = new StringBuilder();
+ if( usesOrientationSensor(sensorBits) ) {
+ if( appendComma ) { sb.append(", "); };
+ sb.append("orientation"); appendComma=true;
+ }
+ if( usesYawCorrectionSensor(sensorBits) ) {
+ if( appendComma ) { sb.append(", "); };
+ sb.append("yaw-corr"); appendComma=true;
+ }
+ if( usesPositionSensor(sensorBits) ) {
+ if( appendComma ) { sb.append(", "); };
+ sb.append("position"); appendComma=true;
+ }
+ return sb.toString();
+ }
+
/**
* Calculates the Side By Side, SBS, projection- and modelview matrix for one eye.
*
- * {@link #updateEyePose(int)} must be called upfront.
+ * {@link #updateViewerPose(int)} must be called upfront.
*
*
* This method merely exist as an example implementation to compute the matrices,
* which shall be adopted by the
- * {@link CustomGLEventListener#reshape(com.jogamp.opengl.GLAutoDrawable, int, int, int, int, EyeParameter, EyePose) upstream client code}.
+ * {@link CustomGLEventListener#reshape(com.jogamp.opengl.GLAutoDrawable, int, int, int, int, EyeParameter, ViewerPose) upstream client code}.
*
- * @param eyeNum eye denominator
+ * @param viewerPose
+ * @param eye
* @param zNear frustum near value
* @param zFar frustum far value
* @param mat4Projection float[16] projection matrix result
* @param mat4Modelview float[16] modelview matrix result
*/
- public static void getSBSUpstreamPMV(final Eye eye, final float zNear, final float zFar,
+ public static void getSBSUpstreamPMV(final ViewerPose viewerPose, final Eye eye,
+ final float zNear, final float zFar,
final float[] mat4Projection, final float[] mat4Modelview) {
final float[] mat4Tmp1 = new float[16];
final float[] mat4Tmp2 = new float[16];
@@ -122,7 +150,6 @@ public class StereoUtil {
final float[] vec3Tmp3 = new float[3];
final EyeParameter eyeParam = eye.getEyeParameter();
- final EyePose eyePose = eye.getLastEyePose();
//
// Projection
@@ -135,10 +162,10 @@ public class StereoUtil {
final Quaternion rollPitchYaw = new Quaternion();
// private final float eyeYaw = FloatUtil.PI; // 180 degrees in radians
// rollPitchYaw.rotateByAngleY(eyeYaw);
- final float[] shiftedEyePos = rollPitchYaw.rotateVector(vec3Tmp1, 0, eyePose.position, 0);
+ final float[] shiftedEyePos = rollPitchYaw.rotateVector(vec3Tmp1, 0, viewerPose.position, 0);
VectorUtil.addVec3(shiftedEyePos, shiftedEyePos, eyeParam.positionOffset);
- rollPitchYaw.mult(eyePose.orientation);
+ rollPitchYaw.mult(viewerPose.orientation);
final float[] up = rollPitchYaw.rotateVector(vec3Tmp2, 0, VectorUtil.VEC3_UNIT_Y, 0);
final float[] forward = rollPitchYaw.rotateVector(vec3Tmp3, 0, VectorUtil.VEC3_UNIT_Z_NEG, 0);
final float[] center = VectorUtil.addVec3(forward, shiftedEyePos, forward);
diff --git a/src/jogl/classes/com/jogamp/opengl/util/stereo/ViewerPose.java b/src/jogl/classes/com/jogamp/opengl/util/stereo/ViewerPose.java
new file mode 100644
index 000000000..40411ac88
--- /dev/null
+++ b/src/jogl/classes/com/jogamp/opengl/util/stereo/ViewerPose.java
@@ -0,0 +1,74 @@
+/**
+ * Copyright 2014 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:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.util.stereo;
+
+import com.jogamp.opengl.math.Quaternion;
+
+/**
+ * Position and orientation of viewer.
+ */
+public final class ViewerPose {
+ /**
+ * float[3] position of viewer in meter.
+ *
+ * Apply the following to resolve the actual eye position:
+ *
+ * - {@link EyeParameter#positionOffset positionOffset} for head.
+ * - [{@link EyeParameter#distNoseToPupilX distNoseToPupilX}, {@link EyeParameter#distMiddleToPupilY distMiddleToPupilY}, {@link EyeParameter#eyeReliefZ eyeReliefZ}] for pupil
+ *
+ *
+ */
+ public final float[] position;
+
+ /** Orientation of viewer. */
+ public final Quaternion orientation;
+
+ public ViewerPose() {
+ this.position = new float[3];
+ this.orientation = new Quaternion();
+ }
+ public ViewerPose(final float[] position, final Quaternion orientation) {
+ this();
+ set(position, orientation);
+ }
+
+ /** Set {@link #position} and {@link #orientation}. */
+ public final void set(final float[] position, final Quaternion orientation) {
+ System.arraycopy(position, 0, this.position, 0, 3);
+ this.orientation.set(orientation);
+ }
+ /** Set position and orientation of this instance. */
+ public final void setPosition(final float posX, final float posY, final float posZ) {
+ position[0] = posX;
+ position[1] = posY;
+ position[2] = posZ;
+ }
+ public final String toString() {
+ return "ViewerPose[pos["+position[0]+", "+position[1]+", "+position[2]+"], "+orientation+"]";
+ }
+}
\ No newline at end of file
diff --git a/src/jogl/classes/com/jogamp/opengl/util/stereo/generic/GenericStereoDeviceConfig.java b/src/jogl/classes/com/jogamp/opengl/util/stereo/generic/GenericStereoDeviceConfig.java
index 04fd8343c..44129de02 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/stereo/generic/GenericStereoDeviceConfig.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/stereo/generic/GenericStereoDeviceConfig.java
@@ -37,6 +37,7 @@ import com.jogamp.opengl.util.stereo.EyeParameter;
import com.jogamp.opengl.util.stereo.StereoDeviceConfig;
import com.jogamp.opengl.util.stereo.StereoDeviceRenderer;
import com.jogamp.opengl.util.stereo.StereoUtil;
+import com.jogamp.opengl.util.stereo.StereoDevice;
/**
* Configuration for {@link GenericStereoDevice}s.
@@ -54,6 +55,7 @@ public class GenericStereoDeviceConfig extends StereoDeviceConfig {
final float interpupillaryDistanceInMeters,
final int[] eyeRenderOrder,
final EyeParameter[] defaultEyeParam,
+ final int supportedSensorBits,
final DistortionMesh.Producer distortionMeshProducer,
final int supportedDistortionBits,
final int recommendedDistortionBits,
@@ -71,6 +73,7 @@ public class GenericStereoDeviceConfig extends StereoDeviceConfig {
this.interpupillaryDistanceInMeters = interpupillaryDistanceInMeters;
this.eyeRenderOrder = eyeRenderOrder;
this.defaultEyeParam = defaultEyeParam;
+ this.supportedSensorBits = supportedSensorBits;
this.distortionMeshProducer = distortionMeshProducer;
this.supportedDistortionBits = supportedDistortionBits;
this.recommendedDistortionBits = recommendedDistortionBits;
@@ -92,6 +95,7 @@ public class GenericStereoDeviceConfig extends StereoDeviceConfig {
this.interpupillaryDistanceInMeters = source.interpupillaryDistanceInMeters;
this.eyeRenderOrder = source.eyeRenderOrder;
this.defaultEyeParam = source.defaultEyeParam;
+ this.supportedSensorBits = source.supportedSensorBits;
this.distortionMeshProducer = source.distortionMeshProducer;
this.supportedDistortionBits = source.supportedDistortionBits;
this.recommendedDistortionBits = source.recommendedDistortionBits;
@@ -141,7 +145,8 @@ public class GenericStereoDeviceConfig extends StereoDeviceConfig {
" [m], eyeParam "+Arrays.toString(defaultEyeParam)+
", distortionBits[supported ["+StereoUtil.distortionBitsToString(supportedDistortionBits)+
"], recommended ["+StereoUtil.distortionBitsToString(recommendedDistortionBits)+
- "], minimum ["+StereoUtil.distortionBitsToString(minimumDistortionBits)+"]]]";
+ "], minimum ["+StereoUtil.distortionBitsToString(minimumDistortionBits)+"]]"+
+ ", sensorBits[supported ["+StereoUtil.sensorBitsToString(supportedSensorBits)+"]]]";
}
/** Configuration Name */
@@ -164,9 +169,13 @@ public class GenericStereoDeviceConfig extends StereoDeviceConfig {
public final float[/*per-eye*/][/*xy*/] pupilCenterFromTopLeft;
public final int[] eyeRenderOrder;
public final EyeParameter[] defaultEyeParam;
+
+ /** Supported sensor bits, see {@link StereoDevice#SENSOR_ORIENTATION}. */
+ public final int supportedSensorBits;
+
public final DistortionMesh.Producer distortionMeshProducer;
- /** Supported distortion bits, see {@link StereoDeviceRenderer.DISTORTION_BARREL}. */
+ /** Supported distortion bits, see {@link StereoDeviceRenderer#DISTORTION_BARREL}. */
public final int supportedDistortionBits;
/** Recommended distortion bits, see {@link StereoDeviceRenderer.DISTORTION_BARREL}. */
public final int recommendedDistortionBits;
diff --git a/src/jogl/classes/com/jogamp/opengl/util/stereo/generic/GenericStereoDeviceFactory.java b/src/jogl/classes/com/jogamp/opengl/util/stereo/generic/GenericStereoDeviceFactory.java
index 6adb96ba4..957758e78 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/stereo/generic/GenericStereoDeviceFactory.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/stereo/generic/GenericStereoDeviceFactory.java
@@ -70,6 +70,7 @@ public class GenericStereoDeviceFactory extends StereoDeviceFactory {
// degrees: 45/2 l, 45/2 r, 45/2 * aspect t, 45/2 * aspect b
FovHVHalves.byFovyRadianAndAspect(45f*d2r, 1280f / 800f),
0f /* distNoseToPupil */, 0f /* verticalDelta */, 0f /* eyeReliefInMeters */) },
+ 0, // supported sensor bits
null, // mash producer distortion bits
0, // supported distortion bits
0, // recommended distortion bits
@@ -114,6 +115,7 @@ public class GenericStereoDeviceFactory extends StereoDeviceFactory {
interpupillaryDistanceInMeters/2f /* distNoseToPupil */, 0f /* verticalDelta */, 0.010f /* eyeReliefInMeters */),
new EyeParameter(1, defaultEyePositionOffset, defaultSBSEyeFovRight,
-interpupillaryDistanceInMeters/2f /* distNoseToPupil */, 0f /* verticalDelta */, 0.010f /* eyeReliefInMeters */) },
+ 0, // supported sensor bits
null, // mash producer distortion bits
0, // supported distortion bits
0, // recommended distortion bits
@@ -171,6 +173,7 @@ public class GenericStereoDeviceFactory extends StereoDeviceFactory {
interpupillaryDistanceInMeters/2f /* distNoseToPupil */, 0f /* verticalDelta */, 0.010f /* eyeReliefInMeters */),
new EyeParameter(1, defaultEyePositionOffset, defaultSBSEyeFovRight,
-interpupillaryDistanceInMeters/2f /* distNoseToPupil */, 0f /* verticalDelta */, 0.010f /* eyeReliefInMeters */) },
+ 0, // supported sensor bits
lenseDistMeshProduce,
// supported distortion bits
StereoDeviceRenderer.DISTORTION_BARREL | StereoDeviceRenderer.DISTORTION_CHROMATIC | StereoDeviceRenderer.DISTORTION_VIGNETTE,
diff --git a/src/jogl/classes/jogamp/opengl/util/stereo/GenericStereoDevice.java b/src/jogl/classes/jogamp/opengl/util/stereo/GenericStereoDevice.java
index 9c0a5045b..491535dc1 100644
--- a/src/jogl/classes/jogamp/opengl/util/stereo/GenericStereoDevice.java
+++ b/src/jogl/classes/jogamp/opengl/util/stereo/GenericStereoDevice.java
@@ -39,6 +39,7 @@ import com.jogamp.opengl.util.stereo.EyeParameter;
import com.jogamp.opengl.util.stereo.StereoDevice;
import com.jogamp.opengl.util.stereo.StereoDeviceFactory;
import com.jogamp.opengl.util.stereo.StereoDeviceRenderer;
+import com.jogamp.opengl.util.stereo.StereoUtil;
import com.jogamp.opengl.util.stereo.generic.GenericStereoDeviceConfig;
import com.jogamp.opengl.util.stereo.generic.GenericStereoDeviceFactory;
@@ -117,6 +118,7 @@ public class GenericStereoDevice implements StereoDevice {
public final Point surfacePos;
private final FovHVHalves[] defaultEyeFov;
+ private int usedSensorBits;
private boolean sensorsStarted = false;
public GenericStereoDevice(final StereoDeviceFactory factory, final int deviceIndex, final StereoDeviceConfig customConfig) {
@@ -137,6 +139,9 @@ public class GenericStereoDevice implements StereoDevice {
for(int i=0; i Success
+ return true;
+ }
+ }
+ protected boolean startSensorsImpl(final boolean start, final int desiredSensorBits, final int requiredSensorBits) {
+ // TODO: Add SPI for sensors
+ // TODO: start sensors in override / or SPI
+ // TODO: set usedSensorBits
+ return false;
+ }
+
+ @Override
+ public final boolean stopSensors() {
+ if( sensorsStarted ) {
+ if( startSensorsImpl(false, 0, 0) ) {
sensorsStarted = false;
+ usedSensorBits = 0;
return true;
} else {
- sensorsStarted = true;
return false;
}
} else {
@@ -206,11 +233,20 @@ public class GenericStereoDevice implements StereoDevice {
return true;
}
}
- private boolean startSensorsImpl(final boolean start) { return start; }
@Override
public boolean getSensorsStarted() { return sensorsStarted; }
+ @Override
+ public final int getSupportedSensorBits() {
+ return config.supportedSensorBits;
+ }
+
+ @Override
+ public final int getEnabledSensorBits() {
+ return usedSensorBits;
+ }
+
@Override
public int[] getEyeRenderOrder() { return config.eyeRenderOrder; }
diff --git a/src/jogl/classes/jogamp/opengl/util/stereo/GenericStereoDeviceRenderer.java b/src/jogl/classes/jogamp/opengl/util/stereo/GenericStereoDeviceRenderer.java
index 6650342e7..21567a0f1 100644
--- a/src/jogl/classes/jogamp/opengl/util/stereo/GenericStereoDeviceRenderer.java
+++ b/src/jogl/classes/jogamp/opengl/util/stereo/GenericStereoDeviceRenderer.java
@@ -49,7 +49,7 @@ import com.jogamp.opengl.util.GLArrayDataServer;
import com.jogamp.opengl.util.glsl.ShaderCode;
import com.jogamp.opengl.util.glsl.ShaderProgram;
import com.jogamp.opengl.util.stereo.EyeParameter;
-import com.jogamp.opengl.util.stereo.EyePose;
+import com.jogamp.opengl.util.stereo.ViewerPose;
import com.jogamp.opengl.util.stereo.StereoDevice;
import com.jogamp.opengl.util.stereo.StereoDeviceRenderer;
import com.jogamp.opengl.util.stereo.StereoUtil;
@@ -82,7 +82,6 @@ public class GenericStereoDeviceRenderer implements StereoDeviceRenderer {
private final EyeParameter eyeParameter;
- private final EyePose eyePose;
@Override
public final RectangleImmutable getViewport() { return viewport; }
@@ -90,12 +89,9 @@ public class GenericStereoDeviceRenderer implements StereoDeviceRenderer {
@Override
public final EyeParameter getEyeParameter() { return eyeParameter; }
- @Override
- public final EyePose getLastEyePose() { return eyePose; }
-
- private GenericEye(final GenericStereoDevice device, final int distortionBits,
- final float[] eyePositionOffset, final EyeParameter eyeParam,
- final DimensionImmutable textureSize, final RectangleImmutable eyeViewport) {
+ /* pp */ GenericEye(final GenericStereoDevice device, final int distortionBits,
+ final float[] eyePositionOffset, final EyeParameter eyeParam,
+ final DimensionImmutable textureSize, final RectangleImmutable eyeViewport) {
this.eyeName = eyeParam.number;
this.distortionBits = distortionBits;
this.viewport = eyeViewport;
@@ -123,10 +119,6 @@ public class GenericStereoDeviceRenderer implements StereoDeviceRenderer {
this.eyeParameter = eyeParam;
- this.eyePose = new EyePose(eyeName);
-
- updateEyePose(device); // 1st init
-
// Setup: eyeToSourceUVScale, eyeToSourceUVOffset
if( usePP ) {
final ScaleAndOffset2D textureScaleAndOffset = new ScaleAndOffset2D(eyeParam.fovhv, textureSize, eyeViewport);
@@ -333,18 +325,18 @@ public class GenericStereoDeviceRenderer implements StereoDeviceRenderer {
indices.enableBuffer(gl, false);
}
- private void dispose(final GL2ES2 gl) {
+ /* pp */ void dispose(final GL2ES2 gl) {
if( null == iVBO ) return;
iVBO.destroy(gl);
indices.destroy(gl);
}
- private void enableVBO(final GL2ES2 gl, final boolean enable) {
+ /* pp */ void enableVBO(final GL2ES2 gl, final boolean enable) {
if( null == iVBO ) return;
iVBO.enableBuffer(gl, enable);
indices.bindBuffer(gl, enable); // keeps VBO binding if enable:=true
}
- private void updateUniform(final GL2ES2 gl, final ShaderProgram sp) {
+ /* pp */ void updateUniform(final GL2ES2 gl, final ShaderProgram sp) {
if( null == iVBO ) return;
gl.glUniform(eyeToSourceUVScale);
gl.glUniform(eyeToSourceUVOffset);
@@ -354,15 +346,6 @@ public class GenericStereoDeviceRenderer implements StereoDeviceRenderer {
}
}
- /**
- * Updates {@link #ovrEyePose} and it's extracted
- * {@link #eyeRenderPoseOrientation} and {@link #eyeRenderPosePosition}.
- * @param hmdCtx used get the {@link #ovrEyePose} via {@link OVR#ovrHmd_GetEyePose(OvrHmdContext, int)}
- */
- private EyePose updateEyePose(final GenericStereoDevice hmdCtx) {
- return eyePose;
- }
-
@Override
public String toString() {
final String ppTxt = null == iVBO ? ", no post-processing" :
@@ -373,12 +356,13 @@ public class GenericStereoDeviceRenderer implements StereoDeviceRenderer {
", "+eyeParameter+
", vertices "+vertexCount+", indices "+indexCount+
ppTxt+
- ", desc"+eyeParameter+", "+eyePose+"]";
+ ", desc "+eyeParameter+"]";
}
}
private final GenericStereoDevice device;
private final GenericEye[] eyes;
+ private final ViewerPose viewerPose;
private final int distortionBits;
private final int textureCount;
private final DimensionImmutable[] eyeTextureSizes;
@@ -445,9 +429,11 @@ public class GenericStereoDeviceRenderer implements StereoDeviceRenderer {
this.totalTextureSize = zeroSize;
texUnit0 = null;
}
+ viewerPose = new ViewerPose();
for(int i=0; i now["+StereoUtil.sensorBitsToString(usedSensorBits)+"]");
+ }
+ }
+ }
+
@Override
- public final boolean startSensors(final boolean start) {
- if( start && !sensorsStarted ) {
+ public final boolean startSensors(final int desiredSensorBits, final int requiredSensorBits) {
+ if( !sensorsStarted ) {
+ if( requiredSensorBits != ( supportedSensorBits & requiredSensorBits ) ) {
+ // required sensors not available
+ if( StereoDevice.DEBUG ) {
+ System.err.println("XXX: startSensors failed: n/a required sensors ["+StereoUtil.sensorBitsToString(requiredSensorBits)+"]");
+ }
+ return false;
+ }
+ if( 0 == ( supportedSensorBits & ( requiredSensorBits | desiredSensorBits ) ) ) {
+ // no sensors available
+ if( StereoDevice.DEBUG ) {
+ System.err.println("XXX: startSensors failed: n/a any sensors");
+ }
+ return false;
+ }
// Start the sensor which provides the Rift’s pose and motion.
- final int requiredTrackingCaps = 0;
- final int supportedTrackingCaps = requiredTrackingCaps |
- OVR.ovrTrackingCap_Orientation |
- OVR.ovrTrackingCap_MagYawCorrection |
- OVR.ovrTrackingCap_Position;
- if( OVR.ovrHmd_ConfigureTracking(hmdDesc, supportedTrackingCaps, requiredTrackingCaps) ) {
+ final int requiredTrackingCaps = OVRUtil.sensorBits2TrackingCaps(requiredSensorBits);
+ final int desiredTrackingCaps = requiredTrackingCaps | OVRUtil.sensorBits2TrackingCaps(desiredSensorBits);
+ final boolean res;
+ if( OVR.ovrHmd_ConfigureTracking(hmdDesc, desiredTrackingCaps, requiredTrackingCaps) ) {
sensorsStarted = true;
- return true;
+ updateUsedSensorBits(OVR.ovrHmd_GetTrackingState(hmdDesc, 0.0));
+ res = true;
} else {
- sensorsStarted = false;
- return false;
+ res = false;
+ }
+ if( StereoDevice.DEBUG ) {
+ System.err.println("XXX: startSensors: "+res+", started "+sensorsStarted+
+ ": required["+StereoUtil.sensorBitsToString(requiredSensorBits)+"]"+
+ ", desired["+StereoUtil.sensorBitsToString(desiredSensorBits)+"]"+
+ ", enabled["+StereoUtil.sensorBitsToString(usedSensorBits)+"]");
}
- } else if( sensorsStarted ) {
+ return res;
+ } else {
+ // No state change -> Success
+ return true;
+ }
+ }
+ @Override
+ public final boolean stopSensors() {
+ if( sensorsStarted ) {
OVR.ovrHmd_ConfigureTracking(hmdDesc, 0, 0); // STOP
sensorsStarted = false;
+ usedSensorBits = 0;
return true;
} else {
// No state change -> Success
@@ -186,6 +241,16 @@ public class OVRStereoDevice implements StereoDevice {
@Override
public final boolean getSensorsStarted() { return sensorsStarted; }
+ @Override
+ public final int getSupportedSensorBits() {
+ return supportedSensorBits;
+ }
+
+ @Override
+ public final int getEnabledSensorBits() {
+ return usedSensorBits;
+ }
+
@Override
public final int[] getEyeRenderOrder() {
return eyeRenderOrder;
diff --git a/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDeviceFactory.java b/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDeviceFactory.java
index f9969a9ad..a0836b5a3 100644
--- a/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDeviceFactory.java
+++ b/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDeviceFactory.java
@@ -40,7 +40,9 @@ public class OVRStereoDeviceFactory extends StereoDeviceFactory {
if( OVR.ovr_Initialize(OVRVersion.defaultInitParams) ) { // recursive ..
boolean res = false;
final int count = OVR.ovrHmd_Detect();
- System.err.println("Detect.0: ovrHmd_Detect() -> "+count);
+ if( StereoDevice.DEBUG ) {
+ System.err.println("Detect.0: ovrHmd_Detect() -> "+count);
+ }
if( 0 < count ) {
res = true;
} else {
@@ -53,6 +55,10 @@ public class OVRStereoDeviceFactory extends StereoDeviceFactory {
System.err.println("Detect.1: hmdDesc: "+hmdDesc.getProductNameAsString());
}
OVR.ovrHmd_Destroy(hmdDesc);
+ } else {
+ if( StereoDevice.DEBUG ) {
+ System.err.println("Detect.1: hmdDesc: null");
+ }
}
}
return res;
diff --git a/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDeviceRenderer.java b/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDeviceRenderer.java
index 60fb8301e..7d05bb7ac 100644
--- a/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDeviceRenderer.java
+++ b/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDeviceRenderer.java
@@ -54,6 +54,7 @@ import com.jogamp.oculusvr.ovrMatrix4f;
import com.jogamp.oculusvr.ovrPosef;
import com.jogamp.oculusvr.ovrRecti;
import com.jogamp.oculusvr.ovrSizei;
+import com.jogamp.oculusvr.ovrTrackingState;
import com.jogamp.oculusvr.ovrVector2f;
import com.jogamp.oculusvr.ovrVector3f;
import com.jogamp.opengl.JoglVersion;
@@ -62,7 +63,7 @@ import com.jogamp.opengl.util.GLArrayDataServer;
import com.jogamp.opengl.util.glsl.ShaderCode;
import com.jogamp.opengl.util.glsl.ShaderProgram;
import com.jogamp.opengl.util.stereo.EyeParameter;
-import com.jogamp.opengl.util.stereo.EyePose;
+import com.jogamp.opengl.util.stereo.ViewerPose;
import com.jogamp.opengl.util.stereo.StereoDevice;
import com.jogamp.opengl.util.stereo.StereoDeviceRenderer;
import com.jogamp.opengl.util.stereo.StereoUtil;
@@ -93,12 +94,11 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer {
private final GLArrayData vboPos, vboParams, vboTexCoordsR, vboTexCoordsG, vboTexCoordsB;
private final GLArrayDataServer indices;
- private final ovrEyeRenderDesc ovrEyeDesc;
+ /* pp */ final ovrEyeRenderDesc ovrEyeDesc;
private final ovrFovPort ovrEyeFov;
private final EyeParameter eyeParameter;
- private ovrPosef ovrEyePose;
- private final EyePose eyePose;
+ private final ovrMatrix4f[] timeWarpMatrices;
@Override
public final RectangleImmutable getViewport() { return viewport; }
@@ -106,12 +106,9 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer {
@Override
public final EyeParameter getEyeParameter() { return eyeParameter; }
- @Override
- public final EyePose getLastEyePose() { return eyePose; }
-
- private OVREye(final ovrHmdDesc hmdDesc, final int distortionBits,
- final float[] eyePositionOffset, final ovrEyeRenderDesc eyeDesc,
- final ovrSizei ovrTextureSize, final RectangleImmutable eyeViewport) {
+ /* pp */ OVREye(final ovrHmdDesc hmdDesc, final int distortionBits,
+ final float[] eyePositionOffset, final ovrEyeRenderDesc eyeDesc,
+ final ovrSizei ovrTextureSize, final RectangleImmutable eyeViewport) {
this.eyeName = eyeDesc.getEye();
this.distortionBits = distortionBits;
this.viewport = eyeViewport;
@@ -125,9 +122,13 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer {
if( usesTimewarp ) {
eyeRotationStart = new GLUniformData("ovr_EyeRotationStart", 4, 4, Buffers.slice2Float(fstash, 4, 16));
eyeRotationEnd = new GLUniformData("ovr_EyeRotationEnd", 4, 4, Buffers.slice2Float(fstash, 20, 16));
+ timeWarpMatrices = new ovrMatrix4f[2];
+ timeWarpMatrices[0] = ovrMatrix4f.create();
+ timeWarpMatrices[1] = ovrMatrix4f.create();
} else {
eyeRotationStart = null;
eyeRotationEnd = null;
+ timeWarpMatrices = null;
}
this.ovrEyeDesc = eyeDesc;
@@ -137,14 +138,10 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer {
this.eyeParameter = new EyeParameter(eyeName, eyePositionOffset, OVRUtil.getFovHV(ovrEyeFov),
eyeViewAdjust.getX(), eyeViewAdjust.getY(), eyeViewAdjust.getZ());
- this.eyePose = new EyePose(eyeName);
-
- updateEyePose(hmdDesc); // 1st init
-
// Setup: eyeToSourceUVScale, eyeToSourceUVOffset
{
final ovrVector2f[] uvScaleOffsetOut = new ovrVector2f[2];
- uvScaleOffsetOut[0] = ovrVector2f.create(); // FIXME: remove ctor / double check
+ uvScaleOffsetOut[0] = ovrVector2f.create();
uvScaleOffsetOut[1] = ovrVector2f.create();
final ovrRecti ovrEyeRenderViewport = OVRUtil.createOVRRecti(eyeViewport);
@@ -194,7 +191,7 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer {
/** 2+2+2+2+2: { vec2 position, vec2 color, vec2 texCoordR, vec2 texCoordG, vec2 texCoordB } */
final FloatBuffer iVBOFB = (FloatBuffer)iVBO.getBuffer();
final ovrDistortionVertex[] ovRes = new ovrDistortionVertex[1];
- ovRes[0] = ovrDistortionVertex.create(); // FIXME: remove ctor / double check
+ ovRes[0] = ovrDistortionVertex.create();
for ( int vertNum = 0; vertNum < vertexCount; vertNum++ ) {
final ovrDistortionVertex ov = meshData.getPVertexData(vertNum, ovRes)[0];
@@ -275,7 +272,7 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer {
OVR.ovrHmd_DestroyDistortionMesh(meshData);
}
- private void linkData(final GL2ES2 gl, final ShaderProgram sp) {
+ /* pp */ void linkData(final GL2ES2 gl, final ShaderProgram sp) {
if( 0 > vboPos.setLocation(gl, sp.program()) ) {
throw new GLException("Couldn't locate "+vboPos);
}
@@ -313,16 +310,16 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer {
indices.enableBuffer(gl, false);
}
- private void dispose(final GL2ES2 gl) {
+ /* pp */ void dispose(final GL2ES2 gl) {
iVBO.destroy(gl);
indices.destroy(gl);
}
- private void enableVBO(final GL2ES2 gl, final boolean enable) {
+ /* pp */ void enableVBO(final GL2ES2 gl, final boolean enable) {
iVBO.enableBuffer(gl, enable);
indices.bindBuffer(gl, enable); // keeps VBO binding if enable:=true
}
- private void updateUniform(final GL2ES2 gl, final ShaderProgram sp) {
+ /* pp */ void updateUniform(final GL2ES2 gl, final ShaderProgram sp) {
gl.glUniform(eyeToSourceUVScale);
gl.glUniform(eyeToSourceUVOffset);
if( StereoUtil.usesTimewarpDistortion(distortionBits) ) {
@@ -331,10 +328,7 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer {
}
}
- private void updateTimewarp(final ovrHmdDesc hmdDesc, final ovrPosef eyeRenderPose, final float[] mat4Tmp1, final float[] mat4Tmp2) {
- final ovrMatrix4f[] timeWarpMatrices = new ovrMatrix4f[2];
- timeWarpMatrices[0] = ovrMatrix4f.create(); // FIXME: remove ctor / double check
- timeWarpMatrices[1] = ovrMatrix4f.create();
+ /* pp */ void updateTimewarp(final ovrHmdDesc hmdDesc, final ovrPosef eyeRenderPose, final float[] mat4Tmp1, final float[] mat4Tmp2) {
OVR.ovrHmd_GetEyeTimewarpMatrices(hmdDesc, eyeName, eyeRenderPose, timeWarpMatrices);
final float[] eyeRotationStartM = FloatUtil.transposeMatrix(timeWarpMatrices[0].getM(0, mat4Tmp1), mat4Tmp2);
@@ -348,19 +342,6 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer {
eyeRotationEndU.rewind();
}
- /**
- * Updates {@link #ovrEyePose} and it's extracted
- * {@link #eyeRenderPoseOrientation} and {@link #eyeRenderPosePosition}.
- * @param hmdCtx used get the {@link #ovrEyePose} via {@link OVR#ovrHmd_GetHmdPosePerEye(ovrHmdDesc, int)}
- */
- private EyePose updateEyePose(final ovrHmdDesc hmdDesc) {
- ovrEyePose = OVR.ovrHmd_GetHmdPosePerEye(hmdDesc, eyeName);
- final ovrVector3f pos = ovrEyePose.getPosition();
- eyePose.setPosition(pos.getX(), pos.getY(), pos.getZ());
- OVRUtil.copyToQuaternion(ovrEyePose.getOrientation(), eyePose.orientation);
- return eyePose;
- }
-
@Override
public String toString() {
return "Eye["+eyeName+", viewport "+viewport+
@@ -368,12 +349,16 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer {
", vertices "+vertexCount+", indices "+indexCount+
", uvScale["+eyeToSourceUVScale.floatBufferValue().get(0)+", "+eyeToSourceUVScale.floatBufferValue().get(1)+
"], uvOffset["+eyeToSourceUVOffset.floatBufferValue().get(0)+", "+eyeToSourceUVOffset.floatBufferValue().get(1)+
- "], desc"+OVRUtil.toString(ovrEyeDesc)+", "+eyePose+"]";
+ "], desc"+OVRUtil.toString(ovrEyeDesc)+"]";
}
}
private final OVRStereoDevice context;
private final OVREye[] eyes;
+ private final ovrPosef[] ovrEyePoses;
+ private final ovrVector3f[] hmdToEyeViewOffset;
+ private final ViewerPose eyePoses;
+ private final ovrTrackingState trackingState;
private final int distortionBits;
private final int textureCount;
private final DimensionImmutable[] eyeTextureSizes;
@@ -439,6 +424,16 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer {
}
eyes[0] = new OVREye(context.hmdDesc, this.distortionBits, eyePositionOffset, eyeRenderDescs[0], ovrTexture0Size, eyeViewports[0]);
eyes[1] = new OVREye(context.hmdDesc, this.distortionBits, eyePositionOffset, eyeRenderDescs[1], ovrTexture1Size, eyeViewports[1]);
+
+ ovrEyePoses = new ovrPosef[2];
+ ovrEyePoses[0] = ovrPosef.create();
+ ovrEyePoses[1] = ovrPosef.create();
+ hmdToEyeViewOffset = new ovrVector3f[2];
+ hmdToEyeViewOffset[0] = eyes[0].ovrEyeDesc.getHmdToEyeViewOffset();
+ hmdToEyeViewOffset[1] = eyes[1].ovrEyeDesc.getHmdToEyeViewOffset();
+ eyePoses = new ViewerPose();
+ trackingState = ovrTrackingState.create();
+
sp = null;
frameTiming = null;
frameCount = 0;
@@ -546,13 +541,29 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer {
}
@Override
- public final EyePose updateEyePose(final int eyeNum) {
- return eyes[eyeNum].updateEyePose(context.hmdDesc);
+ public final ViewerPose updateViewerPose() {
+ final ovrTrackingState trackingState;
+ trackingState = this.trackingState;
+ OVR.ovrHmd_GetEyePoses(context.hmdDesc, frameCount, hmdToEyeViewOffset, ovrEyePoses, trackingState);
+ context.updateUsedSensorBits(trackingState);
+
+ // Use headPose of tracking state, since it points to the viewer
+ // where ovrEyePoses already have hmdToEyeViewOffset applied (IPD .. etc).
+ final ovrPosef pose = trackingState.getHeadPose().getThePose();
+ final ovrVector3f pos = pose.getPosition();
+ eyePoses.setPosition(pos.getX(), pos.getY(), pos.getZ());
+ OVRUtil.copyToQuaternion(pose.getOrientation(), eyePoses.orientation);
+ return eyePoses;
+ }
+
+ @Override
+ public final ViewerPose getLastViewerPose() {
+ return eyePoses;
}
@Override
public final void beginFrame(final GL gl) {
- frameTiming = OVR.ovrHmd_BeginFrameTiming(context.hmdDesc, 0); // ovrHmd_GetFrameTiming not used, otherwise: frameCount);
+ frameTiming = OVR.ovrHmd_BeginFrameTiming(context.hmdDesc, frameCount); // ovrHmd_GetFrameTiming not used, otherwise: frameCount);
}
@Override
@@ -574,7 +585,9 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer {
throw new IllegalStateException("beginFrame not called");
}
if( StereoUtil.usesTimewarpDistortion(distortionBits) ) {
+ // minimize latency
OVR.ovr_WaitTillTime(frameTiming.getTimewarpPointSeconds());
+ // {@link OVREye#updateTimewarp(ovrHmdDesc, ovrPosef, float[], float[])} will be called in {@link #ppOneEye}
}
final GL2ES2 gl2es2 = gl.getGL2ES2();
@@ -599,7 +612,7 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer {
public final void ppOneEye(final GL gl, final int eyeNum) {
final OVREye eye = eyes[eyeNum];
if( StereoUtil.usesTimewarpDistortion(distortionBits) ) {
- eye.updateTimewarp(context.hmdDesc, eye.ovrEyePose, mat4Tmp1, mat4Tmp2);
+ eye.updateTimewarp(context.hmdDesc, ovrEyePoses[eyeNum], mat4Tmp1, mat4Tmp2);
}
final GL2ES2 gl2es2 = gl.getGL2ES2();
diff --git a/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRUtil.java b/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRUtil.java
index c1d01fea2..e54bd61e8 100644
--- a/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRUtil.java
+++ b/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRUtil.java
@@ -44,6 +44,7 @@ import com.jogamp.oculusvr.ovrVector2i;
import com.jogamp.oculusvr.ovrVector3f;
import com.jogamp.opengl.math.FovHVHalves;
import com.jogamp.opengl.math.Quaternion;
+import com.jogamp.opengl.util.stereo.StereoDevice;
import com.jogamp.opengl.util.stereo.StereoDeviceRenderer;
/**
@@ -146,6 +147,42 @@ public class OVRUtil {
return bits;
}
+ public static int ovrTrackingCaps2SensorBits(final int ovrTrackingCaps) {
+ int bits = 0;
+ if( 0 != ( OVR.ovrTrackingCap_Orientation & ovrTrackingCaps ) ) {
+ bits |= StereoDevice.SENSOR_ORIENTATION;
+ }
+ if( 0 != ( OVR.ovrTrackingCap_MagYawCorrection & ovrTrackingCaps ) ) {
+ bits |= StereoDevice.SENSOR_YAW_CORRECTION;
+ }
+ if( 0 != ( OVR.ovrTrackingCap_Position & ovrTrackingCaps ) ) {
+ bits |= StereoDevice.SENSOR_POSITION;
+ }
+ return bits;
+ }
+ public static int ovrTrackingStats2SensorBits(final int ovrTrackingCaps) {
+ int bits = 0;
+ if( 0 != ( OVR.ovrStatus_OrientationTracked & ovrTrackingCaps ) ) {
+ bits |= StereoDevice.SENSOR_ORIENTATION;
+ }
+ if( 0 != ( OVR.ovrStatus_PositionTracked & ovrTrackingCaps ) ) {
+ bits |= StereoDevice.SENSOR_POSITION;
+ }
+ return bits;
+ }
+ public static int sensorBits2TrackingCaps(final int sensorBits) {
+ int caps = 0;
+ if( 0 != ( StereoDevice.SENSOR_ORIENTATION & sensorBits ) ) {
+ caps |= OVR.ovrTrackingCap_Orientation;
+ }
+ if( 0 != ( StereoDevice.SENSOR_YAW_CORRECTION & sensorBits ) ) {
+ caps |= OVR.ovrTrackingCap_MagYawCorrection;
+ }
+ if( 0 != ( StereoDevice.SENSOR_POSITION & sensorBits ) ) {
+ caps |= OVR.ovrTrackingCap_Position;
+ }
+ return caps;
+ }
public static String toString(final ovrFovPort fov) {
return "["+fov.getLeftTan()+" l, "+fov.getRightTan()+" r, "+
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestVersionSemanticsNOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestVersionSemanticsNOUI.java
index 395f6661d..7b8fa077a 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestVersionSemanticsNOUI.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestVersionSemanticsNOUI.java
@@ -56,12 +56,12 @@ public class TestVersionSemanticsNOUI extends SingletonJunitCase {
static final VersionNumberString curVersionNumber = new VersionNumberString(curVersion.getImplementationVersion());
static final Set excludesDefault;
- static final Set excludesV230V23X;
+ static final Set excludesStereoPackage;
static {
excludesDefault = new HashSet();
excludesDefault.add("^\\Qjogamp/\\E.*$");
- excludesV230V23X = new HashSet(excludesDefault);
- excludesV230V23X.add("^\\Qcom/jogamp/opengl/util/stereo/\\E.*$");
+ excludesStereoPackage = new HashSet(excludesDefault);
+ excludesStereoPackage.add("^\\Qcom/jogamp/opengl/util/stereo/\\E.*$");
}
@@ -138,7 +138,7 @@ public class TestVersionSemanticsNOUI extends SingletonJunitCase {
VersionSemanticsUtil.testVersion(diffCriteria, expectedCompatibilityType,
previousJar, preVersionNumber,
curVersion.getClass(), currentCL, curVersionNumber,
- excludesV230V23X);
+ excludesStereoPackage);
}
public static void main(final String args[]) throws IOException {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
index e95c2a9da..9b414d7c5 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
@@ -43,7 +43,7 @@ import com.jogamp.opengl.util.glsl.ShaderCode;
import com.jogamp.opengl.util.glsl.ShaderProgram;
import com.jogamp.opengl.util.glsl.ShaderState;
import com.jogamp.opengl.util.stereo.EyeParameter;
-import com.jogamp.opengl.util.stereo.EyePose;
+import com.jogamp.opengl.util.stereo.ViewerPose;
import com.jogamp.opengl.util.stereo.StereoGLEventListener;
import java.nio.FloatBuffer;
@@ -407,9 +407,11 @@ public class GearsES2 implements StereoGLEventListener, TileRendererBase.TileRen
private final float[] vec3Tmp2 = new float[3];
private final float[] vec3Tmp3 = new float[3];
+ private static final float[] vec3ScalePos = new float[] { 20f, 20f, 20f };
+
@Override
public void reshapeForEye(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height,
- final EyeParameter eyeParam, final EyePose eyePose) {
+ final EyeParameter eyeParam, final ViewerPose viewerPose) {
final GL2ES2 gl = drawable.getGL().getGL2ES2();
pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
final float[] mat4Projection = FloatUtil.makePerspective(mat4Tmp1, 0, true, eyeParam.fovhv, zNear, zFar);
@@ -426,10 +428,11 @@ public class GearsES2 implements StereoGLEventListener, TileRendererBase.TileRen
final Quaternion rollPitchYaw = new Quaternion();
// private final float eyeYaw = FloatUtil.PI; // 180 degrees in radians
// rollPitchYaw.rotateByAngleY(eyeYaw);
- final float[] shiftedEyePos = rollPitchYaw.rotateVector(vec3Tmp1, 0, eyePose.position, 0);
+ final float[] shiftedEyePos = rollPitchYaw.rotateVector(vec3Tmp1, 0, viewerPose.position, 0);
+ VectorUtil.scaleVec3(shiftedEyePos, shiftedEyePos, vec3ScalePos); // amplify viewerPose position
VectorUtil.addVec3(shiftedEyePos, shiftedEyePos, eyeParam.positionOffset);
- rollPitchYaw.mult(eyePose.orientation);
+ rollPitchYaw.mult(viewerPose.orientation);
final float[] up = rollPitchYaw.rotateVector(vec3Tmp2, 0, VectorUtil.VEC3_UNIT_Y, 0);
final float[] forward = rollPitchYaw.rotateVector(vec3Tmp3, 0, VectorUtil.VEC3_UNIT_Z_NEG, 0);
final float[] center = VectorUtil.addVec3(forward, shiftedEyePos, forward);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSBSStereo.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSBSStereo.java
index 57aa76c82..e936bf991 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSBSStereo.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSBSStereo.java
@@ -46,6 +46,7 @@ import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.font.Font;
+import com.jogamp.junit.util.JunitTracer;
import com.jogamp.newt.Window;
import com.jogamp.newt.event.KeyAdapter;
import com.jogamp.newt.event.KeyEvent;
@@ -71,7 +72,7 @@ import com.jogamp.opengl.util.glsl.ShaderCode;
import com.jogamp.opengl.util.glsl.ShaderProgram;
import com.jogamp.opengl.util.glsl.ShaderState;
import com.jogamp.opengl.util.stereo.EyeParameter;
-import com.jogamp.opengl.util.stereo.EyePose;
+import com.jogamp.opengl.util.stereo.ViewerPose;
import com.jogamp.opengl.util.stereo.StereoClientRenderer;
import com.jogamp.opengl.util.stereo.StereoGLEventListener;
import com.jogamp.opengl.util.texture.Texture;
@@ -415,7 +416,7 @@ public class MovieSBSStereo implements StereoGLEventListener {
", "+drawable.getClass().getName()+", "+drawable);
if(waitForKey) {
- UITestCase.waitForKey("Init>");
+ JunitTracer.waitForKey("Init>");
}
final Texture tex;
try {
@@ -639,9 +640,11 @@ public class MovieSBSStereo implements StereoGLEventListener {
GLArrayDataServer interleavedVBOCurrent = null;
+ private static final float[] vec3ScalePos = new float[] { 4f, 4f, 4f };
+
@Override
public void reshapeForEye(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height,
- final EyeParameter eyeParam, final EyePose eyePose) {
+ final EyeParameter eyeParam, final ViewerPose viewerPose) {
final GL2ES2 gl = drawable.getGL().getGL2ES2();
interleavedVBOCurrent = 0 == eyeParam.number ? interleavedVBOLeft : interleavedVBORight;
@@ -657,10 +660,11 @@ public class MovieSBSStereo implements StereoGLEventListener {
pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
final Quaternion rollPitchYaw = new Quaternion();
- final float[] shiftedEyePos = rollPitchYaw.rotateVector(vec3Tmp1, 0, eyePose.position, 0);
+ final float[] shiftedEyePos = rollPitchYaw.rotateVector(vec3Tmp1, 0, viewerPose.position, 0);
+ VectorUtil.scaleVec3(shiftedEyePos, shiftedEyePos, vec3ScalePos); // amplify viewerPose position
VectorUtil.addVec3(shiftedEyePos, shiftedEyePos, eyeParam.positionOffset);
- rollPitchYaw.mult(eyePose.orientation);
+ rollPitchYaw.mult(viewerPose.orientation);
final float[] up = rollPitchYaw.rotateVector(vec3Tmp2, 0, VectorUtil.VEC3_UNIT_Y, 0);
final float[] forward = rollPitchYaw.rotateVector(vec3Tmp3, 0, VectorUtil.VEC3_UNIT_Z_NEG, 0);
final float[] center = VectorUtil.addVec3(forward, shiftedEyePos, forward);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/stereo/StereoDemo01.java b/src/test/com/jogamp/opengl/test/junit/jogl/stereo/StereoDemo01.java
index 693f2f72b..c2e808770 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/stereo/StereoDemo01.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/stereo/StereoDemo01.java
@@ -245,7 +245,7 @@ public class StereoDemo01 {
System.err.println("StereoDevice "+stereoDevice);
// Start the sensor which provides the Rift’s pose and motion.
- if( !stereoDevice.startSensors(true) ) {
+ if( !stereoDevice.startSensors(stereoDevice.getSupportedSensorBits(), 0) ) {
System.err.println("Could not start sensors on device "+deviceIndex);
}
@@ -335,7 +335,11 @@ public class StereoDemo01 {
}
switch(e.getKeySymbol()) {
case KeyEvent.VK_R: {
- stereoDevice.startSensors(!stereoDevice.getSensorsStarted());
+ if( stereoDevice.getSensorsStarted() ) {
+ stereoDevice.stopSensors();
+ } else {
+ stereoDevice.startSensors(stereoDevice.getSupportedSensorBits(), 0);
+ }
break;
}
}
--
cgit v1.2.3