/* * InputDevice.h * * Copyright (C) 2001 J. "MUFTI" Scheurich * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program (see the file "COPYING" for details); if * not, write to the Free Software Foundation, Inc., 675 Mass Ave, * Cambridge, MA 02139, USA. */ #ifndef _INPUTDEVICE_H #define _INPUTDEVICE_H #include #include #include "stdafx.h" #include "TransformMode.h" #include "EulerAngles.h" #include "Quaternion.h" class InputDeviceApp; // class to access several joystick like devices via a unified interface // Example for such devices are spaceballs, magellan-devices, // thumbsticks of gamepads and of course joysticks 8-) // This can also be used for Xinput devices, that not deliver zero, // if you take your hand away from the device like dialbox, mouse or // graphics tablett. class InputDevice { public: // true if there is a new event from the joystick virtual bool readInputDevice(void) = 0; Quaternion& get_quaternion(TransformMode* tm, bool local, bool check_only); virtual Quaternion& get_quaternion(TransformMode* tm=NULL, bool check_only=false); virtual Quaternion& get_localQuaternion(TransformMode* tm=NULL, bool check_only=false); EulerAngles& get_eulerAngles(TransformMode* tm,bool check_only,bool current); Vec3f& get_vector(TransformMode* tm); int get_number_axes(void) { return number_max_axis - number_ignored_axes; } int get_number_max_axis(void) { return number_max_axis; } int get_number_buttons(void) { return number_buttons; } bool isWand(void) { return wandflag; } bool isHead(void) { return headflag; } virtual bool sendalways(void) { return alwaysflag; } virtual bool allzero(void); virtual bool isTracker(void) { return false; } virtual bool hasReadDelay(void) { return false; } virtual void prepareRead(void) { return; } virtual float maxvalue(int) const=0; virtual bool useCurrent(void) { return false; } virtual void setHeadNavigation(void) { } virtual bool getHeadNavigation(void) { return true; } virtual void setIgnoreSize(const char* ignoreSize_string) {} float getxyzfactor(void) { return xyzfactor; } float getrotfactor(void) { return rotfactor; } void setxyzfactor(float f) { xyzfactor = f; } void setrotfactor(float f) { rotfactor = f; } void set_firstflag(void); InputDevice() { int i; // initialise joystick class default data button_pressed=-1; button_released=-1; number_buttons=0; number_max_axis=0; number_max_axes=7; number_ignored_axes=0; for (i=0;i class linux_joystick : public InputDevice { public: linux_joystick() {} ~linux_joystick(); linux_joystick(char* device); bool readInputDevice(void); private: int fd; int version; char name[NAME_LENGTH]; struct js_event js; float maxvalue(int i) const {return(32767.0);} float linux_js_factor; }; # endif # ifdef DIRECTX_JOYSTICK // using M$Windows Joystick interface from DirectInput API # include #include #include #include class windows_joystick : public InputDevice { public: windows_joystick() {} ~windows_joystick(); windows_joystick(char* device); bool readInputDevice(void); private: int number_of_joystick; int version; char name[MAXPNAMELEN]; DIJOYSTATE2 js; DIPROPRANGE diprg; int *max_value; int *null_value; float maxvalue(int i) const {return max_value[i];} float factor; HRESULT InitDirectInput(); LPDIRECTINPUT8 g_pDI; LPDIRECTINPUTDEVICE8 g_pJoystick; }; # endif # ifdef WINDOWS_JOYSTICK // using older M$Windows Joystick API interface ("JOYCAPS" etc.) # include class windows_joystick : public InputDevice { public: windows_joystick() {} ~windows_joystick(); windows_joystick(char* device); bool readInputDevice(void); private: int number_of_joystick; int version; char name[MAXPNAMELEN]; JOYCAPS joycapabilities; JOYINFOEX joyinfo_ex; int *maximum; int *null_value; float maxvalue(int i) const {return maximum[i];} float windows_js_factor; }; # endif # ifdef HAVE_SDL_JOYSTICK // using modified Simple DirectMedia Layer joystick interface # include "SDLjoystick/SDL_joystick.h" class SDL_joystick : public InputDevice { public: // SDL_joystick() {} ~SDL_joystick(); SDL_joystick(char* device); bool readInputDevice(void); private: SDL_Joystick* js; int number_of_joystick; int *maximum; int *null_value; float maxvalue(int i) const {return maximum[i];} float sdl_factor; }; # endif # ifdef HAVE_XINPUT // Xi X11 XInput devices (e.g. spaceball, magellan) # include extern "C" { # include "swtxinput.h" } extern Display* swGetDisplay(void); extern Window* swGetWindow(void); class xinput : public InputDevice { public: xinput() {} ~xinput(); xinput(char* device); bool readInputDevice(void); private: char* name; swXinput* swxinput; float xinput_factor; float *maximum; float maxvalue(int i) const {return maximum[i];} int nullsize; }; # endif # ifdef HAVE_LIBSBALL // using libsball library for SpaceTec/LabTec Spaceball devices # include class spaceball : public InputDevice { public: spaceball() {} ~spaceball(); spaceball(char* device); bool readInputDevice(void); private: char* name; SBallHandle sball; float maxvalue(int i) const {return maximum;} float maximum; float sball_factor; int nullsize; }; # endif # ifdef HAVE_WINDOWS_P5 // using P5 library for P5 devices on M$Windows #include "p5dll.h" #include "p5bend.h" #include "P5Motion.h" class windowsp5 : public InputDevice { public: CP5DLL P5; bool bP5Present; windowsp5() {} ~windowsp5(); windowsp5(char* device); bool sendalways(void) { return true; } bool readInputDevice(void); private: char* name; int number_p5; float maxvalue(int i) const {return maximum;} float maximum; float p5_factor; int nullsize; }; # endif # ifdef HAVE_WINDOWS_SPACEBALL // using libsball library for SpaceTec/LabTec Spaceball devices on M$Windows //REPLACE //# include class windowsspaceball : public InputDevice { public: windowsspaceball() {} ~windowsspaceball(); windowsspaceball(char* device); bool readInputDevice(void); private: char* name; // REPLACE // SBallHandle sball; float maxvalue(int i) const {return maximum;} float maximum; float windows_sball_factor; int nullsize; }; # endif # ifdef HAVE_AFLOCK // using aFlock program from VR Juggler library for // Ascention Flock of birds devices # include "Aflock.h" class AflockDevice { public: AflockDevice(char* device); ~AflockDevice(); Aflock* getAflock(void); void close(); // parameters void setBaud(char* baudrate_string); void setSync(char* sync_string); void setBlock(char* block_string); void setNumBrds(char* numBrds_string); void setTransmit(char* transmit_string); void setHemi(char* hemi_string); void setFilt(char* filt_string); void setSuddenChangeLock(char* sudden_string); void setReport(char* report_string); void setCalfile(char* calfile_string); void start(void) { if (flock) flock->start(); } void stop(void) { if (flock) flock->stop(); } private: char* name; Aflock* flock; bool opened; char* device; int baudrate; int sync; int block; int numBrds; int transmit; BIRD_HEMI hemi; BIRD_FILT filt; bool sudden_change_lock; char report; char* calfile; }; class aflock : public InputDevice { public: aflock(AflockDevice* device,char* receiver_string,bool headflag); ~aflock(); bool readInputDevice(void); bool sendalways(void) { return true; } bool hasReadDelay(void) { return true; } void prepareRead(void); void setHeadNavigation(void) { headNavigation=true; } bool getHeadNavigation(void) { return isTracker() && headNavigation; } bool useCurrent(void) { return true; } void setIgnoreSize(const char* ignoresize_string); private: int receiver; char* name; bool head; bool wand; bool headNavigation; bool isTracker(void) { return head; } bool isWand(void) { return wand; } Aflock* flock; float maxvalue(int i) const {return maximum;} float maximum; float aflock_factor; float degreefactor; bool aflockFirstFlag; float ignoreSize; float old_value[3]; }; # endif #endif