android: add the Google cardboard support module
authorAlexis Laferrière <alexis.laf@xymus.net>
Sun, 4 Jan 2015 08:00:14 +0000 (03:00 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 5 Jan 2015 18:34:30 +0000 (13:34 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/android/cardboard.nit [new file with mode: 0644]

diff --git a/lib/android/cardboard.nit b/lib/android/cardboard.nit
new file mode 100644 (file)
index 0000000..30ec5eb
--- /dev/null
@@ -0,0 +1,70 @@
+# This file is part of NIT (http://www.nitlanguage.org).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Services from the Google Cardboard SDK for virtual reality on Android
+#
+# Projects using this module should keep the `cardboard.jar` archive in the
+# `libs` folder at the root of the project.
+#
+# External resources:
+# * Download `cardboard.jar` from
+# https://raw.githubusercontent.com/googlesamples/cardboard-java/master/CardboardSample/libs/cardboard.jar
+# * Read about Cardboard at
+# https://developers.google.com/cardboard/
+# * Find the Cardboard SDK documentation at
+# https://developers.google.com/cardboard/android/latest/reference/com/google/vrtoolkit/cardboard/package-summary
+module cardboard
+
+import java::collections
+import native_app_glue
+
+in "Java" `{
+       import com.google.vrtoolkit.cardboard.CardboardActivity;
+       import com.google.vrtoolkit.cardboard.sensors.HeadTracker;
+`}
+
+# Provides head tracking information from the device IMU
+#
+# The corresponding Java class is no longer documented, but it is still useful.
+extern class NativeHeadTracker in "Java" `{ com.google.vrtoolkit.cardboard.sensors.HeadTracker `}
+       super JavaObject
+
+       # Instantiate a new `NativeHeadTracker` for the given `context`
+       new (context: NativeContext) in "Java" `{
+               return HeadTracker.createFromContext(context);
+       `}
+
+       # Start tracking head movement
+       fun start_tracking in "Java" `{ recv.startTracking(); `}
+
+       # Stop tracking head movement
+       fun stop_tracking in "Java" `{ recv.stopTracking(); `}
+
+       # Apply correction to the gyroscope values
+       fun gyro_bias=(matrix: JavaFloatArray) in "Java" `{
+               recv.setGyroBias(matrix);
+       `}
+
+       # Enable finer analysis using the neck as center of movement
+       fun neck_model_enabled=(value: Bool) in "Java" `{
+               recv.setNeckModelEnabled(value);
+       `}
+
+       # Fill `matrix` with the last rotation matrix calculated from head movements
+       #
+       # Require: matrix.length >= offset + 16
+       fun last_head_view(matrix: JavaFloatArray, offset: Int) in "Java" `{
+               recv.getLastHeadView(matrix, (int)offset);
+       `}
+end