/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield * * This software is open source and may be redistributed and/or modified under * the terms of the GNU General Public License (GPL) version 2.0. * The full license is in LICENSE.txt file included with this distribution,. * * This software 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 * include LICENSE.txt for more details. */ #include #include "JoystickDevice.h" #include #include #include #include JoystickDevice::JoystickDevice() { _verbose = false; // init SDL if ( SDL_Init(SDL_INIT_JOYSTICK) < 0 ) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); int numJoysticks = SDL_NumJoysticks(); if (_verbose) { std::cout<<"number of joysticks "<0 ? SDL_JoystickOpen(0) : 0; _numAxes = _joystick ? SDL_JoystickNumAxes(_joystick) : 0; _numBalls = _joystick ? SDL_JoystickNumBalls(_joystick) : 0; _numHats = _joystick ? SDL_JoystickNumHats(_joystick) : 0; _numButtons = _joystick ? SDL_JoystickNumButtons(_joystick) : 0; if (_verbose) { std::cout<<"numAxes = "<<_numAxes<getTime() : 0.0; osgGA::GUIEventAdapter* previous_event = eq->getCurrentEventState(); float projected_mx = previous_event->getXmin() + (mx+1.0)*0.5*(previous_event->getXmax()-previous_event->getXmin()); float projected_my = previous_event->getYmin() + (my+1.0)*0.5*(previous_event->getYmax()-previous_event->getYmin()); if (mx!=prev_mx || my!=prev_my) { eq->mouseMotion(projected_mx, projected_my, time); } OSG_NOTICE<<"mx="<0) { if (newButtonValues[bi]==0) eq->mouseButtonRelease(projected_mx,projected_my,mouseButton,time); else eq->mouseButtonPress(projected_mx,projected_my,mouseButton,time); } else if (key>0) { if (newButtonValues[bi]==0) eq->keyRelease(key,time); else eq->keyPress(key,time); } } } _axisValues.swap(newAxisValues); _buttonValues.swap(newButtonValues); } return !(getEventQueue()->empty()); }