|
Blender
V2.59
|
00001 /* 00002 * $Id: GHOST_NDOFManager.h 38922 2011-08-02 09:09:07Z jesterking $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * Contributor(s): 00021 * Mike Erwin 00022 * 00023 * ***** END GPL LICENSE BLOCK ***** 00024 */ 00025 00026 #ifndef _GHOST_NDOFMANAGER_H_ 00027 #define _GHOST_NDOFMANAGER_H_ 00028 00029 #include "GHOST_System.h" 00030 00031 00032 // #define DEBUG_NDOF_MOTION 00033 // #define DEBUG_NDOF_BUTTONS 00034 00035 typedef enum { 00036 NDOF_UnknownDevice, // <-- motion will work fine, buttons are ignored 00037 00038 // current devices 00039 NDOF_SpaceNavigator, 00040 NDOF_SpaceExplorer, 00041 NDOF_SpacePilotPro, 00042 00043 // older devices 00044 NDOF_SpacePilot 00045 00046 } NDOF_DeviceT; 00047 00048 // NDOF device button event types 00049 typedef enum { 00050 // used internally, never sent 00051 NDOF_BUTTON_NONE, 00052 // these two are available from any 3Dconnexion device 00053 NDOF_BUTTON_MENU, 00054 NDOF_BUTTON_FIT, 00055 // standard views 00056 NDOF_BUTTON_TOP, 00057 NDOF_BUTTON_BOTTOM, 00058 NDOF_BUTTON_LEFT, 00059 NDOF_BUTTON_RIGHT, 00060 NDOF_BUTTON_FRONT, 00061 NDOF_BUTTON_BACK, 00062 // more views 00063 NDOF_BUTTON_ISO1, 00064 NDOF_BUTTON_ISO2, 00065 // 90 degree rotations 00066 // these don't all correspond to physical buttons 00067 NDOF_BUTTON_ROLL_CW, 00068 NDOF_BUTTON_ROLL_CCW, 00069 NDOF_BUTTON_SPIN_CW, 00070 NDOF_BUTTON_SPIN_CCW, 00071 NDOF_BUTTON_TILT_CW, 00072 NDOF_BUTTON_TILT_CCW, 00073 // device control 00074 NDOF_BUTTON_ROTATE, 00075 NDOF_BUTTON_PANZOOM, 00076 NDOF_BUTTON_DOMINANT, 00077 NDOF_BUTTON_PLUS, 00078 NDOF_BUTTON_MINUS, 00079 // general-purpose buttons 00080 // users can assign functions via keymap editor 00081 NDOF_BUTTON_1, 00082 NDOF_BUTTON_2, 00083 NDOF_BUTTON_3, 00084 NDOF_BUTTON_4, 00085 NDOF_BUTTON_5, 00086 NDOF_BUTTON_6, 00087 NDOF_BUTTON_7, 00088 NDOF_BUTTON_8, 00089 NDOF_BUTTON_9, 00090 NDOF_BUTTON_10, 00091 00092 } NDOF_ButtonT; 00093 00094 class GHOST_NDOFManager 00095 { 00096 public: 00097 GHOST_NDOFManager(GHOST_System&); 00098 00099 virtual ~GHOST_NDOFManager() {}; 00100 00101 // whether multi-axis functionality is available (via the OS or driver) 00102 // does not imply that a device is plugged in or being used 00103 virtual bool available() = 0; 00104 00105 // each platform's device detection should call this 00106 // use standard USB/HID identifiers 00107 bool setDevice(unsigned short vendor_id, unsigned short product_id); 00108 00109 // filter out small/accidental/uncalibrated motions by 00110 // setting up a "dead zone" around home position 00111 // set to 0 to disable 00112 // 0.1 is a safe and reasonable value 00113 void setDeadZone(float); 00114 00115 // the latest raw axis data from the device 00116 // NOTE: axis data should be in blender view coordinates 00117 // +X is to the right 00118 // +Y is up 00119 // +Z is out of the screen 00120 // for rotations, look from origin to each +axis 00121 // rotations are + when CCW, - when CW 00122 // each platform is responsible for getting axis data into this form 00123 // these values should not be scaled (just shuffled or flipped) 00124 void updateTranslation(short t[3], GHOST_TUns64 time); 00125 void updateRotation(short r[3], GHOST_TUns64 time); 00126 00127 // the latest raw button data from the device 00128 // use HID button encoding (not NDOF_ButtonT) 00129 void updateButton(int button_number, bool press, GHOST_TUns64 time); 00130 void updateButtons(int button_bits, GHOST_TUns64 time); 00131 // NDOFButton events are sent immediately 00132 00133 // processes and sends most recent raw data as an NDOFMotion event 00134 // returns whether an event was sent 00135 bool sendMotionEvent(); 00136 00137 protected: 00138 GHOST_System& m_system; 00139 00140 private: 00141 void sendButtonEvent(NDOF_ButtonT, bool press, GHOST_TUns64 time, GHOST_IWindow*); 00142 void sendKeyEvent(GHOST_TKey, bool press, GHOST_TUns64 time, GHOST_IWindow*); 00143 00144 NDOF_DeviceT m_deviceType; 00145 int m_buttonCount; 00146 int m_buttonMask; 00147 00148 short m_translation[3]; 00149 short m_rotation[3]; 00150 int m_buttons; // bit field 00151 00152 GHOST_TUns64 m_motionTime; // in milliseconds 00153 GHOST_TUns64 m_prevMotionTime; // time of most recent Motion event sent 00154 00155 GHOST_TProgress m_motionState; 00156 bool m_motionEventPending; 00157 float m_deadZone; // discard motion with each component < this 00158 }; 00159 00160 #endif