lovr/src/lovr/headset.c

173 lines
4.7 KiB
C
Raw Normal View History

2016-08-11 04:17:14 +00:00
#include "headset.h"
#include "types/controller.h"
2016-08-11 04:17:14 +00:00
#include "../headset/headset.h"
2016-10-03 18:15:46 +00:00
#include "../util.h"
2016-08-11 04:17:14 +00:00
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_pushstring(L, eyeIndex == 0 ? "left" : "right");
2016-08-11 04:17:14 +00:00
lua_call(L, 1, 0);
}
const luaL_Reg lovrHeadset[] = {
2016-10-01 21:12:55 +00:00
{ "isPresent", l_lovrHeadsetIsPresent },
{ "getType", l_lovrHeadsetGetType },
2016-10-24 23:03:29 +00:00
{ "getDisplayWidth", l_lovrHeadsetGetDisplayWidth },
{ "getDisplayHeight", l_lovrHeadsetGetDisplayHeight },
{ "getDisplayDimensions", l_lovrHeadsetGetDisplayDimensions },
2016-09-27 06:48:09 +00:00
{ "getClipDistance", l_lovrHeadsetGetClipDistance },
2016-10-01 21:12:55 +00:00
{ "setClipDistance", l_lovrHeadsetSetClipDistance },
2016-10-01 21:17:26 +00:00
{ "getTrackingSize", l_lovrHeadsetGetTrackingSize },
2016-11-12 09:23:22 +00:00
{ "isBoundsVisible", l_lovrHeadsetIsBoundsVisible },
{ "setBoundsVisible", l_lovrHeadsetSetBoundsVisible },
2016-09-27 06:48:09 +00:00
{ "getPosition", l_lovrHeadsetGetPosition },
2016-10-04 00:02:01 +00:00
{ "getOrientation", l_lovrHeadsetGetOrientation },
2016-09-17 02:43:43 +00:00
{ "getVelocity", l_lovrHeadsetGetVelocity },
2016-10-01 21:12:55 +00:00
{ "getAngularVelocity", l_lovrHeadsetGetAngularVelocity },
2016-10-03 14:40:20 +00:00
{ "getController", l_lovrHeadsetGetController },
2016-08-11 04:17:14 +00:00
{ "renderTo", l_lovrHeadsetRenderTo },
{ NULL, NULL }
};
int l_lovrHeadsetInit(lua_State* L) {
lua_newtable(L);
luaL_register(L, NULL, lovrHeadset);
2016-10-03 18:11:30 +00:00
luaRegisterType(L, "Controller", lovrController, NULL);
2016-10-03 14:40:20 +00:00
map_init(&ControllerHands);
map_set(&ControllerHands, "left", CONTROLLER_HAND_LEFT);
map_set(&ControllerHands, "right", CONTROLLER_HAND_RIGHT);
2016-11-15 00:20:56 +00:00
map_init(&ControllerAxes);
map_set(&ControllerAxes, "trigger", CONTROLLER_AXIS_TRIGGER);
map_set(&ControllerAxes, "touchx", CONTROLLER_AXIS_TOUCHPAD_X);
map_set(&ControllerAxes, "touchy", CONTROLLER_AXIS_TOUCHPAD_Y);
2016-11-15 03:57:23 +00:00
map_init(&ControllerButtons);
map_set(&ControllerButtons, "system", CONTROLLER_BUTTON_SYSTEM);
map_set(&ControllerButtons, "menu", CONTROLLER_BUTTON_MENU);
map_set(&ControllerButtons, "grip", CONTROLLER_BUTTON_GRIP);
map_set(&ControllerButtons, "touchpad", CONTROLLER_BUTTON_TOUCHPAD);
2016-08-11 04:17:14 +00:00
lovrHeadsetInit();
2016-10-03 14:40:20 +00:00
2016-08-11 04:17:14 +00:00
return 1;
}
2016-10-01 21:12:55 +00:00
int l_lovrHeadsetIsPresent(lua_State* L) {
lua_pushboolean(L, lovrHeadsetIsPresent());
return 1;
}
int l_lovrHeadsetGetType(lua_State* L) {
lua_pushstring(L, lovrHeadsetGetType());
return 1;
2016-08-11 04:17:14 +00:00
}
2016-10-24 23:03:29 +00:00
int l_lovrHeadsetGetDisplayWidth(lua_State* L) {
int width;
lovrHeadsetGetDisplayDimensions(&width, NULL);
lua_pushnumber(L, width);
return 1;
}
int l_lovrHeadsetGetDisplayHeight(lua_State* L) {
int height;
lovrHeadsetGetDisplayDimensions(NULL, &height);
lua_pushnumber(L, height);
return 1;
}
int l_lovrHeadsetGetDisplayDimensions(lua_State* L) {
int width, height;
lovrHeadsetGetDisplayDimensions(&width, &height);
lua_pushnumber(L, width);
lua_pushnumber(L, height);
return 2;
}
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-10-01 21:12:55 +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;
}
2016-10-01 21:17:26 +00:00
int l_lovrHeadsetGetTrackingSize(lua_State* L) {
float width, depth;
lovrHeadsetGetClipDistance(&width, &depth);
lua_pushnumber(L, width);
lua_pushnumber(L, depth);
return 2;
}
2016-10-01 22:11:45 +00:00
int l_lovrHeadsetIsBoundsVisible(lua_State* L) {
lua_pushboolean(L, lovrHeadsetIsBoundsVisible());
return 1;
}
int l_lovrHeadsetSetBoundsVisible(lua_State* L) {
char visible = lua_toboolean(L, 1);
lovrHeadsetSetBoundsVisible(visible);
return 0;
}
2016-10-01 21:12:55 +00:00
int l_lovrHeadsetGetPosition(lua_State* L) {
float x, y, z;
lovrHeadsetGetPosition(&x, &y, &z);
lua_pushnumber(L, x);
lua_pushnumber(L, y);
lua_pushnumber(L, z);
return 3;
}
2016-09-17 02:43:43 +00:00
int l_lovrHeadsetGetOrientation(lua_State* L) {
2016-10-04 00:02:01 +00:00
float w, x, y, z;
lovrHeadsetGetOrientation(&w, &x, &y, &z);
lua_pushnumber(L, w);
2016-09-17 02:43:43 +00:00
lua_pushnumber(L, x);
lua_pushnumber(L, y);
lua_pushnumber(L, z);
return 4;
2016-08-11 04:17:14 +00:00
}
2016-10-01 21:12:55 +00:00
int l_lovrHeadsetGetVelocity(lua_State* L) {
2016-09-17 02:43:43 +00:00
float x, y, z;
2016-10-01 21:12:55 +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-08-11 04:17:14 +00:00
}
2016-10-01 21:12:55 +00:00
int l_lovrHeadsetGetAngularVelocity(lua_State* L) {
2016-09-17 02:43:43 +00:00
float x, y, z;
2016-10-01 21:12:55 +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-09-16 06:57:01 +00:00
}
2016-10-03 14:40:20 +00:00
int l_lovrHeadsetGetController(lua_State* L) {
2016-11-08 22:15:37 +00:00
ControllerHand* hand = (ControllerHand*) luax_checkenum(L, 1, &ControllerHands, "controller hand");
2016-10-03 14:40:20 +00:00
luax_pushcontroller(L, lovrHeadsetGetController(*hand));
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;
}