android: add the Google cardboard support module
[nit.git] / lib / android / cardboard.nit
1 # This file is part of NIT (http://www.nitlanguage.org).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Services from the Google Cardboard SDK for virtual reality on Android
16 #
17 # Projects using this module should keep the `cardboard.jar` archive in the
18 # `libs` folder at the root of the project.
19 #
20 # External resources:
21 # * Download `cardboard.jar` from
22 # https://raw.githubusercontent.com/googlesamples/cardboard-java/master/CardboardSample/libs/cardboard.jar
23 # * Read about Cardboard at
24 # https://developers.google.com/cardboard/
25 # * Find the Cardboard SDK documentation at
26 # https://developers.google.com/cardboard/android/latest/reference/com/google/vrtoolkit/cardboard/package-summary
27 module cardboard
28
29 import java::collections
30 import native_app_glue
31
32 in "Java" `{
33 import com.google.vrtoolkit.cardboard.CardboardActivity;
34 import com.google.vrtoolkit.cardboard.sensors.HeadTracker;
35 `}
36
37 # Provides head tracking information from the device IMU
38 #
39 # The corresponding Java class is no longer documented, but it is still useful.
40 extern class NativeHeadTracker in "Java" `{ com.google.vrtoolkit.cardboard.sensors.HeadTracker `}
41 super JavaObject
42
43 # Instantiate a new `NativeHeadTracker` for the given `context`
44 new (context: NativeContext) in "Java" `{
45 return HeadTracker.createFromContext(context);
46 `}
47
48 # Start tracking head movement
49 fun start_tracking in "Java" `{ recv.startTracking(); `}
50
51 # Stop tracking head movement
52 fun stop_tracking in "Java" `{ recv.stopTracking(); `}
53
54 # Apply correction to the gyroscope values
55 fun gyro_bias=(matrix: JavaFloatArray) in "Java" `{
56 recv.setGyroBias(matrix);
57 `}
58
59 # Enable finer analysis using the neck as center of movement
60 fun neck_model_enabled=(value: Bool) in "Java" `{
61 recv.setNeckModelEnabled(value);
62 `}
63
64 # Fill `matrix` with the last rotation matrix calculated from head movements
65 #
66 # Require: matrix.length >= offset + 16
67 fun last_head_view(matrix: JavaFloatArray, offset: Int) in "Java" `{
68 recv.getLastHeadView(matrix, (int)offset);
69 `}
70 end