2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * ***** END GPL LICENSE BLOCK *****
24 #ifndef __GHOST_NDOFMANAGER_H__
25 #define __GHOST_NDOFMANAGER_H__
27 #include "GHOST_System.h"
30 // #define DEBUG_NDOF_MOTION
31 // #define DEBUG_NDOF_BUTTONS
49 // NDOF device button event types
51 // used internally, never sent
53 // these two are available from any 3Dconnexion device
66 // 90 degree rotations
67 // these don't all correspond to physical buttons
85 // general-purpose buttons
86 // users can assign functions via keymap editor
97 // more general-purpose buttons
105 class GHOST_NDOFManager
108 GHOST_NDOFManager(GHOST_System&);
110 virtual ~GHOST_NDOFManager() {}
112 // whether multi-axis functionality is available (via the OS or driver)
113 // does not imply that a device is plugged in or being used
114 virtual bool available() = 0;
116 // each platform's device detection should call this
117 // use standard USB/HID identifiers
118 bool setDevice(unsigned short vendor_id, unsigned short product_id);
120 // filter out small/accidental/uncalibrated motions by
121 // setting up a "dead zone" around home position
122 // set to 0 to disable
123 // 0.1 is a safe and reasonable value
124 void setDeadZone(float);
126 // the latest raw axis data from the device
127 // NOTE: axis data should be in blender view coordinates
128 // +X is to the right
130 // +Z is out of the screen
131 // for rotations, look from origin to each +axis
132 // rotations are + when CCW, - when CW
133 // each platform is responsible for getting axis data into this form
134 // these values should not be scaled (just shuffled or flipped)
135 void updateTranslation(short t[3], GHOST_TUns64 time);
136 void updateRotation(short r[3], GHOST_TUns64 time);
138 // the latest raw button data from the device
139 // use HID button encoding (not NDOF_ButtonT)
140 void updateButton(int button_number, bool press, GHOST_TUns64 time);
141 void updateButtons(int button_bits, GHOST_TUns64 time);
142 // NDOFButton events are sent immediately
144 // processes and sends most recent raw data as an NDOFMotion event
145 // returns whether an event was sent
146 bool sendMotionEvent();
149 GHOST_System& m_system;
152 void sendButtonEvent(NDOF_ButtonT, bool press, GHOST_TUns64 time, GHOST_IWindow *);
153 void sendKeyEvent(GHOST_TKey, bool press, GHOST_TUns64 time, GHOST_IWindow *);
155 NDOF_DeviceT m_deviceType;
158 const NDOF_ButtonT *m_hidMap;
160 short m_translation[3];
162 int m_buttons; // bit field
164 GHOST_TUns64 m_motionTime; // in milliseconds
165 GHOST_TUns64 m_prevMotionTime; // time of most recent Motion event sent
167 GHOST_TProgress m_motionState;
168 bool m_motionEventPending;
169 float m_deadZone; // discard motion with each component < this