| 1 | /* $Id: glut_joy.c,v 1.2 2000-02-09 08:46:13 jeroen Exp $ */
|
|---|
| 2 | /* Copyright (c) Mark J. Kilgard, 1997, 1998. */
|
|---|
| 3 |
|
|---|
| 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. */
|
|---|
| 7 |
|
|---|
| 8 | #ifdef _WIN32
|
|---|
| 9 | #include <windows.h>
|
|---|
| 10 | #include <mmsystem.h> /* Win32 Multimedia API header. */
|
|---|
| 11 | #endif
|
|---|
| 12 |
|
|---|
| 13 | #include "glutint.h"
|
|---|
| 14 |
|
|---|
| 15 | /* CENTRY */
|
|---|
| 16 | void APIENTRY
|
|---|
| 17 | glutJoystickFunc(GLUTjoystickCB joystickFunc, int pollInterval)
|
|---|
| 18 | {
|
|---|
| 19 | #ifdef _WIN32
|
|---|
| 20 | if (joystickFunc && (pollInterval > 0)) {
|
|---|
| 21 | if (__glutCurrentWindow->entryState == WM_SETFOCUS) {
|
|---|
| 22 | MMRESULT result;
|
|---|
| 23 |
|
|---|
| 24 | /* Capture joystick focus if current window has
|
|---|
| 25 | focus now. */
|
|---|
| 26 | result = joySetCapture(__glutCurrentWindow->win,
|
|---|
| 27 | JOYSTICKID1, 0, TRUE);
|
|---|
| 28 | if (result == JOYERR_NOERROR) {
|
|---|
| 29 | (void) joySetThreshold(JOYSTICKID1, pollInterval);
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 | __glutCurrentWindow->joyPollInterval = pollInterval;
|
|---|
| 33 | } else {
|
|---|
| 34 | /* Release joystick focus if current window has
|
|---|
| 35 | focus now. */
|
|---|
| 36 | if (__glutCurrentWindow->joystick
|
|---|
| 37 | && (__glutCurrentWindow->joyPollInterval > 0)
|
|---|
| 38 | && (__glutCurrentWindow->entryState == WM_SETFOCUS)) {
|
|---|
| 39 | (void) joyReleaseCapture(JOYSTICKID1);
|
|---|
| 40 | }
|
|---|
| 41 | __glutCurrentWindow->joyPollInterval = 0;
|
|---|
| 42 | }
|
|---|
| 43 | __glutCurrentWindow->joystick = joystickFunc;
|
|---|
| 44 | #else
|
|---|
| 45 | /* XXX No support currently for X11 joysticks. */
|
|---|
| 46 | #endif
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | void APIENTRY
|
|---|
| 50 | glutForceJoystickFunc(void)
|
|---|
| 51 | {
|
|---|
| 52 | #ifdef _WIN32
|
|---|
| 53 | if (__glutCurrentWindow->joystick) {
|
|---|
| 54 | JOYINFOEX jix;
|
|---|
| 55 | MMRESULT res;
|
|---|
| 56 | int x, y, z;
|
|---|
| 57 |
|
|---|
| 58 | /* Poll the joystick. */
|
|---|
| 59 | jix.dwSize = sizeof(jix);
|
|---|
| 60 | jix.dwFlags = JOY_RETURNALL;
|
|---|
| 61 | res = joyGetPosEx(JOYSTICKID1,&jix);
|
|---|
| 62 | if (res == JOYERR_NOERROR) {
|
|---|
| 63 |
|
|---|
| 64 | /* Convert to int for scaling. */
|
|---|
| 65 | x = jix.dwXpos;
|
|---|
| 66 | y = jix.dwYpos;
|
|---|
| 67 | z = jix.dwZpos;
|
|---|
| 68 |
|
|---|
| 69 | #define SCALE(v) ((int) ((v - 32767)/32.768))
|
|---|
| 70 |
|
|---|
| 71 | __glutCurrentWindow->joystick(jix.dwButtons,
|
|---|
| 72 | SCALE(x), SCALE(y), SCALE(z));
|
|---|
| 73 | }
|
|---|
| 74 | }
|
|---|
| 75 | #else
|
|---|
| 76 | /* XXX No support currently for X11 joysticks. */
|
|---|
| 77 | #endif
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | /* ENDCENTRY */
|
|---|