Update of /cvsroot/simspark/simspark/spark/plugin/inputois In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv17660 Added Files: Tag: projectx .cvsignore Makefile.am export.cpp inputdeviceois.h inputdeviceois_c.cpp inputsystemois.cpp inputsystemois.h inputsystemois_c.cpp keyboardois.cpp keyboardois.h keyboardois_c.cpp mouseois.cpp mouseois.h mouseois_c.cpp timerois.cpp timerois.h timerois_c.cpp Log Message: added ois input system --- NEW FILE: .cvsignore --- .deps .libs Makefile Makefile.in *.la *.lo --- NEW FILE: timerois.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Wed May 9 2007 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: timerois.h,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ 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; version 2 of the License. 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; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. TimerOIS HISTORY: 17.05.07 - OO - Initial version */ #ifndef TIMEROIS_H #define TIMEROIS_H #include "inputdeviceois.h" #include <sys/time.h> /** \class TimerOIS returns the elapsed time since the last call in milliseconds. */ class TimerOIS : public InputDeviceOIS { // // functions // public: TimerOIS(); virtual ~TimerOIS(); //! init the device virtual bool Init(kerosin::InputSystem* inputSystem); //! this filters an SDL specific input virtual int EventFilter(const OIS::EventArg* event); //! return an Input void GetInput(kerosin::Input &input); protected: unsigned long int TimevalSubtract(const timeval* x, const timeval* y) const; protected: timeval mLastTimeVal; }; DECLARE_CLASS(TimerOIS); #endif //MOUSESDL_H__ --- NEW FILE: inputdeviceois.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: inputdeviceois.h,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ 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; version 2 of the License. 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; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. InputDeviceOIS HISTORY: 16/03/07 - OO - Initial version */ #ifndef INPUTDEVICEOIS_H__ #define INPUTDEVICEOIS_H__ #include <kerosin/inputserver/inputdevice.h> #include <kerosin/inputserver/inputserver.h> namespace OIS { class EventArg; } /** \class InputDeviceOIS This class introduces OIS-specific callback functions for the event filtering. */ class InputDeviceOIS : public kerosin::InputDevice { // // functions // public: //! this filters an OIS specific input // virtual int EventFilter(const OIS::EventArg* event) = 0; virtual void Capture() {} }; DECLARE_ABSTRACTCLASS(InputDeviceOIS); #endif //INPUTDEVICEOIS_H__ --- NEW FILE: keyboardois_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: keyboardois_c.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ 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; version 2 of the License. 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; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "keyboardois.h" void CLASS(KeyboardOIS)::DefineClass() { DEFINE_BASECLASS(InputDeviceOIS); } --- NEW FILE: inputsystemois.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: inputsystemois.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ 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; version 2 of the License. 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; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "inputsystemois.h" #include "inputdeviceois.h" #include <zeitgeist/logserver/logserver.h> #include <kerosin/inputserver/inputserver.h> #include <kerosin/openglserver/openglserver.h> #include <sstream> #include <OIS/OIS.h> using namespace boost; using namespace kerosin; using namespace zeitgeist; using namespace OIS; /*! This function is used to filter OIS Events and delegate them to the input device which registered for the event type. NOTE: This function may run in a different thread, so care has to be taken when accessing the global object. Things to watch out for: - gDeviceList changes (done by individual devices (construction/destruction)) handled - Events are pushed into a device (done by EventFilter) - Events are taken out of a device (this is done by the inputserver) */ InputSystemOIS *gInputSystem; InputSystemOIS::InputSystemOIS() : InputSystem(), mOIS(0) { } InputSystemOIS::~InputSystemOIS() { InputManager::destroyInputSystem(mOIS); } bool InputSystemOIS::Init(InputServer *inputServer) { if (!InputSystem::Init(inputServer)) return false; mOpenGLServer = shared_dynamic_cast<OpenGLServer> (GetCore()->Get("/sys/server/opengl")); if (mOpenGLServer.get() == 0) { GetLog()->Error() << "(InputSystemOIS) ERROR: OpenGLServer not found\n"; return false; } // set up an OIS parameter list ParamList pl; std::ostringstream ss; ss << mOpenGLServer->GetWindowHandle(); pl.insert(ParamList::value_type("WINDOW", ss.str())); mOIS = InputManager::createInputSystem(pl); return true; } bool InputSystemOIS::CreateDevice(const std::string& deviceName) { // first, we mangle the deviceName to avoid nameclashes std::string mangledName = deviceName + "OIS"; shared_ptr<InputDevice> device = shared_static_cast<InputDevice>(GetCore()->New(mangledName)); if (device.get() == 0) { GetLog()->Error() << "ERROR: (InputSystemOIS) Creating device '" << mangledName << "'\n"; return false; } // initialize the device if (device->Init(this) == false) { GetLog()->Error() << "ERROR: (InputSystemOIS) Initializing device '" << mangledName << "'\n"; return false; } // try to link the device into the inputserver // some special case handling for the timer (FIXME) if (mangledName.compare("TimerOIS") == 0) { mTimer = shared_static_cast<TimerOIS>(device); } else { if (AddChildReference(device) == false) { GetLog()->Error() << "ERROR: (InputSystemOIS) Linking device '" << mangledName << "'\n"; return false; } } return true; } void InputSystemOIS::Capture() { // loop through all children for (TLeafList::iterator i = mChildren.begin(); i!=mChildren.end(); ++i) { shared_ptr<InputDeviceOIS> device = shared_static_cast<InputDeviceOIS>(*i); device->Capture(); } } void InputSystemOIS::AddInput(const Input& input) { InputSystem::AddInput(input); } bool InputSystemOIS::GetInput(Input& input) { Capture(); return InputSystem::GetInput(input); } bool InputSystemOIS::UpdateTimerInput(Input &input) { if (mTimer.get() == 0) { return false; } mTimer->GetInput(input); return true; } OIS::InputManager* InputSystemOIS::GetInputManager() { return mOIS; } --- NEW FILE: keyboardois.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: keyboardois.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ 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; version 2 of the License. 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; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "keyboardois.h" #include "inputsystemois.h" #include <kerosin/inputserver/inputserver.h> #include <zeitgeist/logserver/logserver.h> using namespace kerosin; using namespace OIS; KeyboardOIS::KeyboardOIS() { SetupSymMap(); } KeyboardOIS::~KeyboardOIS() { } void KeyboardOIS::SetupSymMap() { mSymbols.clear(); // KC_UNASSIGNED mSymbols[KC_ESCAPE] = Input::IC_ESCAPE; mSymbols[KC_0] = Input::IC_0; mSymbols[KC_1] = Input::IC_1; mSymbols[KC_2] = Input::IC_2; mSymbols[KC_3] = Input::IC_3; mSymbols[KC_4] = Input::IC_4; mSymbols[KC_5] = Input::IC_5; mSymbols[KC_6] = Input::IC_6; mSymbols[KC_7] = Input::IC_7; mSymbols[KC_8] = Input::IC_8; mSymbols[KC_9] = Input::IC_9; mSymbols[KC_MINUS] = Input::IC_MINUS; mSymbols[KC_EQUALS] = Input::IC_EQUALS; mSymbols[KC_BACK] = Input::IC_BACKSPACE; mSymbols[KC_TAB] = Input::IC_TAB; mSymbols[KC_Q] = Input::IC_Q; mSymbols[KC_W] = Input::IC_W; mSymbols[KC_E] = Input::IC_E; mSymbols[KC_R] = Input::IC_R; mSymbols[KC_T] = Input::IC_T; mSymbols[KC_Y] = Input::IC_Y; mSymbols[KC_U] = Input::IC_U; mSymbols[KC_I] = Input::IC_I; mSymbols[KC_O] = Input::IC_O; mSymbols[KC_P] = Input::IC_P; mSymbols[KC_LBRACKET] = Input::IC_LBRACKET; mSymbols[KC_RBRACKET] = Input::IC_RBRACKET; mSymbols[KC_RETURN] = Input::IC_RETURN; mSymbols[KC_LCONTROL] = Input::IC_LCTRL; mSymbols[KC_A] = Input::IC_A; mSymbols[KC_S] = Input::IC_S; mSymbols[KC_D] = Input::IC_D; mSymbols[KC_F] = Input::IC_F; mSymbols[KC_G] = Input::IC_G; mSymbols[KC_H] = Input::IC_H; mSymbols[KC_J] = Input::IC_J; mSymbols[KC_K] = Input::IC_K; mSymbols[KC_L] = Input::IC_L; mSymbols[KC_SEMICOLON] = Input::IC_SEMICOLON; // KC_APOSTROPHE // KC_GRAVE mSymbols[KC_LSHIFT] = Input::IC_LSHIFT; mSymbols[KC_BACKSLASH] = Input::IC_BACKSLASH; mSymbols[KC_Z] = Input::IC_Z; mSymbols[KC_X] = Input::IC_X; mSymbols[KC_C] = Input::IC_C; mSymbols[KC_V] = Input::IC_V; mSymbols[KC_B] = Input::IC_B; mSymbols[KC_N] = Input::IC_N; mSymbols[KC_M] = Input::IC_M; mSymbols[KC_COMMA] = Input::IC_COMMA; mSymbols[KC_PERIOD] = Input::IC_PERIOD; mSymbols[KC_SLASH] = Input::IC_SLASH; mSymbols[KC_RSHIFT] = Input::IC_RSHIFT; // KC_MULTIPLY // KC_LMENU mSymbols[KC_SPACE] = Input::IC_SPACE; // KC_CAPITAL mSymbols[KC_F1] = Input::IC_F1; mSymbols[KC_F2] = Input::IC_F2; mSymbols[KC_F3] = Input::IC_F3; mSymbols[KC_F4] = Input::IC_F4; mSymbols[KC_F5] = Input::IC_F5; mSymbols[KC_F6] = Input::IC_F6; mSymbols[KC_F7] = Input::IC_F7; mSymbols[KC_F8] = Input::IC_F8; mSymbols[KC_F9] = Input::IC_F9; mSymbols[KC_F10] = Input::IC_F10; mSymbols[KC_NUMLOCK] = Input::IC_NUMLOCK; mSymbols[KC_SCROLL] = Input::IC_SCROLLOCK; mSymbols[KC_NUMPAD7] = Input::IC_KP7; mSymbols[KC_NUMPAD8] = Input::IC_KP8; mSymbols[KC_NUMPAD9] = Input::IC_KP9; // KC_SUBTRACT mSymbols[KC_NUMPAD4] = Input::IC_KP4; mSymbols[KC_NUMPAD5] = Input::IC_KP5; mSymbols[KC_NUMPAD6] = Input::IC_KP6; // KC_ADD mSymbols[KC_NUMPAD1] = Input::IC_KP1; mSymbols[KC_NUMPAD2] = Input::IC_KP2; mSymbols[KC_NUMPAD3] = Input::IC_KP3; mSymbols[KC_NUMPAD0] = Input::IC_KP0; // is this the numad decimal? we map to it, at least mSymbols[KC_DECIMAL] = Input::IC_KP_DECIMAL; // KC_OEM_102 mSymbols[KC_F11] = Input::IC_F11; mSymbols[KC_F12] = Input::IC_F12; // KC_F13 // KC_F14 // KC_F15 // KC_KANA // KC_ABNT_C1 // KC_CONVERT // KC_NOCONVERT // KC_YEN // KC_ABNT_C2 // KC_NUMPADEQUALS // KC_PREVTRACK // KC_AT // KC_COLON // KC_UNDERLINE // KC_KANJI // KC_STOP // KC_AX // KC_UNLABELED // KC_NEXTTRACK mSymbols[KC_NUMPADENTER] = Input::IC_KP_ENTER; mSymbols[KC_RCONTROL] = Input::IC_RCTRL; // KC_MUTE // KC_CALCULATOR // KC_PLAYPAUSE // KC_MEDIASTOP // KC_VOLUMEDOWN // KC_VOLUMEUP // KC_WEBHOME mSymbols[KC_NUMPADCOMMA] = Input::IC_KP_DECIMAL; // KC_DIVIDE // KC_SYSRQ // KC_RMENU mSymbols[KC_PAUSE] = Input::IC_PAUSE; mSymbols[KC_HOME] = Input::IC_HOME; mSymbols[KC_UP] = Input::IC_UP; mSymbols[KC_PGUP] = Input::IC_PAGEUP; mSymbols[KC_LEFT] = Input::IC_LEFT; mSymbols[KC_RIGHT] = Input::IC_RIGHT; mSymbols[KC_END] = Input::IC_END; mSymbols[KC_DOWN] = Input::IC_DOWN; mSymbols[KC_PGDOWN] = Input::IC_PAGEDOWN; mSymbols[KC_INSERT] = Input::IC_INSERT; mSymbols[KC_DELETE] = Input::IC_DELETE; // KC_LWIN // KC_RWIN // KC_APPS // KC_POWER // KC_SLEEP // KC_WAKE // KC_WEBSEARCH // KC_WEBFAVORITES // KC_WEBREFRESH // KC_WEBSTOP // KC_WEBFORWARD // KC_WEBBACK // KC_MYCOMPUTER // KC_MAIL // KC_MEDIASELECT } bool KeyboardOIS::Init(kerosin::InputSystem *inputSystem) { InputSystemOIS* iois = dynamic_cast<InputSystemOIS*>(inputSystem); if (iois == 0) { GetLog()->Error() << "(KeyboardOIS) should be used with InputSystemOIS only\n"; return false; } OIS::InputManager* im = iois->GetInputManager(); mKeyboard = boost::shared_ptr<OIS::Keyboard>(static_cast<OIS::Keyboard*>(im->createInputObject(OIS::OISKeyboard, true))); mKeyboard.get()->setEventCallback(this); return InputDeviceOIS::Init(inputSystem); } bool KeyboardOIS::TranslateSymbol(KeyCode sym, int& tsym) const { TSymMap::const_iterator iter = mSymbols.find(sym); if (iter == mSymbols.end()) { return false; } tsym = (*iter).second; return true; } int KeyboardOIS::EventFilter(const EventArg* event, bool keyDown) { const KeyEvent* ke = dynamic_cast<const KeyEvent*>(event); // we only want keyboard events if (ke == 0) { return 1; } unsigned int& modState = mInputSystem->GetInputServer()->GetModifierState(); if (ke->key == KC_LSHIFT) { modState |= Input::eLShift; } if (ke->key == KC_RSHIFT) { modState |= Input::eRShift; } #if 0 if (ke->key.keysym.mod & KMOD_LALT) { modState |= Input::eLAlt; } if (ke->key.keysym.mod & KMOD_RALT) { modState |= Input::eRAlt; } #endif if (ke->key == 0) { return 1; } int tsym; // we could also use the event->text to get the mapping directly if (! TranslateSymbol(ke->key,tsym)) { GetLog()->Warning() << "(KeyboardOIS) WARNING: encountered unknown OIS key symbol " << ke->key << "\n"; return 1; } Input input(Input::eButton, tsym); input.mData.l = keyDown; mInputSystem->AddInputInternal(input); return 0; } void KeyboardOIS::Capture() { if (mKeyboard.get() != 0) { mKeyboard->capture(); } } bool KeyboardOIS::keyPressed(const OIS::KeyEvent& arg) { return (EventFilter(&arg,true) == 0); } bool KeyboardOIS::keyReleased(const OIS::KeyEvent& arg) { return (EventFilter(&arg,false) == 0); } --- NEW FILE: keyboardois.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: keyboardois.h,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ 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; version 2 of the License. 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; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. KeyboardOIS HISTORY: 16/03/07 - OO - Initial version */ #ifndef KEYBOARDOIS_H__ #define KEYBOARDOIS_H__ #include "inputdeviceois.h" #include <OIS/OIS.h> class KeyboardOIS : public InputDeviceOIS, OIS::KeyListener { // // functions // public: KeyboardOIS(); virtual ~KeyboardOIS(); //! init the device virtual bool Init(kerosin::InputSystem* inputSystem); //! this filters an OIS specific input virtual int EventFilter(const OIS::EventArg* event, bool keyDown); //! get the keyboard input void Capture(); protected: /** sets up the mapping from OIS key constants to InputServer key constants */ void SetupSymMap(); /** translates a OIS key constant to an InputServer key constant. returns true on success */ bool TranslateSymbol(OIS::KeyCode sym, int& tsym) const; /** This method is called for buffered input from OIS. keyPressed is inherited from the OIS Keylistener baseclass. */ virtual bool keyPressed(const OIS::KeyEvent& arg ); /** This method is called for buffered input from OIS. keyPressed is inherited from the OIS Keylistener baseclass. */ virtual bool keyReleased(const OIS::KeyEvent& arg); protected: typedef std::map<OIS::KeyCode,int> TSymMap; //! mapping from OIS key constants to InputServer key constants TSymMap mSymbols; //! the OIS keyboard device boost::shared_ptr<OIS::Keyboard> mKeyboard; }; DECLARE_CLASS(KeyboardOIS); #endif //KEYBOARDOIS_H__ --- NEW FILE: inputdeviceois_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group $Id: inputdeviceois_c.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ 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; version 2 of the License. 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; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "inputdeviceois.h" void CLASS(InputDeviceOIS)::DefineClass() { DEFINE_BASECLASS(kerosin/InputDevice); } --- NEW FILE: mouseois.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: mouseois.h,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ 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; version 2 of the License. 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; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. MouseOIS HISTORY: 16/03/07 - OO - Initial version */ #ifndef MOUSEOIS_H__ #define MOUSEOIS_H__ #include "inputdeviceois.h" #include <OIS/OIS.h> class MouseOIS : public InputDeviceOIS, OIS::MouseListener { // // functions // public: MouseOIS(); virtual ~MouseOIS(); //! init the device virtual bool Init(kerosin::InputSystem* inputSystem); //! this filters an OIS specific input virtual int EventFilter(const OIS::MouseEvent* me); //! this filters an OIS specific input virtual int EventFilter(const OIS::MouseEvent* me, bool pressed, OIS::MouseButtonID id); virtual void Capture(); /** This method os called for buffered input from OIS. mouseMoved is inherited from OIS Mouselistener baseclass. */ bool mouseMoved(const OIS::MouseEvent &e); /** This method os called for buffered input from OIS. mousePressed is inherited from OIS Mouselistener baseclass. */ bool mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id ); /** This method os called for buffered input from OIS. mouseReleased is inherited from OIS Mouselistener baseclass. */ bool mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id ); protected: //! the OIS mouse device boost::shared_ptr<OIS::Mouse> mMouse; //! flag if we want to emulate dragging by using the middle mouse button bool mEmulateDrag; //! if we emulate dragging: flag if we currently drag or not bool mDragMode; }; DECLARE_CLASS(MouseOIS); #endif //MOUSEOIS_H__ --- NEW FILE: inputsystemois.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: inputsystemois.h,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ 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; version 2 of the License. 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; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. InputSystemOIS HISTORY: 16/03/07 - OO - Initial version */ #ifndef INPUTSYSTEMOIS_H__ #define INPUTSYSTEMOIS_H__ #include "timerois.h" #include <deque> #include <kerosin/inputserver/inputsystem.h> #include <kerosin/inputserver/inputserver.h> #include <kerosin/openglserver/openglserver.h> namespace OIS { class InputManager; class EventArg; } class InputSystemOIS : public kerosin::InputSystem { // // functions // public: InputSystemOIS(); virtual ~InputSystemOIS(); virtual bool Init(kerosin::InputServer* inputServer); virtual bool CreateDevice(const std::string& deviceName); void Capture(); //! add the input to the queue virtual void AddInput(const kerosin::Input::Input& input); //! retrieve an input from the queue virtual bool GetInput(kerosin::Input::Input& input); //! get a pointer to the OIS input manager OIS::InputManager* GetInputManager(); protected: virtual bool UpdateTimerInput(kerosin::Input& input); private: boost::shared_ptr<kerosin::OpenGLServer> mOpenGLServer; boost::shared_ptr<TimerOIS> mTimer; OIS::InputManager* mOIS; }; DECLARE_CLASS(InputSystemOIS); #endif //INPUTSYSTEMOIS_H__ --- NEW FILE: timerois_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Wed May 9 2007 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: timerois_c.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ 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; version 2 of the License. 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; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "timerois.h" void CLASS(TimerOIS)::DefineClass() { DEFINE_BASECLASS(InputDeviceOIS); } --- NEW FILE: inputsystemois_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: inputsystemois_c.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ 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; version 2 of the License. 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; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "inputsystemois.h" void CLASS(InputSystemOIS)::DefineClass() { DEFINE_BASECLASS(kerosin/InputSystem); } --- NEW FILE: Makefile.am --- if BUILD_KEROSIN pkglib_LTLIBRARIES = inputois.la endif inputois_la_SOURCES = \ inputsystemois.cpp \ inputsystemois.h \ inputsystemois_c.cpp \ inputdeviceois.h \ inputdeviceois_c.cpp \ keyboardois.cpp \ keyboardois.h \ keyboardois_c.cpp \ export.cpp mouseois.cpp mouseois.h mouseois_c.cpp \ timerois.cpp \ timerois.h \ timerois_c.cpp # -module tells automake we're not building a library but a loadable module # so we don't need the "lib" prefix in the module name inputois_la_LDFLAGS = -module -avoid-version libois.a AM_CPPFLAGS = -I${top_srcdir}/lib @RUBY_CPPFLAGS@ -I/Users/fruit/Code/ogrenew/Dependencies/include --- NEW FILE: timerois.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Wed May 9 2007 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: timerois.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ 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; version 2 of the License. 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; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "timerois.h" #include <zeitgeist/logserver/logserver.h> using namespace kerosin; TimerOIS::TimerOIS() { mLastTimeVal.tv_sec = 0; mLastTimeVal.tv_usec = 0; } TimerOIS::~TimerOIS() { } bool TimerOIS::Init(kerosin::InputSystem* inputSystem) { if (InputDevice::Init(inputSystem) == false) { return false; } gettimeofday(&mLastTimeVal,0); return true; } int TimerOIS::EventFilter(const OIS::EventArg* event) { return 1; } void TimerOIS::GetInput(Input& input) { input.mType = Input::eAxis; input.mCode = Input::IC_AXIST; timeval tv; gettimeofday(&tv,0); unsigned int ticks = TimevalSubtract(&tv,&mLastTimeVal); input.mData.l = ticks; mLastTimeVal = tv; } unsigned long int TimerOIS::TimevalSubtract(const timeval* x, const timeval* z) const { timeval y,result; y.tv_usec = z->tv_usec; y.tv_sec = z->tv_sec; // Perform the carry for the later subtraction by updating y. if (x->tv_usec < y.tv_usec) { int nsec = (y.tv_usec - x->tv_usec) / 1000000 + 1; y.tv_usec -= 1000000 * nsec; y.tv_sec += nsec; } if (x->tv_usec - y.tv_usec > 1000000) { int nsec = (x->tv_usec - y.tv_usec) / 1000000; y.tv_usec += 1000000 * nsec; y.tv_sec -= nsec; } /* Compute the time remaining to wait. tv_usec is certainly positive. */ result.tv_sec = x->tv_sec - y.tv_sec; result.tv_usec = x->tv_usec - y.tv_usec; /* Return 0 if result is negative. */ if (x->tv_sec < y.tv_sec) { std::cerr << "(TimerOIS) went negative\n"; return 0; } else { return (1000000 * result.tv_sec + result.tv_usec) / 1000.0; } } --- NEW FILE: mouseois.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: mouseois.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ 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; version 2 of the License. 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; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "mouseois.h" #include "inputsystemois.h" #include <kerosin/inputserver/inputserver.h> #include <zeitgeist/logserver/logserver.h> using namespace kerosin; using namespace OIS; MouseOIS::MouseOIS() : mEmulateDrag(true), mDragMode(false) { } MouseOIS::~MouseOIS() { } bool MouseOIS::Init(kerosin::InputSystem* inputSystem) { InputSystemOIS* iois = dynamic_cast<InputSystemOIS*>(inputSystem); if (iois == 0) { GetLog()->Error() << "(MouseOIS) should be used with InputSystemOIS only\n"; return false; } OIS::InputManager* im = iois->GetInputManager(); mMouse = boost::shared_ptr<OIS::Mouse> (static_cast<OIS::Mouse*>(im->createInputObject(OIS::OISMouse, true))); mMouse.get()->setEventCallback(this); return InputDevice::Init(inputSystem); } int MouseOIS::EventFilter(const OIS::MouseEvent* me) { Input input(Input::eAxis,Input::IC_AXISX); if (me->state.X.rel != 0) { input.mData.l = me->state.X.rel; mInputSystem->AddInputInternal(input); } if (me->state.Y.rel != 0) { input.mCode = Input::IC_AXISY; input.mData.l = me->state.Y.rel; mInputSystem->AddInputInternal(input); } return 0; } int MouseOIS::EventFilter(const OIS::MouseEvent* me, bool pressed, OIS::MouseButtonID id) { Input input(Input::eButton); if (id == MB_Left) input.mCode = Input::IC_MOUSE_LEFT; else if (id == MB_Middle) { if (mEmulateDrag) { if (!pressed) { mDragMode = !mDragMode; input.mCode = Input::IC_MOUSE_LEFT; pressed = mDragMode; std::cerr << "Switched drag mode (" << pressed << ")\n"; } else return 0; } else input.mCode = Input::IC_MOUSE_MIDDLE; } else if (id == MB_Right) input.mCode = Input::IC_MOUSE_RIGHT; else return 0; input.mData.l = pressed; mInputSystem->AddInputInternal(input); return 0; } void MouseOIS::Capture() { if (mMouse.get() != 0) { mMouse->capture(); } } bool MouseOIS::mouseMoved(const OIS::MouseEvent& e) { return (EventFilter(&e) == 0); } bool MouseOIS::mousePressed(const OIS::MouseEvent& e, OIS::MouseButtonID id) { std::cerr << "mousePressed\n"; return (EventFilter(&e,true,id) == 0); } bool MouseOIS::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) { std::cerr << "mouseReleased\n"; return (EventFilter(&e,false,id) == 0); } --- NEW FILE: mouseois_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: mouseois_c.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ 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; version 2 of the License. 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; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "mouseois.h" void CLASS(MouseOIS)::DefineClass() { DEFINE_BASECLASS(InputDeviceOIS); } --- NEW FILE: export.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: export.cpp,v 1.1.2.1 2007/07/24 01:13:16 fruit Exp $ 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; version 2 of the License. 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; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "inputsystemois.h" #include "inputdeviceois.h" #include "keyboardois.h" #include "mouseois.h" #include "timerois.h" #include <zeitgeist/zeitgeist.h> ZEITGEIST_EXPORT_BEGIN() ZEITGEIST_EXPORT(InputSystemOIS); ZEITGEIST_EXPORT(InputDeviceOIS); ZEITGEIST_EXPORT(KeyboardOIS); ZEITGEIST_EXPORT(MouseOIS); ZEITGEIST_EXPORT(TimerOIS); ZEITGEIST_EXPORT_END() |