43#define MAP_ENTRY(button) \
45 GHOST_##button, #button \
124 "SpaceMouseWireless",
125 "SpaceMouseProWireless",
126 "SpaceMouseEnterprise",
215 hid_map_button_mask_(0),
217 button_depressed_(0),
218 pressed_buttons_cache_(),
219 pressed_long_buttons_cache_(),
221 motion_time_prev_(0),
223 motion_event_pending_(
false),
224 motion_dead_zone_(0.0f)
228 memset(translation_, 0,
sizeof(translation_));
229 memset(rotation_, 0,
sizeof(rotation_));
239#define LOG (&LOG_NDOF_DEVICE)
254 hid_map_button_mask_ = 0;
262 switch (product_id) {
268 hid_map_button_num_ = 2;
274 hid_map_button_num_ = 15;
280 hid_map_button_num_ = 31;
286 hid_map_button_num_ = 27;
287 hid_map_button_mask_ = 0x07C0F137;
295 hid_map_button_num_ = 21;
301 hid_map_button_num_ = 12;
306 hid_map_button_num_ = 8;
310 CLOG_INFO(
LOG, 2,
"unknown Logitech product %04hx", product_id);
315 switch (product_id) {
321 hid_map_button_num_ = 2;
332 hid_map_button_num_ = 27;
333 hid_map_button_mask_ = 0x07C0F137;
352 CLOG_INFO(
LOG, 2,
"unknown 3Dconnexion product %04hx", product_id);
357 CLOG_INFO(
LOG, 2,
"unknown device %04hx:%04hx", vendor_id, product_id);
364 if (hid_map_button_mask_ == 0) {
365 hid_map_button_mask_ =
int(~(
UINT_MAX << hid_map_button_num_));
368 CLOG_INFO(
LOG, 2,
"%d buttons -> hex:%X", hid_map_button_num_,
uint(hid_map_button_mask_));
383 memcpy(translation_, t,
sizeof(translation_));
385 motion_event_pending_ =
true;
390 memcpy(rotation_, r,
sizeof(rotation_));
392 motion_event_pending_ =
true;
402#define LOG (&LOG_NDOF_BUTTONS)
432#ifdef USE_3DCONNEXION_NONSTANDARD_KEYS
487 "rogue button trying to escape GHOST_NDOF manager");
490 GHOST_TEventNDOFButtonData *data = (GHOST_TEventNDOFButtonData *)event->getData();
492 data->action = press ? GHOST_kPress : GHOST_kRelease;
493 data->button = button;
498void GHOST_NDOFManager::sendKeyEvent(
GHOST_TKey key,
514 if (std::find(bitmask_devices_.begin(), bitmask_devices_.end(), device_type_) !=
515 bitmask_devices_.end())
517 button = hid_map_[button_number];
522 LOG, 2,
"button=%d, press=%d (mapped to none, ignoring!)", button_number,
int(press));
528 "button=%d, press=%d, name=%s",
533#ifndef USE_3DCONNEXION_NONSTANDARD_KEYS
544 if (window !=
nullptr) {
547 sendKeyEvent(key, press, time, window);
550 sendButtonEvent(button, press, time, window);
559 if (std::find(bitmask_devices_.begin(), bitmask_devices_.end(), device_type_) ==
560 bitmask_devices_.end())
565 button_bits &= hid_map_button_mask_;
567 int diff = button_depressed_ ^ button_bits;
569 for (
int button_number = 0; button_number < hid_map_button_num_; ++button_number) {
570 int mask = 1 << button_number;
573 bool press = button_bits &
mask;
576 button_depressed_ |=
mask;
579 button_depressed_ &= ~mask;
591 pressed_buttons_cache_;
594 for (
const auto &cached_button : cache) {
596 for (
const auto &button : buttons) {
597 if (button == cached_button) {
608 for (
const auto &button : buttons) {
610 for (
const auto &cached_button : cache) {
611 if (button == cached_button) {
631#define LOG (&LOG_NDOF_MOTION)
639 motion_dead_zone_ = dz;
642 CLOG_INFO(
LOG, 2,
"dead zone set to %.2f%s", dz, (dz > 0.5f) ?
" (unexpectedly high)" :
"");
647#define HOME(foo) (ndof->foo == 0.0f)
654 if (threshold == 0.0f) {
657#define HOME(foo) (fabsf(ndof->foo) < threshold)
664 if (!motion_event_pending_) {
668 motion_event_pending_ =
false;
673 if (window ==
nullptr) {
680 GHOST_TEventNDOFMotionData *data = (GHOST_TEventNDOFMotionData *)event->getData();
685 const float scale = 1.0f / 350.0f;
687 data->tx = scale * translation_[0];
688 data->ty = scale * translation_[1];
689 data->tz = scale * translation_[2];
691 data->rx = scale * rotation_[0];
692 data->ry = scale * rotation_[1];
693 data->rz = scale * rotation_[2];
694 data->dt = 0.001f * (motion_time_ - motion_time_prev_);
695 motion_time_prev_ = motion_time_;
701 switch (motion_state_) {
738 "motion sent, T=(%.2f,%.2f,%.2f), R=(%.2f,%.2f,%.2f) dt=%.3f, status=%s",
751 "motion sent, T=(%d,%d,%d) R=(%d,%d,%d) status=%s",
#define CLOG_INFO(clg_ref, level,...)
#define GHOST_ASSERT(x, info)
static const GHOST_NDOF_ButtonT ndof_HID_map_SpaceExplorer[]
static CLG_LogRef LOG_NDOF_DEVICE
static const int genericButtonCount
static const std::map< GHOST_NDOF_ButtonT, const char * > ndof_button_names
static bool atHomePosition(const GHOST_TEventNDOFMotionData *ndof)
static GHOST_TKey ghost_map_keyboard_from_ndof_buttom(const GHOST_NDOF_ButtonT button)
static CLG_LogRef LOG_NDOF_MOTION
static CLG_LogRef LOG_NDOF_BUTTONS
static const GHOST_NDOF_ButtonT ndof_HID_map_Generic[]
static bool nearHomePosition(const GHOST_TEventNDOFMotionData *ndof, float threshold)
static const GHOST_NDOF_ButtonT ndof_HID_map_Shared3Dx[]
static const char * ndof_progress_string[]
static const char * ndof_device_names[]
#define MAP_ENTRY(button)
static const GHOST_NDOF_ButtonT ndof_HID_map_SpacePilot[]
@ NDOF_SpaceMouseProWireless
@ NDOF_SpaceMouseWireless
@ NDOF_SpaceMouseEnterprise
std::array< GHOST_NDOF_ButtonT, 6 > NDOF_Button_Array
@ GHOST_NDOF_BUTTON_KBP_F11
@ GHOST_NDOF_BUTTON_FRONT
@ GHOST_NDOF_BUTTON_KBP_F7
@ GHOST_NDOF_BUTTON_DOMINANT
@ GHOST_NDOF_BUTTON_SPACE
@ GHOST_NDOF_BUTTON_DELETE
@ GHOST_NDOF_BUTTON_NP_F2
@ GHOST_NDOF_BUTTON_RIGHT
@ GHOST_NDOF_BUTTON_INVALID
@ GHOST_NDOF_BUTTON_KBP_F9
@ GHOST_NDOF_BUTTON_MINUS
@ GHOST_NDOF_BUTTON_PANZOOM
@ GHOST_NDOF_BUTTON_ROLL_CW
@ GHOST_NDOF_BUTTON_KBP_F1
@ GHOST_NDOF_BUTTON_ROLL_CCW
@ GHOST_NDOF_BUTTON_KBP_F12
@ GHOST_NDOF_BUTTON_KBP_F8
@ GHOST_NDOF_BUTTON_KBP_F5
@ GHOST_NDOF_BUTTON_KBP_F6
@ GHOST_NDOF_BUTTON_NP_F1
@ GHOST_NDOF_BUTTON_KBP_F2
@ GHOST_NDOF_BUTTON_NP_F4
@ GHOST_NDOF_BUTTON_NP_F3
@ GHOST_NDOF_BUTTON_KBP_F3
@ GHOST_NDOF_BUTTON_BOTTOM
@ GHOST_NDOF_BUTTON_ROTATE
@ GHOST_NDOF_BUTTON_KBP_F10
@ GHOST_NDOF_BUTTON_ENTER
@ GHOST_NDOF_BUTTON_KBP_F4
@ GHOST_NDOF_BUTTON_SHIFT
void updateButtonsBitmask(int button_bits, uint64_t time)
void updateButtonsArray(NDOF_Button_Array buttons, uint64_t time, NDOF_Button_Type type)
void updateButton(int button_number, bool press, uint64_t time)
void updateTranslation(const int t[3], uint64_t time)
GHOST_NDOFManager(GHOST_System &)
void updateRotation(const int r[3], uint64_t time)
bool setDevice(unsigned short vendor_id, unsigned short product_id)
GHOST_WindowManager * getWindowManager() const
GHOST_TSuccess pushEvent(const GHOST_IEvent *event)
GHOST_IWindow * getActiveWindow() const
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt)
ccl_device_inline float4 mask(const int4 mask, const float4 a)
unsigned __int64 uint64_t