mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
ENABLE_3DCONNEXION_DEVICES - 1st installment of support for 3Dconnexion devices
Implemented using hidapi library (https://github.com/libusb/hidapi) and https://github.com/koenieee/CrossplatformSpacemouseDriver/tree/master/SpaceMouseDriver as reference Unsolved issues: - When manipulating the SpaceNavigator wxWidgets generates a mouse wheel event that needs to be filtered out - wxWidgets does not detect devices being connected/disconnected to the pc - Current state forces a continuous rendering - Current state misses dependence on camera zoom - Non intuitive movement limits - Translation and rotation speed factors are hardcoded - Number of device buttons hardcoded
This commit is contained in:
parent
c1e3be9b27
commit
f958cfd2ff
14 changed files with 3805 additions and 1 deletions
96
src/slic3r/GUI/Mouse3DController.hpp
Normal file
96
src/slic3r/GUI/Mouse3DController.hpp
Normal file
|
@ -0,0 +1,96 @@
|
|||
#ifndef slic3r_Mouse3DController_hpp_
|
||||
#define slic3r_Mouse3DController_hpp_
|
||||
|
||||
#if ENABLE_3DCONNEXION_DEVICES
|
||||
|
||||
#include "hidapi/hidapi.h"
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
class GLCanvas3D;
|
||||
|
||||
class Mouse3DController
|
||||
{
|
||||
class State
|
||||
{
|
||||
static const double DefaultTranslationScale;
|
||||
static const float DefaultRotationScale;
|
||||
|
||||
mutable std::mutex m_mutex;
|
||||
|
||||
Vec3d m_translation;
|
||||
Vec3f m_rotation;
|
||||
std::vector<bool> m_buttons;
|
||||
|
||||
double m_translation_scale;
|
||||
float m_rotation_scale;
|
||||
|
||||
public:
|
||||
State();
|
||||
|
||||
void set_translation(const Vec3d& translation);
|
||||
void set_rotation(const Vec3f& rotation);
|
||||
void set_button(unsigned int id);
|
||||
|
||||
bool has_translation() const;
|
||||
bool has_rotation() const;
|
||||
bool has_any_button() const;
|
||||
|
||||
// return true if any change to the camera took place
|
||||
bool apply(GLCanvas3D& canvas);
|
||||
};
|
||||
|
||||
bool m_initialized;
|
||||
State m_state;
|
||||
std::thread m_thread;
|
||||
GLCanvas3D* m_canvas;
|
||||
std::mutex m_mutex;
|
||||
hid_device* m_device;
|
||||
bool m_running;
|
||||
|
||||
public:
|
||||
Mouse3DController();
|
||||
|
||||
void init();
|
||||
void shutdown();
|
||||
|
||||
bool is_device_connected() const { return m_device != nullptr; }
|
||||
bool is_running() const { return m_running; }
|
||||
|
||||
void set_canvas(GLCanvas3D* canvas)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_canvas = canvas;
|
||||
}
|
||||
|
||||
bool has_translation() const { return m_state.has_translation(); }
|
||||
bool has_rotation() const { return m_state.has_rotation(); }
|
||||
bool has_any_button() const { return m_state.has_any_button(); }
|
||||
|
||||
bool apply()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return (m_canvas != nullptr) ? m_state.apply(*m_canvas) : false;
|
||||
}
|
||||
|
||||
private:
|
||||
void connect_device();
|
||||
void disconnect_device();
|
||||
void start();
|
||||
void stop() { m_running = false; }
|
||||
|
||||
void run();
|
||||
void collect_input();
|
||||
};
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
||||
#endif // ENABLE_3DCONNEXION_DEVICES
|
||||
|
||||
#endif // slic3r_Mouse3DController_hpp_
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue