mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-17 06:43:14 +02:00
Do not merge - Spacemouse
This commit is contained in:
parent
603405ad61
commit
5d695da630
4 changed files with 1345 additions and 0 deletions
72
examples/controllers/Spacemouse/spacemouseExample.js
Normal file
72
examples/controllers/Spacemouse/spacemouseExample.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
//
|
||||
// spaceMouseDebug.js
|
||||
// examples
|
||||
//
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
|
||||
|
||||
var firstmove = 1;
|
||||
var position = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
};
|
||||
var rotation = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
};
|
||||
|
||||
function toggleFirstMove() {
|
||||
if(firstmove){
|
||||
print("____________________________________");
|
||||
firstmove = 0;
|
||||
}
|
||||
}
|
||||
|
||||
function spacemouseCheck() {
|
||||
return Controller.Hardware.Spacemouse !== undefined;
|
||||
}
|
||||
|
||||
function update(deltaTime) {
|
||||
if(spacemouseCheck){
|
||||
if(Controller.getValue(Controller.Standard.LY) != 0){
|
||||
toggleFirstMove();
|
||||
print("Controller TX: " + Controller.getValue(Controller.Standard.LY));
|
||||
}
|
||||
|
||||
if(Controller.getValue(Controller.Standard.LX) != 0){
|
||||
toggleFirstMove();
|
||||
print("Controller TZ: " + Controller.getValue(Controller.Standard.LX));
|
||||
}
|
||||
|
||||
if(Controller.getValue(Controller.Standard.LT) != 0){
|
||||
toggleFirstMove();
|
||||
print("Controller TY: " + Controller.getValue(Controller.Standard.LT));
|
||||
}
|
||||
|
||||
if(Controller.getValue(Controller.Standard.RY) != 0){
|
||||
toggleFirstMove();
|
||||
print("Controller RX: " + Controller.getValue(Controller.Standard.RY));
|
||||
}
|
||||
|
||||
if(Controller.getValue(Controller.Standard.RX) != 0){
|
||||
toggleFirstMove();
|
||||
print("Controller RZ: " + Controller.getValue(Controller.Standard.RX));
|
||||
}
|
||||
|
||||
if(Controller.getValue(Controller.Standard.RT) != 0){
|
||||
toggleFirstMove();
|
||||
print("Controller RY: " + Controller.getValue(Controller.Standard.RT));
|
||||
}
|
||||
|
||||
firstmove = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Script.update.connect(update);
|
15
interface/resources/controllers/spacemouse.json
Normal file
15
interface/resources/controllers/spacemouse.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "Spacemouse to Standard",
|
||||
"channels": [
|
||||
{ "from": "Spacemouse.TranslateX", "to": "Standard.LY" },
|
||||
{ "from": "Spacemouse.TranslateZ", "filters": "invert", "to": "Standard.LX" },
|
||||
|
||||
{ "from": "Spacemouse.RotateX", "to": "Standard.RY" },
|
||||
{ "from": "Spacemouse.RotateZ", "to": "Standard.RX" },
|
||||
|
||||
{ "from": "Spacemouse.LeftButton", "to": "Standard.Back" },
|
||||
{ "from": "Spacemouse.RightButton", "to": "Standard.Start" }
|
||||
|
||||
]
|
||||
}
|
||||
|
1022
libraries/input-plugins/src/input-plugins/SpacemouseManager.cpp
Normal file
1022
libraries/input-plugins/src/input-plugins/SpacemouseManager.cpp
Normal file
File diff suppressed because it is too large
Load diff
236
libraries/input-plugins/src/input-plugins/SpacemouseManager.h
Normal file
236
libraries/input-plugins/src/input-plugins/SpacemouseManager.h
Normal file
|
@ -0,0 +1,236 @@
|
|||
// SpacemouseManager.h
|
||||
// interface/src/devices
|
||||
//
|
||||
// Created by Marcel Verhagen on 09-06-15.
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_SpacemouseManager_h
|
||||
#define hifi_SpacemouseManager_h
|
||||
|
||||
#include <QObject>
|
||||
#include <QLibrary>
|
||||
#include <controllers/UserInputMapper.h>
|
||||
#include <controllers/InputDevice.h>
|
||||
#include <controllers/StandardControls.h>
|
||||
|
||||
#include "InputPlugin.h"
|
||||
|
||||
#ifndef HAVE_SPACEMOUSE
|
||||
class SpacemouseManager : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static SpacemouseManager& getInstance();
|
||||
void ManagerFocusOutEvent();
|
||||
void init() {};
|
||||
void destroy() {};
|
||||
bool Is3dmouseAttached() { return false; };
|
||||
public slots:
|
||||
void toggleConnexion(bool shouldEnable) {};
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SPACEMOUSE
|
||||
// the windows connexion rawinput
|
||||
#ifdef Q_OS_WIN
|
||||
|
||||
#include "../../../interface/external/3dconnexionclient/include/I3dMouseParams.h"
|
||||
#include <QAbstractNativeEventFilter>
|
||||
#include <QAbstractEventDispatcher>
|
||||
#include <Winsock2.h>
|
||||
#include <windows.h>
|
||||
|
||||
// windows rawinput parameters
|
||||
class MouseParameters : public I3dMouseParam {
|
||||
public:
|
||||
MouseParameters();
|
||||
|
||||
// I3dmouseSensor interface
|
||||
bool IsPanZoom() const;
|
||||
bool IsRotate() const;
|
||||
Speed GetSpeed() const;
|
||||
|
||||
void SetPanZoom(bool isPanZoom);
|
||||
void SetRotate(bool isRotate);
|
||||
void SetSpeed(Speed speed);
|
||||
|
||||
// I3dmouseNavigation interface
|
||||
Navigation GetNavigationMode() const;
|
||||
Pivot GetPivotMode() const;
|
||||
PivotVisibility GetPivotVisibility() const;
|
||||
bool IsLockHorizon() const;
|
||||
|
||||
void SetLockHorizon(bool bOn);
|
||||
void SetNavigationMode(Navigation navigation);
|
||||
void SetPivotMode(Pivot pivot);
|
||||
void SetPivotVisibility(PivotVisibility visibility);
|
||||
|
||||
static bool Is3dmouseAttached();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
MouseParameters(const MouseParameters&);
|
||||
const MouseParameters& operator = (const MouseParameters&);
|
||||
|
||||
Navigation fNavigation;
|
||||
Pivot fPivot;
|
||||
PivotVisibility fPivotVisibility;
|
||||
bool fIsLockHorizon;
|
||||
|
||||
bool fIsPanZoom;
|
||||
bool fIsRotate;
|
||||
Speed fSpeed;
|
||||
};
|
||||
|
||||
class SpacemouseManager : public QObject, public QAbstractNativeEventFilter {
|
||||
//class SpacemouseManager : public InputPlugin, public controller::InputDevice {
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
SpacemouseManager() {};
|
||||
|
||||
static SpacemouseManager& getInstance();
|
||||
void init();
|
||||
void destroy();
|
||||
bool Is3dmouseAttached();
|
||||
|
||||
SpacemouseManager* client;
|
||||
|
||||
void ManagerFocusOutEvent();
|
||||
|
||||
I3dMouseParam& MouseParams();
|
||||
const I3dMouseParam& MouseParams() const;
|
||||
|
||||
virtual void Move3d(HANDLE device, std::vector<float>& motionData);
|
||||
virtual void On3dmouseKeyDown(HANDLE device, int virtualKeyCode);
|
||||
virtual void On3dmouseKeyUp(HANDLE device, int virtualKeyCode);
|
||||
|
||||
virtual bool nativeEventFilter(const QByteArray& eventType, void* message, long* result) Q_DECL_OVERRIDE
|
||||
{
|
||||
MSG* msg = static_cast< MSG * >(message);
|
||||
return RawInputEventFilter(message, result);
|
||||
}
|
||||
|
||||
public slots:
|
||||
void toggleSpacemouse(bool shouldEnable);
|
||||
|
||||
//std::shared_ptr<SpacemouseDevice> getDevice();
|
||||
|
||||
|
||||
signals:
|
||||
void Move3d(std::vector<float>& motionData);
|
||||
void On3dmouseKeyDown(int virtualKeyCode);
|
||||
void On3dmouseKeyUp(int virtualKeyCode);
|
||||
|
||||
private:
|
||||
bool InitializeRawInput(HWND hwndTarget);
|
||||
|
||||
bool RawInputEventFilter(void* msg, long* result);
|
||||
|
||||
void OnRawInput(UINT nInputCode, HRAWINPUT hRawInput);
|
||||
UINT GetRawInputBuffer(PRAWINPUT pData, PUINT pcbSize, UINT cbSizeHeader);
|
||||
bool TranslateRawInputData(UINT nInputCode, PRAWINPUT pRawInput);
|
||||
void On3dmouseInput();
|
||||
|
||||
class TInputData {
|
||||
public:
|
||||
TInputData() : fAxes(6) {}
|
||||
|
||||
bool IsZero() {
|
||||
return (0.0f == fAxes[0] && 0.0f == fAxes[1] && 0.0f == fAxes[2] &&
|
||||
0.0f == fAxes[3] && 0.0f == fAxes[4] && 0.0f == fAxes[5]);
|
||||
}
|
||||
|
||||
int fTimeToLive; // For telling if the device was unplugged while sending data
|
||||
bool fIsDirty;
|
||||
std::vector<float> fAxes;
|
||||
|
||||
};
|
||||
|
||||
HWND fWindow;
|
||||
|
||||
// Data cache to handle multiple rawinput devices
|
||||
std::map< HANDLE, TInputData> fDevice2Data;
|
||||
std::map< HANDLE, unsigned long> fDevice2Keystate;
|
||||
|
||||
// 3dmouse parameters
|
||||
MouseParameters f3dMouseParams; // Rotate, Pan Zoom etc.
|
||||
|
||||
// use to calculate distance traveled since last event
|
||||
DWORD fLast3dmouseInputTime;
|
||||
};
|
||||
|
||||
// the osx connexion api
|
||||
#else
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include "../../../interface/external/3dconnexionclient/include/ConnexionClientAPI.h"
|
||||
|
||||
class SpacemouseManager : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static SpacemouseManager& getInstance();
|
||||
void init();
|
||||
void destroy();
|
||||
bool Is3dmouseAttached();
|
||||
public slots:
|
||||
void toggleSpacemouse(bool shouldEnable);
|
||||
};
|
||||
|
||||
#endif // __APPLE__
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// connnects to the userinputmapper
|
||||
class SpacemouseDevice : public QObject, public controller::InputDevice {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//static SpacemouseDevice& getInstance();
|
||||
SpacemouseDevice();
|
||||
enum PositionChannel {
|
||||
TRANSLATE_X,
|
||||
TRANSLATE_Y,
|
||||
TRANSLATE_Z,
|
||||
ROTATE_X,
|
||||
ROTATE_Y,
|
||||
ROTATE_Z,
|
||||
};
|
||||
|
||||
enum ButtonChannel {
|
||||
BUTTON_1 = 1,
|
||||
BUTTON_2 = 2,
|
||||
BUTTON_3 = 3
|
||||
};
|
||||
|
||||
typedef std::unordered_set<int> ButtonPressedMap;
|
||||
typedef std::map<int, float> AxisStateMap;
|
||||
|
||||
float getButton(int channel) const;
|
||||
float getAxis(int channel) const;
|
||||
|
||||
controller::Input makeInput(SpacemouseDevice::PositionChannel axis) const;
|
||||
controller::Input makeInput(SpacemouseDevice::ButtonChannel button) const;
|
||||
|
||||
controller::Input::NamedPair makePair(SpacemouseDevice::PositionChannel axis, const QString& name) const;
|
||||
controller::Input::NamedPair makePair(SpacemouseDevice::ButtonChannel button, const QString& name) const;
|
||||
|
||||
virtual controller::Input::NamedVector getAvailableInputs() const override;
|
||||
virtual QString getDefaultMappingConfig() const override;
|
||||
virtual void update(float deltaTime, bool jointsCaptured) override;
|
||||
virtual void focusOutEvent() override;
|
||||
|
||||
glm::vec3 cc_position;
|
||||
glm::vec3 cc_rotation;
|
||||
int clientId;
|
||||
|
||||
void setButton(int lastButtonState);
|
||||
void handleAxisEvent();
|
||||
};
|
||||
|
||||
#endif // defined(hifi_SpacemouseManager_h)
|
Loading…
Reference in a new issue