mirror of
https://github.com/ctruLua/ctruLua.git
synced 2025-10-27 16:39:29 +00:00
Finished the QTM library, Added some text in ctr.c
The QTM (Headtracking) is not tested on real hardware, and doesn't work in citra. But should work, maybe. Please update your boot.3dsx to use it without errors.
This commit is contained in:
parent
3f48e6e66e
commit
848fe42096
2 changed files with 75 additions and 7 deletions
80
source/qtm.c
80
source/qtm.c
|
|
@ -5,10 +5,20 @@
|
|||
#include <lapi.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
static int qtm_init(lua_State *L) {
|
||||
qtmInit();
|
||||
typedef struct {
|
||||
qtmHeadtrackingInfo *info;
|
||||
} qtm_userdata;
|
||||
|
||||
return 0;
|
||||
static int qtm_init(lua_State *L) {
|
||||
Result ret = qtmInit();
|
||||
if (ret) {
|
||||
lua_pushboolean(L, false);
|
||||
lua_pushinteger(L, ret);
|
||||
return 2;
|
||||
}
|
||||
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int qtm_shutdown(lua_State *L) {
|
||||
|
|
@ -25,18 +35,69 @@ static int qtm_checkInitialized(lua_State *L) {
|
|||
}
|
||||
|
||||
static int qtm_getHeadtrackingInfo(lua_State *L) {
|
||||
return 0;
|
||||
qtm_userdata *data = lua_newuserdata(L, sizeof(*data));
|
||||
luaL_getmetatable(L, "LQTM");
|
||||
lua_setmetatable(L, -2);
|
||||
Result ret = qtmGetHeadtrackingInfo(0, data->info);
|
||||
if (ret) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int qtm_checkHeadFullyDetected(lua_State *L) {
|
||||
return 0;
|
||||
qtm_userdata *info = luaL_checkudata(L, 1, "LQTM");
|
||||
lua_pushboolean(L, qtmCheckHeadFullyDetected(info->info));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int qtm___index(lua_State *L) {
|
||||
qtm_userdata *info = luaL_checkudata(L, 1, "LQTM");
|
||||
lua_Integer index = luaL_checkinteger(L, 2);
|
||||
index = index - 1; // Lua index begins at 1
|
||||
if (index > 3 || index < 0) {
|
||||
lua_pushnil(L);
|
||||
lua_pushnil(L);
|
||||
return 2;
|
||||
}
|
||||
|
||||
lua_pushnumber(L, info->info->coords0[index].x);
|
||||
lua_pushnumber(L, info->info->coords0[index].y);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int qtm_convertCoordToScreen(lua_State *L) {
|
||||
return 0;
|
||||
qtm_userdata *info = luaL_checkudata(L, 1, "LQTM");
|
||||
lua_Integer index = luaL_checkinteger(L, 2);
|
||||
index = index - 1; // Lua index begins at 1
|
||||
if (index > 3 || index < 0) {
|
||||
lua_pushnil(L);
|
||||
lua_pushnil(L);
|
||||
return 2;
|
||||
}
|
||||
float screenWidth = luaL_optnumber(L, 3, 400.0f);
|
||||
float screenHeight = luaL_optnumber(L, 4, 320.0f);
|
||||
|
||||
u32 x, y = 0;
|
||||
qtmConvertCoordToScreen(&info->info->coords0[index], &screenWidth, &screenHeight, &x, &y);
|
||||
|
||||
lua_pushinteger(L, x);
|
||||
lua_pushinteger(L, y);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
// module
|
||||
// object
|
||||
static const struct luaL_Reg qtm_methods[] = {
|
||||
{"checkHeadFullyDetected", qtm_checkHeadFullyDetected},
|
||||
{"convertCoordToScreen", qtm_convertCoordToScreen },
|
||||
{"__index", qtm___index },
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
// module functions
|
||||
static const struct luaL_Reg qtm_functions[] = {
|
||||
{"init", qtm_init },
|
||||
{"shutdown", qtm_shutdown },
|
||||
|
|
@ -48,6 +109,11 @@ static const struct luaL_Reg qtm_functions[] = {
|
|||
};
|
||||
|
||||
int luaopen_qtm_lib(lua_State *L) {
|
||||
luaL_newmetatable(L, "LQTM");
|
||||
lua_pushvalue(L, -1);
|
||||
lua_setfield(L, -2, "__index");
|
||||
luaL_setfuncs(L, qtm_methods, 0);
|
||||
|
||||
luaL_newlib(L, qtm_functions);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue