Open CASCADE Technology Reference Manual 8.0.2
Loading...
Searching...
No Matches
WNT_HIDSpaceMouse Class Reference

Wrapper over Space Mouse data chunk within WM_INPUT event (known also as Raw Input in WinAPI). This class predefines specific list of supported devices, which does not depend on 3rdparty library provided by mouse vendor. Supported input chunks: More...

#include <WNT_HIDSpaceMouse.hxx>

Public Types

enum  { VENDOR_ID_LOGITECH = 0x46D , VENDOR_ID_3DCONNEXION = 0x256F }
 Vendor HID identifier. More...

Public Member Functions

 WNT_HIDSpaceMouse (unsigned long theProductId, const uint8_t *theData, size_t theSize)
 Main constructor.
int16_t RawValueRange () const
 Return the raw value range.
void SetRawValueRange (int16_t theRange)
 Set the raw value range.
bool IsTranslation () const
 Return TRUE if data chunk defines new translation values.
NCollection_Vec3< double > Translation (bool &theIsIdle, bool theIsQuadric) const
 Return new translation values.
bool IsRotation () const
 Return TRUE if data chunk defines new rotation values.
NCollection_Vec3< double > Rotation (bool &theIsIdle, bool theIsQuadric) const
 Return new rotation values.
bool IsKeyState () const
 Return TRUE for key state data chunk.
uint32_t KeyState () const
 Return new keystate.
Aspect_VKey HidToSpaceKey (unsigned short theKeyBit) const
 Convert key state bit into virtual key.

Static Public Member Functions

static bool IsKnownProduct (unsigned long theProductId)
 Return if product id is known by this class.

Detailed Description

Wrapper over Space Mouse data chunk within WM_INPUT event (known also as Raw Input in WinAPI). This class predefines specific list of supported devices, which does not depend on 3rdparty library provided by mouse vendor. Supported input chunks:

  • Rotation (3 directions);
  • Translation (3 directions);
  • Pressed buttons.

To use the class, register Raw Input device:

RAWINPUTDEVICE aRawInDevList[1];
RAWINPUTDEVICE& aRawSpace = aRawInDevList[0];
aRawSpace.usUsagePage = HID_USAGE_PAGE_GENERIC;
aRawSpace.usUsage = HID_USAGE_GENERIC_MULTI_AXIS_CONTROLLER;
aRawSpace.dwFlags = 0; // RIDEV_DEVNOTIFY
aRawSpace.hwndTarget = (HWND )theWindow->NativeHandle();
if (!::RegisterRawInputDevices (aRawInDevList, 1, sizeof(aRawInDevList[0]))) { Error; }
opencascade::handle< T > handle
Intrusive smart pointer template for Standard_Transient descendants. This is an alias to opencascade:...
Definition Standard_Handle.hxx:421

Then handle WM_INPUT events within window message loop.

AIS_ViewController theViewCtrl;
case WM_INPUT:
{
UINT aSize = 0;
::GetRawInputData ((HRAWINPUT )theLParam, RID_INPUT, NULL, &aSize, sizeof(RAWINPUTHEADER));
NCollection_LocalArray<BYTE> aRawData (aSize); // receive Raw Input for any device and
process known devices if (aSize == 0 || ::GetRawInputData ((HRAWINPUT )theLParam, RID_INPUT,
aRawData, &aSize, sizeof(RAWINPUTHEADER)) != aSize)
{
break;
}
const RAWINPUT* aRawInput = (RAWINPUT* )(BYTE* )aRawData;
if (aRawInput->header.dwType != RIM_TYPEHID)
{
break;
}
RID_DEVICE_INFO aDevInfo; aDevInfo.cbSize = sizeof(RID_DEVICE_INFO);
UINT aDevInfoSize = sizeof(RID_DEVICE_INFO);
if (::GetRawInputDeviceInfoW (aRawInput->header.hDevice, RIDI_DEVICEINFO, &aDevInfo,
&aDevInfoSize) != sizeof(RID_DEVICE_INFO)
|| (aDevInfo.hid.dwVendorId != WNT_HIDSpaceMouse::VENDOR_ID_LOGITECH
&& aDevInfo.hid.dwVendorId != WNT_HIDSpaceMouse::VENDOR_ID_3DCONNEXION))
{
break;
}
Aspect_VKeySet& aKeys = theViewCtrl.ChangeKeys();
const double aTimeStamp = theViewCtrl.EventTime();
WNT_HIDSpaceMouse aSpaceData (aDevInfo.hid.dwProductId, aRawInput->data.hid.bRawData,
aRawInput->data.hid.dwSizeHid); if (aSpaceData.IsTranslation())
{
// process translation input
bool isIdle = true, isQuadric = true;
const NCollection_Vec3<double> aTrans = aSpaceData.Translation (isIdle, isQuadric);
aTimeStamp, aTrans.y()); aKeys.KeyFromAxis (Aspect_VKey_NavSlideUp,
Aspect_VKey_NavSlideDown, aTimeStamp, aTrans.z());
}
if (aSpaceData.IsRotation()) {} // process rotation input
if (aSpaceData.IsKeyState()) {} // process keys input
break;
}
@ Aspect_VKey_NavSlideRight
sidewalk, right
Definition Aspect_VKey.hxx:170
@ Aspect_VKey_NavSlideDown
fall down
Definition Aspect_VKey.hxx:172
@ Aspect_VKey_NavForward
go forward
Definition Aspect_VKey.hxx:167
@ Aspect_VKey_NavBackward
go backward
Definition Aspect_VKey.hxx:168
@ Aspect_VKey_NavSlideUp
lift up
Definition Aspect_VKey.hxx:171
@ Aspect_VKey_NavSlideLeft
sidewalk, left
Definition Aspect_VKey.hxx:169
Auxiliary structure for handling viewer events between GUI and Rendering threads.
Definition AIS_ViewController.hxx:56
double EventTime() const
Return event time (e.g. current time).
Definition Aspect_WindowInputListener.hxx:37
Aspect_VKeySet & ChangeKeys()
Return keyboard state.
Definition Aspect_WindowInputListener.hxx:59
void KeyFromAxis(Aspect_VKey theNegative, Aspect_VKey thePositive, double theTime, double thePressure)
Simulate key up/down events from axis value.
Auxiliary class optimizing creation of array buffer (using stack allocation for small arrays).
Definition NCollection_LocalArray.hxx:39
constexpr Element_t y() const noexcept
Alias to 2nd component as Y coordinate in XYZ.
Definition NCollection_Vec3.hxx:125
constexpr Element_t x() const noexcept
Alias to 1st component as X coordinate in XYZ.
Definition NCollection_Vec3.hxx:119
constexpr Element_t z() const noexcept
Alias to 3rd component as Z coordinate in XYZ.
Definition NCollection_Vec3.hxx:131
WNT_HIDSpaceMouse(unsigned long theProductId, const uint8_t *theData, size_t theSize)
Main constructor.
@ VENDOR_ID_3DCONNEXION
Definition WNT_HIDSpaceMouse.hxx:97
@ VENDOR_ID_LOGITECH
Definition WNT_HIDSpaceMouse.hxx:96

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Vendor HID identifier.

Enumerator
VENDOR_ID_LOGITECH 
VENDOR_ID_3DCONNEXION 

Constructor & Destructor Documentation

◆ WNT_HIDSpaceMouse()

WNT_HIDSpaceMouse::WNT_HIDSpaceMouse ( unsigned long theProductId,
const uint8_t * theData,
size_t theSize )

Main constructor.

Member Function Documentation

◆ HidToSpaceKey()

Aspect_VKey WNT_HIDSpaceMouse::HidToSpaceKey ( unsigned short theKeyBit) const

Convert key state bit into virtual key.

◆ IsKeyState()

bool WNT_HIDSpaceMouse::IsKeyState ( ) const
inline

Return TRUE for key state data chunk.

◆ IsKnownProduct()

bool WNT_HIDSpaceMouse::IsKnownProduct ( unsigned long theProductId)
static

Return if product id is known by this class.

◆ IsRotation()

bool WNT_HIDSpaceMouse::IsRotation ( ) const
inline

Return TRUE if data chunk defines new rotation values.

◆ IsTranslation()

bool WNT_HIDSpaceMouse::IsTranslation ( ) const
inline

Return TRUE if data chunk defines new translation values.

◆ KeyState()

uint32_t WNT_HIDSpaceMouse::KeyState ( ) const
inline

Return new keystate.

◆ RawValueRange()

int16_t WNT_HIDSpaceMouse::RawValueRange ( ) const
inline

Return the raw value range.

◆ Rotation()

NCollection_Vec3< double > WNT_HIDSpaceMouse::Rotation ( bool & theIsIdle,
bool theIsQuadric ) const

Return new rotation values.

Parameters
[out]theIsIdleflag indicating idle state (no rotation)
[in]theIsQuadricflag to apply non-linear scale factor
Returns
vector of 3 elements defining rotation values within [-1..1] range, 0 meaning idle, .x defining tilt, .y defining roll and .z defining spin.

◆ SetRawValueRange()

void WNT_HIDSpaceMouse::SetRawValueRange ( int16_t theRange)
inline

Set the raw value range.

◆ Translation()

NCollection_Vec3< double > WNT_HIDSpaceMouse::Translation ( bool & theIsIdle,
bool theIsQuadric ) const

Return new translation values.

Parameters
[out]theIsIdleflag indicating idle state (no translation)
[in]theIsQuadricflag to apply non-linear scale factor
Returns
vector of 3 elements defining translation values within [-1..1] range, 0 meaning idle, .x defining left/right slide, .y defining forward/backward and .z defining up/down slide.

The documentation for this class was generated from the following file: