X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmswin%2Ffg_spaceball_mswin.c;h=00e42f6bd36c93fb4123182d14c28c6ce454b1f4;hb=cd0898cee3e8d093c4edbafd87aa66661cdbce46;hp=4d96c31a0b4265fe025a5d2bba38afa6db1ca837;hpb=cae6701c343e3a42bc9504f14e6d83e4ca9d8119;p=freeglut diff --git a/src/mswin/fg_spaceball_mswin.c b/src/mswin/fg_spaceball_mswin.c index 4d96c31..00e42f6 100644 --- a/src/mswin/fg_spaceball_mswin.c +++ b/src/mswin/fg_spaceball_mswin.c @@ -10,7 +10,7 @@ * Copyright (c) 2014 Jinrong Xie. All Rights Reserved. * Written by Jinrong Xie * Modification date: Wed Dec 24, 2014 - + * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation @@ -30,11 +30,16 @@ */ /* + * Modified by Jinrong Xie 12/24/2014 + * for Space Navigator support on Windows. * This code is enhanced by at least supporting 3Dconnexion's * six degree of freedom navigator. */ +#if(_WIN32_WINNT >= 0x0501) + #include +#include #include "../fg_internal.h" enum { @@ -51,7 +56,7 @@ RAWINPUTDEVICE __fgSpaceball = { 0x01, 0x08, 0x00, 0x00 }; void fgPlatformInitializeSpaceball(void) { HWND hwnd; - sball_initialized = 1; + sball_initialized = 1; if (!fgStructure.CurrentWindow) { sball_initialized = 0; @@ -59,17 +64,17 @@ void fgPlatformInitializeSpaceball(void) } 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; + { + BOOL ok; + UINT cbSize = sizeof(__fgSpaceball); + __fgSpaceball.hwndTarget = hwnd; + ok = RegisterRawInputDevices(&__fgSpaceball, 1, cbSize); + + if (!ok){ + __fgSpaceball.hwndTarget = NULL; + sball_initialized = 0; + } } - - return; } void fgPlatformSpaceballClose(void) @@ -94,6 +99,7 @@ void fgPlatformSpaceballSetWindow(SFG_Window *window) int fgIsSpaceballWinEvent(HWND hwnd, WPARAM wParam, LPARAM lParam) { + return 0; } void fgSpaceballHandleWinEvent(HWND hwnd, WPARAM wParam, LPARAM lParam) @@ -101,7 +107,6 @@ void fgSpaceballHandleWinEvent(HWND hwnd, WPARAM wParam, LPARAM lParam) #define LOGITECH_VENDOR_ID 0x46d HRAWINPUT hRawInput = (HRAWINPUT)lParam; UINT inputCode = (UINT)wParam; - RAWINPUTHEADER hdr; UINT size; BYTE *rawInputBuffer; PRAWINPUT pRawInput; @@ -121,7 +126,7 @@ void fgSpaceballHandleWinEvent(HWND hwnd, WPARAM wParam, LPARAM lParam) if (res == -1) return; - rawInputBuffer = (BYTE*)malloc(size); + rawInputBuffer = malloc(size * sizeof *rawInputBuffer); pRawInput = (PRAWINPUT)rawInputBuffer; res = GetRawInputData(hRawInput, RID_INPUT, pRawInput, &size, sizeof(RAWINPUTHEADER)); @@ -135,57 +140,60 @@ void fgSpaceballHandleWinEvent(HWND hwnd, WPARAM wParam, LPARAM lParam) 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)//0x01) - { // 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)//0x02) - { // 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)//0x03) - { // 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_DOWN)); - if (!stateBefore && stateNow) - INVOKE_WCB(*window, SpaceButton, (stateNow, GLUT_UP)); + 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_DOWN)); + if (!stateBefore && stateNow) + INVOKE_WCB(*window, SpaceButton, (stateNow, GLUT_UP)); + + } } + __fgSpaceKeystate = dwKeystate; } - __fgSpaceKeystate = dwKeystate; } } -} \ No newline at end of file +} + +#endif \ No newline at end of file