Blender V2.61 - r43446

GHOST_NDOFManager.h

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