154 lines
4.5 KiB
C++
154 lines
4.5 KiB
C++
#ifndef ULTRALEAP_H
|
|
#define ULTRALEAP_H
|
|
|
|
#include <godot_cpp/classes/node3d.hpp>
|
|
#include <godot_cpp/classes/global_constants.hpp>
|
|
#include <godot_cpp/classes/viewport.hpp>
|
|
#include <godot_cpp/variant/vector3.hpp>
|
|
#include <godot_cpp/variant/quaternion.hpp>
|
|
#include <godot_cpp/variant/string.hpp>
|
|
|
|
#include <godot_cpp/core/binder_common.hpp>
|
|
|
|
#include <LeapC.h>
|
|
#include <thread>
|
|
#include <queue>
|
|
#include <atomic>
|
|
|
|
#include "types.h"
|
|
#include "frame.h"
|
|
#include "image.h"
|
|
#include "device.h"
|
|
#include "device_list.h"
|
|
|
|
using namespace godot;
|
|
|
|
class UltraleapHandTracking : public Node3D {
|
|
GDCLASS(UltraleapHandTracking, Node3D);
|
|
|
|
public:
|
|
~UltraleapHandTracking();
|
|
|
|
void start();
|
|
void stop();
|
|
|
|
UltraleapTypes::TrackingMode default_tracking_mode = UltraleapTypes::TrackingMode::Desktop;
|
|
|
|
bool interpolate = true;
|
|
|
|
bool get_interpolate();
|
|
void set_interpolate(bool value);
|
|
|
|
UltraleapDeviceList* devices = memnew(UltraleapDeviceList);
|
|
|
|
Ref<UltraleapFrame> last_frame_ref = Ref<UltraleapFrame>(memnew(UltraleapFrame));
|
|
Ref<UltraleapImage> left_image_ref = Ref<UltraleapImage>(memnew(UltraleapImage));
|
|
Ref<UltraleapImage> right_image_ref = Ref<UltraleapImage>(memnew(UltraleapImage));
|
|
|
|
String service_ip = String("127.0.0.1");
|
|
uint32_t service_port = 12345;
|
|
|
|
bool autostart = true;
|
|
bool enable_images = true;
|
|
|
|
Variant get_last_frame();
|
|
void set_last_frame(Variant value) { return; }
|
|
|
|
UltraleapTypes::TrackingMode get_tracking_mode();
|
|
void set_tracking_mode(UltraleapTypes::TrackingMode value);
|
|
|
|
Variant get_left_image();
|
|
Variant get_right_image();
|
|
|
|
Array get_devices() { return devices->devices; }
|
|
void set_devices(Array value) { devices->devices = value; }
|
|
|
|
Variant get_service_ip() { return service_ip; }
|
|
void set_service_ip(Variant value) { service_ip = value; }
|
|
|
|
Variant get_service_port() { return service_port; }
|
|
void set_service_port(Variant value) { service_port = value; }
|
|
|
|
Variant get_autostart() { return autostart; }
|
|
void set_autostart(Variant value) { autostart = value; }
|
|
|
|
Variant get_enable_images() { return enable_images; }
|
|
void set_enable_images(Variant value) { enable_images = value; }
|
|
|
|
bool is_connected() { return connected; }
|
|
bool is_started() { return started; }
|
|
|
|
// Policy setters
|
|
void set_images_policy(bool value);
|
|
void set_background_frames_policy(bool value);
|
|
void set_map_points_policy(bool value);
|
|
void set_allow_pause_resume_policy(bool value);
|
|
|
|
// Policy getters
|
|
// Only reimplementing the things we know do something
|
|
bool get_images_policy();
|
|
|
|
// Set and get primary device
|
|
void set_primary_device(Ref<UltraleapDevice> device);
|
|
Variant get_primary_device();
|
|
|
|
void set_pause(bool value);
|
|
|
|
void _notification(int p_what);
|
|
|
|
protected:
|
|
static void _bind_methods();
|
|
|
|
private:
|
|
bool _isRunning = false;
|
|
|
|
std::atomic<bool> is_running = false;
|
|
std::atomic<bool> keep_running = false;
|
|
|
|
LEAP_CONNECTION connectionHandle = NULL;
|
|
LEAP_CLOCK_REBASER clockSynchronizer;
|
|
|
|
std::thread messageLoop;
|
|
|
|
bool started = false; /* The whole thing is started */
|
|
bool opened = false; /* Indicate an opened connection */
|
|
bool connected = false; /* We have confirmed connection */
|
|
|
|
Ref<UltraleapDevice> primary_device = NULL;
|
|
|
|
typedef struct {
|
|
StringName signal;
|
|
Variant arg;
|
|
} event;
|
|
std::queue<event> events;
|
|
|
|
void serviceMessageLoop();
|
|
void dispose_ultraleap();
|
|
|
|
void handle_tracking_event(const LEAP_TRACKING_EVENT* event, uint32_t device_id);
|
|
void handle_image_event(const LEAP_IMAGE_EVENT* event, uint32_t device_id);
|
|
void handle_connection_event(const LEAP_CONNECTION_EVENT *evt);
|
|
void handle_connection_lost_event(const LEAP_CONNECTION_LOST_EVENT* event);
|
|
void handle_device_event(const LEAP_DEVICE_EVENT* event);
|
|
void handle_device_lost_event(const LEAP_DEVICE_EVENT* event);
|
|
void handle_tracking_mode_event(const LEAP_TRACKING_MODE_EVENT* event, uint32_t device_id);
|
|
void handle_policy_change_event(const LEAP_POLICY_EVENT* event);
|
|
void handle_device_status_change_event(const LEAP_DEVICE_STATUS_CHANGE_EVENT* event, uint32_t device_id);
|
|
|
|
void set_policy(UltraleapTypes::PolicyFlag flag, bool value);
|
|
bool get_policy(UltraleapTypes::PolicyFlag flag);
|
|
|
|
String generate_connection_payload();
|
|
|
|
void refresh_device_list();
|
|
|
|
Ref<UltraleapDevice> create_device(LEAP_DEVICE_REF ref);
|
|
|
|
uint32_t policy_flags = UINT32_MAX;
|
|
|
|
#ifdef ANDROID_ENABLED
|
|
Object *binder = NULL;
|
|
#endif
|
|
};
|
|
|
|
#endif |