-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathluaCBJoystick.cpp
More file actions
70 lines (59 loc) · 1.6 KB
/
luaCBJoystick.cpp
File metadata and controls
70 lines (59 loc) · 1.6 KB
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
// Author: Greg "fugue" Santucci, 2011
// Email: thecodewitch@gmail.com
// Web: http://createuniverses.blogspot.com/
#include "luaCB.h"
int luaCBGetJoyAxis(lua_State * L)
{
#ifdef __PRAXIS_WINDOWS__
JOYINFOEX joyInfo;
//joyInfo.dwSize = 3000;
joyInfo.dwSize = sizeof(JOYINFOEX);
joyInfo.dwFlags = JOY_RETURNALL;
MMRESULT joyresult = joyGetPosEx(JOYSTICKID1, &joyInfo);
if(joyresult == JOYERR_NOERROR)
{
float fScale = 1.0f / 32.768f;
lua_pushnumber(L, (float)((int)joyInfo.dwXpos - 32768) * fScale);
lua_pushnumber(L, (float)((int)joyInfo.dwYpos - 32768) * fScale);
lua_pushnumber(L, (float)((int)joyInfo.dwRpos - 32768) * fScale);
}
else
{
lua_pushnumber(L, 0);
lua_pushnumber(L, 0);
lua_pushnumber(L, 0);
}
#else
lua_pushnumber(L, 0);
lua_pushnumber(L, 0);
lua_pushnumber(L, 0);
#endif
return 3;
}
int luaCBGetJoyThrottle(lua_State * L)
{
#ifdef __PRAXIS_WINDOWS__
JOYINFOEX joyInfo;
//joyInfo.dwSize = 3000;
joyInfo.dwSize = sizeof(JOYINFOEX);
joyInfo.dwFlags = JOY_RETURNALL;
MMRESULT joyresult = joyGetPosEx(JOYSTICKID1, &joyInfo);
if(joyresult == JOYERR_NOERROR)
{
float fScale = 1.0f / 32.768f;
lua_pushnumber(L, (float)(joyInfo.dwZpos - 32768) * fScale);
}
else
{
lua_pushnumber(L, 0);
}
#else
lua_pushnumber(L, 0);
#endif
return 1;
}
void luaInitCallbacksJoystick()
{
lua_register(g_pLuaState, "getJoyAxis", luaCBGetJoyAxis);
lua_register(g_pLuaState, "getJoyThrottle", luaCBGetJoyThrottle);
}