-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenHMD-Java.c
277 lines (214 loc) · 5.76 KB
/
OpenHMD-Java.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#include "OpenHMD-Java.h"
#include "openhmd.h"
#include <jni.h>
jlong Java_OpenHMD_ohmd_1ctx_1create
(JNIEnv *env, jclass cls)
{
//Create the context and pass pointer as long to Java
ohmd_context* ctx = ohmd_ctx_create();
return (long)ctx;
}
void Java_OpenHMD_ohmd_1ctx_1destroy
(JNIEnv *env, jclass cls, jlong context)
{
//Destroy the context
ohmd_context* ctx = (ohmd_context*)context;
ohmd_ctx_destroy(ctx);
}
jstring Java_OpenHMD_ohmd_1ctx_1get_1error
(JNIEnv *env, jclass cls, jlong context)
{
//Call get_error and return the error code
ohmd_context* ctx = (ohmd_context*)context;
const char* cerror = ohmd_ctx_get_error(ctx);
jstring error;
error = (*env)->NewStringUTF(env,cerror);
return error;
}
void Java_OpenHMD_ohmd_1ctx_1update
(JNIEnv *env, jclass cls, jlong context)
{
ohmd_context* ctx = (ohmd_context*)context;
ohmd_ctx_update(ctx);
}
jint Java_OpenHMD_ohmd_1ctx_1probe
(JNIEnv *env, jclass cls, jlong context)
{
ohmd_context* ctx = (ohmd_context*)context;
return ohmd_ctx_probe(ctx);
}
jstring Java_OpenHMD_ohmd_1list_1gets
(JNIEnv *env, jclass cls, jlong context, jint index, jint type)
{
ohmd_context* ctx = (ohmd_context*)context;
const char* creturn = ohmd_list_gets(ctx, index, type);
jstring jreturn;
jreturn = (*env)->NewStringUTF(env,creturn);
return jreturn;
}
jlong Java_OpenHMD_ohmd_1list_1open_1device
(JNIEnv *env, jclass cls, jlong context, jint index)
{
ohmd_context* ctx = (ohmd_context*)context;
ohmd_device* dev = ohmd_list_open_device(ctx, index);
//returns pointer to device as long
return (long)dev;
}
jint Java_OpenHMD_ohmd_1close_1device
(JNIEnv *env, jclass cls, jlong context)
{
ohmd_device* dev = (ohmd_device*)context;
//return int is error code
return ohmd_close_device(dev);
}
jfloatArray Java_OpenHMD_ohmd_1device_1getf
(JNIEnv *env, jclass cls, jlong device, jint type)
{
ohmd_device* dev = (ohmd_device*)device;
switch(type){
case OHMD_LEFT_EYE_GL_MODELVIEW_MATRIX:
{
float cout[16];
jfloatArray jout = (*env)->NewFloatArray(env, 16);
ohmd_device_getf(dev, type, cout);
(*env)->SetFloatArrayRegion(env, jout, 0, 16, cout);
return jout;
}
case OHMD_RIGHT_EYE_GL_MODELVIEW_MATRIX:
{
float cout[16];
jfloatArray jout = (*env)->NewFloatArray(env, 16);
ohmd_device_getf(dev, type, cout);
(*env)->SetFloatArrayRegion(env, jout, 0, 16, cout);
return jout;
}
case OHMD_LEFT_EYE_GL_PROJECTION_MATRIX:
{
float cout[16];
jfloatArray jout = (*env)->NewFloatArray(env, 16);
ohmd_device_getf(dev, type, cout);
(*env)->SetFloatArrayRegion(env, jout, 0, 16, cout);
return jout;
}
case OHMD_RIGHT_EYE_GL_PROJECTION_MATRIX:
{
float cout[16];
jfloatArray jout = (*env)->NewFloatArray(env, 16);
ohmd_device_getf(dev, type, cout);
(*env)->SetFloatArrayRegion(env, jout, 0, 16, cout);
return jout;
}
case OHMD_SCREEN_HORIZONTAL_SIZE:
{
float cout[1];
jfloatArray jout = (*env)->NewFloatArray(env, 1);
ohmd_device_getf(dev, type, cout);
(*env)->SetFloatArrayRegion(env, jout, 0, 1, cout);
return jout;
}
case OHMD_SCREEN_VERTICAL_SIZE:
{
float cout[1];
jfloatArray jout = (*env)->NewFloatArray(env, 1);
ohmd_device_getf(dev, type, cout);
(*env)->SetFloatArrayRegion(env, jout, 0, 1, cout);
return jout;
}
case OHMD_LENS_HORIZONTAL_SEPARATION:
{
float cout[1];
jfloatArray jout = (*env)->NewFloatArray(env, 1);
ohmd_device_getf(dev, type, cout);
(*env)->SetFloatArrayRegion(env, jout, 0, 1, cout);
return jout;
}
case OHMD_LENS_VERTICAL_POSITION:
{
float cout[1];
jfloatArray jout = (*env)->NewFloatArray(env, 1);
ohmd_device_getf(dev, type, cout);
(*env)->SetFloatArrayRegion(env, jout, 0, 1, cout);
return jout;
}
case OHMD_RIGHT_EYE_FOV:
case OHMD_LEFT_EYE_FOV:
{
float cout[1];
jfloatArray jout = (*env)->NewFloatArray(env, 1);
ohmd_device_getf(dev, type, cout);
(*env)->SetFloatArrayRegion(env, jout, 0, 1, cout);
return jout;
}
case OHMD_RIGHT_EYE_ASPECT_RATIO:
case OHMD_LEFT_EYE_ASPECT_RATIO:
{
float cout[1];
jfloatArray jout = (*env)->NewFloatArray(env, 1);
ohmd_device_getf(dev, type, cout);
(*env)->SetFloatArrayRegion(env, jout, 0, 1, cout);
return jout;
}
case OHMD_EYE_IPD:
{
float cout[1];
jfloatArray jout = (*env)->NewFloatArray(env, 1);
ohmd_device_getf(dev, type, cout);
(*env)->SetFloatArrayRegion(env, jout, 0, 1, cout);
return jout;
}
case OHMD_PROJECTION_ZFAR:
{
float cout[1];
jfloatArray jout = (*env)->NewFloatArray(env, 1);
ohmd_device_getf(dev, type, cout);
(*env)->SetFloatArrayRegion(env, jout, 0, 1, cout);
return jout;
}
case OHMD_PROJECTION_ZNEAR:
{
float cout[1];
jfloatArray jout = (*env)->NewFloatArray(env, 1);
ohmd_device_getf(dev, type, cout);
(*env)->SetFloatArrayRegion(env, jout, 0, 1, cout);
return jout;
}
case OHMD_ROTATION_QUAT:
{
float cout[4];
jfloatArray jout = (*env)->NewFloatArray(env, 4);
ohmd_device_getf(dev, type, cout);
(*env)->SetFloatArrayRegion(env, jout, 0, 4, cout);
return jout;
}
case OHMD_POSITION_VECTOR:
{
float cout[3];
jfloatArray jout = (*env)->NewFloatArray(env, 3);
ohmd_device_getf(dev, type, cout);
(*env)->SetFloatArrayRegion(env, jout, 0, 4, cout);
return jout;
}
default:
return 0;
//return dev->getf(dev, type, out);
}
return 0; //something horrible has gone wrong
}
jint Java_OpenHMD_ohmd_1device_1setf
(JNIEnv *env, jclass cls, jlong context, jint type, jfloatArray in)
{
ohmd_context* ctx = (ohmd_context*)context;
//return int is error code
//return ohmd_device_setf(device, type, in);
}
jintArray Java_OpenHMD_ohmd_1device_1geti
(JNIEnv *env, jclass cls, jlong device, jint type)
{
/*
ohmd_context* ctx = (ohmd_context*)context;
int* cout;
jintArray jout;
ohmd_device_geti(device, type, cout);
jout = (*env)->GetIntArrayElements(env, cout, 0);
return jout;*/
}