2016-08-11 04:17:14 +00:00
|
|
|
#include "headset.h"
|
|
|
|
#include "../headset/headset.h"
|
|
|
|
|
|
|
|
void renderHelper(int eyeIndex, void* userdata) {
|
|
|
|
lua_State* L = (lua_State*)userdata;
|
2016-08-17 03:35:15 +00:00
|
|
|
luaL_checktype(L, 1, LUA_TFUNCTION);
|
|
|
|
lua_pushvalue(L, 1);
|
|
|
|
lua_pushinteger(L, eyeIndex);
|
2016-08-11 04:17:14 +00:00
|
|
|
lua_call(L, 1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
const luaL_Reg lovrHeadset[] = {
|
2016-09-27 06:48:09 +00:00
|
|
|
{ "getAngularVelocity", l_lovrHeadsetGetAngularVelocity },
|
|
|
|
{ "getClipDistance", l_lovrHeadsetGetClipDistance },
|
2016-09-17 02:43:43 +00:00
|
|
|
{ "getOrientation", l_lovrHeadsetGetPosition },
|
2016-09-27 06:48:09 +00:00
|
|
|
{ "getPosition", l_lovrHeadsetGetPosition },
|
2016-09-17 02:43:43 +00:00
|
|
|
{ "getVelocity", l_lovrHeadsetGetVelocity },
|
|
|
|
{ "isPresent", l_lovrHeadsetIsPresent },
|
2016-08-11 04:17:14 +00:00
|
|
|
{ "renderTo", l_lovrHeadsetRenderTo },
|
2016-09-27 06:48:09 +00:00
|
|
|
{ "setClipDistance", l_lovrHeadsetSetClipDistance },
|
2016-08-11 04:17:14 +00:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
int l_lovrHeadsetInit(lua_State* L) {
|
|
|
|
lua_newtable(L);
|
|
|
|
luaL_register(L, NULL, lovrHeadset);
|
|
|
|
lovrHeadsetInit();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-09-17 21:25:08 +00:00
|
|
|
int l_lovrHeadsetGetAngularVelocity(lua_State* L) {
|
2016-09-17 02:43:43 +00:00
|
|
|
float x, y, z;
|
2016-09-17 21:25:08 +00:00
|
|
|
lovrHeadsetGetAngularVelocity(&x, &y, &z);
|
2016-09-17 02:43:43 +00:00
|
|
|
lua_pushnumber(L, x);
|
|
|
|
lua_pushnumber(L, y);
|
|
|
|
lua_pushnumber(L, z);
|
|
|
|
return 3;
|
2016-08-11 04:17:14 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 06:48:09 +00:00
|
|
|
int l_lovrHeadsetGetClipDistance(lua_State* L) {
|
|
|
|
float near, far;
|
|
|
|
lovrHeadsetGetClipDistance(&near, &far);
|
|
|
|
lua_pushnumber(L, near);
|
|
|
|
lua_pushnumber(L, far);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2016-09-17 02:43:43 +00:00
|
|
|
int l_lovrHeadsetGetOrientation(lua_State* L) {
|
|
|
|
float x, y, z, w;
|
|
|
|
lovrHeadsetGetOrientation(&x, &y, &z, &w);
|
|
|
|
lua_pushnumber(L, x);
|
|
|
|
lua_pushnumber(L, y);
|
|
|
|
lua_pushnumber(L, z);
|
|
|
|
lua_pushnumber(L, w);
|
|
|
|
return 4;
|
2016-08-11 04:17:14 +00:00
|
|
|
}
|
|
|
|
|
2016-09-17 21:25:08 +00:00
|
|
|
int l_lovrHeadsetGetPosition(lua_State* L) {
|
2016-09-17 02:43:43 +00:00
|
|
|
float x, y, z;
|
2016-09-17 21:25:08 +00:00
|
|
|
lovrHeadsetGetPosition(&x, &y, &z);
|
2016-09-17 02:43:43 +00:00
|
|
|
lua_pushnumber(L, x);
|
|
|
|
lua_pushnumber(L, y);
|
|
|
|
lua_pushnumber(L, z);
|
|
|
|
return 3;
|
2016-08-11 04:17:14 +00:00
|
|
|
}
|
|
|
|
|
2016-09-17 21:25:08 +00:00
|
|
|
int l_lovrHeadsetGetVelocity(lua_State* L) {
|
2016-09-17 02:43:43 +00:00
|
|
|
float x, y, z;
|
2016-09-17 21:25:08 +00:00
|
|
|
lovrHeadsetGetVelocity(&x, &y, &z);
|
2016-09-17 02:43:43 +00:00
|
|
|
lua_pushnumber(L, x);
|
|
|
|
lua_pushnumber(L, y);
|
|
|
|
lua_pushnumber(L, z);
|
|
|
|
return 3;
|
2016-09-16 06:57:01 +00:00
|
|
|
}
|
|
|
|
|
2016-09-17 02:43:43 +00:00
|
|
|
int l_lovrHeadsetIsPresent(lua_State* L) {
|
|
|
|
lua_pushboolean(L, lovrHeadsetIsPresent());
|
2016-09-16 06:57:01 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-08-11 04:17:14 +00:00
|
|
|
int l_lovrHeadsetRenderTo(lua_State* L) {
|
|
|
|
luaL_checktype(L, 1, LUA_TFUNCTION);
|
|
|
|
lovrHeadsetRenderTo(renderHelper, L);
|
|
|
|
return 0;
|
|
|
|
}
|
2016-09-27 06:48:09 +00:00
|
|
|
|
|
|
|
int l_lovrHeadsetSetClipDistance(lua_State* L) {
|
|
|
|
float near = luaL_checknumber(L, 1);
|
|
|
|
float far = luaL_checknumber(L, 2);
|
|
|
|
lovrHeadsetSetClipDistance(near, far);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|