2 /* Copyright (c) Mark J. Kilgard, 1997, 1998. */
4 /* This program is freely distributable without licensing fees
5 and is provided without guarantee or warrantee expressed or
6 implied. This program is -not- in the public domain. */
11 #include <mmsystem.h> /* Win32 Multimedia API header. */
19 glutJoystickFunc(GLUTjoystickCB joystickFunc
, int pollInterval
)
22 if (joystickFunc
&& (pollInterval
> 0)) {
23 if (__glutCurrentWindow
->entryState
== WM_SETFOCUS
) {
26 /* Capture joystick focus if current window has
28 result
= joySetCapture(__glutCurrentWindow
->win
,
29 JOYSTICKID1
, 0, TRUE
);
30 if (result
== JOYERR_NOERROR
) {
31 (void) joySetThreshold(JOYSTICKID1
, pollInterval
);
34 __glutCurrentWindow
->joyPollInterval
= pollInterval
;
36 /* Release joystick focus if current window has
38 if (__glutCurrentWindow
->joystick
39 && (__glutCurrentWindow
->joyPollInterval
> 0)
40 && (__glutCurrentWindow
->entryState
== WM_SETFOCUS
)) {
41 (void) joyReleaseCapture(JOYSTICKID1
);
43 __glutCurrentWindow
->joyPollInterval
= 0;
45 __glutCurrentWindow
->joystick
= joystickFunc
;
47 /* XXX No support currently for X11 joysticks. */
52 glutForceJoystickFunc(void)
55 if (__glutCurrentWindow
->joystick
) {
60 /* Poll the joystick. */
61 jix
.dwSize
= sizeof(jix
);
62 jix
.dwFlags
= JOY_RETURNALL
;
63 res
= joyGetPosEx(JOYSTICKID1
,&jix
);
64 if (res
== JOYERR_NOERROR
) {
66 /* Convert to int for scaling. */
71 #define SCALE(v) ((int) ((v - 32767)/32.768))
73 __glutCurrentWindow
->joystick(jix
.dwButtons
,
74 SCALE(x
), SCALE(y
), SCALE(z
));
78 /* XXX No support currently for X11 joysticks. */