X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fmswin%2Ffg_spaceball_mswin.c;h=9dc55fb5d416c19b879a0634dc2854e9c1b1e311;hb=b1ed93dd348f7b8f3bd2c75474f5d4151d502f1f;hp=0dfa3e932837dc37649a0ed9900f292df26e6fd6;hpb=226cd5ccd0f86cc1f2741e686fcf8e4846acf867;p=freeglut diff --git a/src/mswin/fg_spaceball_mswin.c b/src/mswin/fg_spaceball_mswin.c index 0dfa3e9..9dc55fb 100644 --- a/src/mswin/fg_spaceball_mswin.c +++ b/src/mswin/fg_spaceball_mswin.c @@ -2,7 +2,7 @@ * fg_spaceball_mswin.c * * Spaceball support for Windows - * + * * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved. * Written by Evan Felix * Creation date: Sat Feb 4, 2012 @@ -32,7 +32,7 @@ /* * Modified by Jinrong Xie 12/24/2014 * for Space Navigator support on Windows. - * This code is enhanced by at least supporting 3Dconnexion's + * This code is enhanced by at least supporting 3Dconnexion's * six degree of freedom navigator. */ @@ -43,7 +43,7 @@ #include "../fg_internal.h" enum { - SPNAV_EVENT_ANY, + SPNAV_EVENT_ANY, SPNAV_EVENT_MOTION_TRANSLATION, SPNAV_EVENT_MOTION_ROTATION, SPNAV_EVENT_BUTTON /* includes both press and release */ @@ -55,145 +55,145 @@ RAWINPUTDEVICE __fgSpaceball = { 0x01, 0x08, 0x00, 0x00 }; void fgPlatformInitializeSpaceball(void) { - HWND hwnd; - sball_initialized = 1; - if (!fgStructure.CurrentWindow) - { - sball_initialized = 0; - return; - } - hwnd = fgStructure.CurrentWindow->Window.Handle; - - { - BOOL ok; - UINT cbSize = sizeof(__fgSpaceball); - __fgSpaceball.hwndTarget = hwnd; - ok = RegisterRawInputDevices(&__fgSpaceball, 1, cbSize); - - if (!ok){ - __fgSpaceball.hwndTarget = NULL; - sball_initialized = 0; - } - } + HWND hwnd; + sball_initialized = 1; + if (!fgStructure.CurrentWindow) + { + sball_initialized = 0; + return; + } + hwnd = fgStructure.CurrentWindow->Window.Handle; + + { + BOOL ok; + UINT cbSize = sizeof(__fgSpaceball); + __fgSpaceball.hwndTarget = hwnd; + ok = RegisterRawInputDevices(&__fgSpaceball, 1, cbSize); + + if (!ok){ + __fgSpaceball.hwndTarget = NULL; + sball_initialized = 0; + } + } } void fgPlatformSpaceballClose(void) { - return; + return; } int fgPlatformHasSpaceball(void) { - return __fgSpaceball.hwndTarget ? 1 : 0; + return __fgSpaceball.hwndTarget ? 1 : 0; } int fgPlatformSpaceballNumButtons(void) { - return 0; + return 0; } void fgPlatformSpaceballSetWindow(SFG_Window *window) { - return; + return; } int fgIsSpaceballWinEvent(HWND hwnd, WPARAM wParam, LPARAM lParam) { - return 0; + return 0; } void fgSpaceballHandleWinEvent(HWND hwnd, WPARAM wParam, LPARAM lParam) { - #define LOGITECH_VENDOR_ID 0x46d - HRAWINPUT hRawInput = (HRAWINPUT)lParam; - UINT inputCode = (UINT)wParam; - UINT size; - BYTE *rawInputBuffer; - PRAWINPUT pRawInput; - UINT res; - RID_DEVICE_INFO sRidDeviceInfo; - - if (!sball_initialized) - { - fgPlatformInitializeSpaceball(); - if (!sball_initialized) - { - return; - } - } - - res = GetRawInputData(hRawInput, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER)); - if (res == -1) - return; - - rawInputBuffer = malloc(size * sizeof *rawInputBuffer); - pRawInput = (PRAWINPUT)rawInputBuffer; - - res = GetRawInputData(hRawInput, RID_INPUT, pRawInput, &size, sizeof(RAWINPUTHEADER)); - if (res == -1) - return; - if (pRawInput->header.dwType != RIM_TYPEHID) - return; - - sRidDeviceInfo.cbSize = sizeof(RID_DEVICE_INFO); - size = sizeof(RID_DEVICE_INFO); - res = GetRawInputDeviceInfo(pRawInput->header.hDevice, RIDI_DEVICEINFO, &sRidDeviceInfo, &size); - if (res == -1) - return; - { - SFG_Window* window = fgWindowByHandle(hwnd); - if ((window == NULL)) - return; - - if (sRidDeviceInfo.hid.dwVendorId == LOGITECH_VENDOR_ID) - { - // Motion data comes in two parts: motion type and - // displacement/rotation along three axis. - // Orientation is a right handed coordinate system with - // X goes right, Y goes up and Z goes towards viewer, e.g. - // the one used in OpenGL - if (pRawInput->data.hid.bRawData[0] == - SPNAV_EVENT_MOTION_TRANSLATION) - { // Translation vector - short* pnData = (short*)(&pRawInput->data.hid.bRawData[1]); - short X = pnData[0]; - short Y = -pnData[2]; - short Z = pnData[1]; - INVOKE_WCB(*window, SpaceMotion, (X, Y, Z)); - } - else if (pRawInput->data.hid.bRawData[0] == - SPNAV_EVENT_MOTION_ROTATION) - { // Axis aligned rotation vector - short* pnData = (short*)(&pRawInput->data.hid.bRawData[1]); - short rX = pnData[0]; - short rY = -pnData[2]; - short rZ = pnData[1]; - INVOKE_WCB(*window, SpaceRotation, (rX, rY, rZ)); - } - else if (pRawInput->data.hid.bRawData[0] == - SPNAV_EVENT_BUTTON) - { // State of the keys - unsigned long dwKeystate = *(unsigned long*)(&pRawInput->data.hid.bRawData[1]); - unsigned int state = GLUT_UP; - if (FETCH_WCB(*window, SpaceButton)) - { - int i; - for (i = 0; i < 32; i++) - { - unsigned long stateBefore = __fgSpaceKeystate&(1 << i); - unsigned long stateNow = dwKeystate&(1 << i); - - if (stateBefore && !stateNow) - INVOKE_WCB(*window, SpaceButton, (stateBefore, GLUT_UP)); - if (!stateBefore && stateNow) - INVOKE_WCB(*window, SpaceButton, (stateNow, GLUT_DOWN)); - - } - } - __fgSpaceKeystate = dwKeystate; - } - } - } + #define LOGITECH_VENDOR_ID 0x46d + HRAWINPUT hRawInput = (HRAWINPUT)lParam; + UINT inputCode = (UINT)wParam; + UINT size; + BYTE *rawInputBuffer; + PRAWINPUT pRawInput; + UINT res; + RID_DEVICE_INFO sRidDeviceInfo; + + if (!sball_initialized) + { + fgPlatformInitializeSpaceball(); + if (!sball_initialized) + { + return; + } + } + + res = GetRawInputData(hRawInput, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER)); + if (res == -1) + return; + + rawInputBuffer = malloc(size * sizeof *rawInputBuffer); + pRawInput = (PRAWINPUT)rawInputBuffer; + + res = GetRawInputData(hRawInput, RID_INPUT, pRawInput, &size, sizeof(RAWINPUTHEADER)); + if (res == -1) + return; + if (pRawInput->header.dwType != RIM_TYPEHID) + return; + + sRidDeviceInfo.cbSize = sizeof(RID_DEVICE_INFO); + size = sizeof(RID_DEVICE_INFO); + res = GetRawInputDeviceInfo(pRawInput->header.hDevice, RIDI_DEVICEINFO, &sRidDeviceInfo, &size); + if (res == -1) + return; + { + SFG_Window* window = fgWindowByHandle(hwnd); + if ((window == NULL)) + return; + + if (sRidDeviceInfo.hid.dwVendorId == LOGITECH_VENDOR_ID) + { + // Motion data comes in two parts: motion type and + // displacement/rotation along three axis. + // Orientation is a right handed coordinate system with + // X goes right, Y goes up and Z goes towards viewer, e.g. + // the one used in OpenGL + if (pRawInput->data.hid.bRawData[0] == + SPNAV_EVENT_MOTION_TRANSLATION) + { // Translation vector + short* pnData = (short*)(&pRawInput->data.hid.bRawData[1]); + short X = pnData[0]; + short Y = -pnData[2]; + short Z = pnData[1]; + INVOKE_WCB(*window, SpaceMotion, (X, Y, Z)); + } + else if (pRawInput->data.hid.bRawData[0] == + SPNAV_EVENT_MOTION_ROTATION) + { // Axis aligned rotation vector + short* pnData = (short*)(&pRawInput->data.hid.bRawData[1]); + short rX = pnData[0]; + short rY = -pnData[2]; + short rZ = pnData[1]; + INVOKE_WCB(*window, SpaceRotation, (rX, rY, rZ)); + } + else if (pRawInput->data.hid.bRawData[0] == + SPNAV_EVENT_BUTTON) + { // State of the keys + unsigned long dwKeystate = *(unsigned long*)(&pRawInput->data.hid.bRawData[1]); + unsigned int state = GLUT_UP; + if (FETCH_WCB(*window, SpaceButton)) + { + int i; + for (i = 0; i < 32; i++) + { + unsigned long stateBefore = __fgSpaceKeystate&(1 << i); + unsigned long stateNow = dwKeystate&(1 << i); + + if (stateBefore && !stateNow) + INVOKE_WCB(*window, SpaceButton, (stateBefore, GLUT_UP)); + if (!stateBefore && stateNow) + INVOKE_WCB(*window, SpaceButton, (stateNow, GLUT_DOWN)); + + } + } + __fgSpaceKeystate = dwKeystate; + } + } + } } #endif \ No newline at end of file