X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fmswin%2Ffg_spaceball_mswin.c;h=84d848d820dbd5e9241c97b5cb9946255634f32b;hb=23613f66511be15d205d5bd7bb49883ad8c66624;hp=901954dc5f984a023acde38990a99ee37773c009;hpb=4fefea3c8feaa601f1f8af1b79888da862a53119;p=freeglut diff --git a/src/mswin/fg_spaceball_mswin.c b/src/mswin/fg_spaceball_mswin.c index 901954d..84d848d 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,13 +30,16 @@ */ /* - * Modified by Jinrong Xie (stonexjr@gmail.com) 12/24/2014 + * 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 { @@ -53,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; @@ -121,7 +124,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)); @@ -148,7 +151,7 @@ void fgSpaceballHandleWinEvent(HWND hwnd, WPARAM wParam, LPARAM lParam) // 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) + SPNAV_EVENT_MOTION_TRANSLATION) { // Translation vector short* pnData = (short*)(&pRawInput->data.hid.bRawData[1]); short X = pnData[0]; @@ -157,7 +160,7 @@ void fgSpaceballHandleWinEvent(HWND hwnd, WPARAM wParam, LPARAM lParam) INVOKE_WCB(*window, SpaceMotion, (X, Y, Z)); } else if (pRawInput->data.hid.bRawData[0] == - SPNAV_EVENT_MOTION_ROTATION)//0x02) + SPNAV_EVENT_MOTION_ROTATION) { // Axis aligned rotation vector short* pnData = (short*)(&pRawInput->data.hid.bRawData[1]); short rX = pnData[0]; @@ -166,7 +169,7 @@ void fgSpaceballHandleWinEvent(HWND hwnd, WPARAM wParam, LPARAM lParam) INVOKE_WCB(*window, SpaceRotation, (rX, rY, rZ)); } else if (pRawInput->data.hid.bRawData[0] == - SPNAV_EVENT_BUTTON)//0x03) + SPNAV_EVENT_BUTTON) { // State of the keys unsigned long dwKeystate = *(unsigned long*)(&pRawInput->data.hid.bRawData[1]); unsigned int state = GLUT_UP; @@ -188,4 +191,6 @@ void fgSpaceballHandleWinEvent(HWND hwnd, WPARAM wParam, LPARAM lParam) __fgSpaceKeystate = dwKeystate; } } -} \ No newline at end of file +} + +#endif \ No newline at end of file