From 53966f92042d44483cb44f6c6b3c95a6a1fdd325 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
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/StereoUtil.java  | 41 ++++++++++++++++++----
 1 file changed, 34 insertions(+), 7 deletions(-)

(limited to 'src/jogl/classes/com/jogamp/opengl/util/stereo/StereoUtil.java')

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 <i>Side By Side</i>, SBS, projection- and modelview matrix for one eye.
      * <p>
-     * {@link #updateEyePose(int)} must be called upfront.
+     * {@link #updateViewerPose(int)} must be called upfront.
      * </p>
      * <p>
      * 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}.
      * </p>
-     * @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);
-- 
cgit v1.2.3