Compare commits

...

4 Commits

9 changed files with 64 additions and 60 deletions

View File

@ -15,6 +15,10 @@ using namespace godot;
UltraleapDevice::~UltraleapDevice() {
UtilityFunctions::print("Destroying device");
if (*connection == NULL) {
printf("Connection seems to be already destroyed\n");
return;
}
unsubscribe();
close();
}
@ -146,7 +150,7 @@ void UltraleapDevice::set_tracking_mode(UltraleapTypes::TrackingMode value) {
else {
UtilityFunctions::print("Invalid value for tracking mode");
}
LeapSetPolicyFlagsEx(connection, device, set_flag, clear_flag);
LeapSetPolicyFlagsEx(*connection, device, set_flag, clear_flag);
}
}
@ -159,7 +163,7 @@ void UltraleapDevice::subscribe() {
UtilityFunctions::print("Device already subscribed to");
return;
}
eLeapRS result = LeapSubscribeEvents(connection, device);
eLeapRS result = LeapSubscribeEvents(*connection, device);
if (result != eLeapRS_Success) {
UtilityFunctions::print(UltraleapTypes::ultraleap_result_to_string(result));
return;
@ -172,7 +176,7 @@ void UltraleapDevice::unsubscribe() {
UtilityFunctions::print("Device not subscribed to");
return;
}
eLeapRS result = LeapUnsubscribeEvents(connection, device);
eLeapRS result = LeapUnsubscribeEvents(*connection, device);
if (result != eLeapRS_Success) {
UtilityFunctions::print(UltraleapTypes::ultraleap_result_to_string(result));
return;
@ -258,12 +262,12 @@ Ref<UltraleapFrame> UltraleapDevice::get_interpolated_frame(int64_t time) {
uint64_t targetFrameSize = 0;
//Get the buffer size needed to hold the tracking data
eLeapRS result = LeapGetFrameSizeEx(connection, device, time, &targetFrameSize);
eLeapRS result = LeapGetFrameSizeEx(*connection, device, time, &targetFrameSize);
if (result == eLeapRS_Success) {
//Allocate enough memory
LEAP_TRACKING_EVENT* interpolatedFrame = (LEAP_TRACKING_EVENT*)malloc((size_t)targetFrameSize);
//Get the frame
result = LeapInterpolateFrameEx(connection, device, time, interpolatedFrame, targetFrameSize);
result = LeapInterpolateFrameEx(*connection, device, time, interpolatedFrame, targetFrameSize);
if (result == eLeapRS_Success) {
Ref<UltraleapFrame> new_frame = memnew(UltraleapFrame);
UltraleapFrame::fill_frame_data(new_frame, interpolatedFrame, rigging_transform);

View File

@ -64,7 +64,7 @@ public:
LEAP_DEVICE_REF device_ref;
LEAP_DEVICE device;
LEAP_CONNECTION connection;
LEAP_CONNECTION* connection;
LEAP_CLOCK_REBASER rebaser;
void tracking_mode_changed(UltraleapTypes::TrackingMode value);

View File

@ -127,11 +127,11 @@ void UltraleapDigit::_bind_methods() {
}
void UltraleapDigit::fill_digit_data(Ref<UltraleapDigit> ul_digit, LEAP_DIGIT* digit, FingerType type, Transform3D root, Transform3D rigging_transform) {
if (ul_digit->metacarpal_ref == NULL) {
ul_digit->metacarpal_ref = Ref<UltraleapBone>(memnew(UltraleapBone));
ul_digit->proximal_ref = Ref<UltraleapBone>(memnew(UltraleapBone));
ul_digit->intermediate_ref = Ref<UltraleapBone>(memnew(UltraleapBone));
ul_digit->distal_ref = Ref<UltraleapBone>(memnew(UltraleapBone));
if (ul_digit->metacarpal == NULL) {
ul_digit->metacarpal.instantiate();
ul_digit->proximal.instantiate();
ul_digit->intermediate.instantiate();
ul_digit->distal.instantiate();
}
ul_digit->is_extended = digit->is_extended == 1;
@ -139,16 +139,16 @@ void UltraleapDigit::fill_digit_data(Ref<UltraleapDigit> ul_digit, LEAP_DIGIT* d
// We need some extra logic here because the metacarpal doesn't exist in Ultraleap's hand data
if (type == UltraleapDigit::FingerType::Thumb) {
UltraleapBone::fill_bone_data(ul_digit->proximal_ref, root, &digit->proximal, UltraleapBone::BoneType::Proximal, rigging_transform);
UltraleapBone::fill_bone_data(ul_digit->proximal, root, &digit->proximal, UltraleapBone::BoneType::Proximal, rigging_transform);
// Still filling it out but shouldn't be used
UltraleapBone::fill_bone_data(ul_digit->metacarpal_ref, root, &digit->metacarpal, UltraleapBone::BoneType::Metacarpal, rigging_transform);
UltraleapBone::fill_bone_data(ul_digit->metacarpal, root, &digit->metacarpal, UltraleapBone::BoneType::Metacarpal, rigging_transform);
}
else {
UltraleapBone::fill_bone_data(ul_digit->metacarpal_ref, root, &digit->metacarpal, UltraleapBone::BoneType::Metacarpal, rigging_transform);
UltraleapBone::fill_bone_data(ul_digit->proximal_ref, ul_digit->metacarpal_ref, &digit->proximal, UltraleapBone::BoneType::Proximal, rigging_transform);
UltraleapBone::fill_bone_data(ul_digit->metacarpal, root, &digit->metacarpal, UltraleapBone::BoneType::Metacarpal, rigging_transform);
UltraleapBone::fill_bone_data(ul_digit->proximal, ul_digit->metacarpal, &digit->proximal, UltraleapBone::BoneType::Proximal, rigging_transform);
}
UltraleapBone::fill_bone_data(ul_digit->intermediate_ref, ul_digit->proximal_ref, &digit->intermediate, UltraleapBone::BoneType::Intermediate, rigging_transform);
UltraleapBone::fill_bone_data(ul_digit->distal_ref, ul_digit->intermediate_ref, &digit->distal, UltraleapBone::BoneType::Distal, rigging_transform);
UltraleapBone::fill_bone_data(ul_digit->intermediate, ul_digit->proximal, &digit->intermediate, UltraleapBone::BoneType::Intermediate, rigging_transform);
UltraleapBone::fill_bone_data(ul_digit->distal, ul_digit->intermediate, &digit->distal, UltraleapBone::BoneType::Distal, rigging_transform);
}

View File

@ -39,17 +39,17 @@ public:
FingerType get_type() { return type; }
void set_type(FingerType value) { type = value; }
Ref<UltraleapBone> get_metacarpal() { return metacarpal_ref; }
void set_metacarpal(Ref<UltraleapBone> value) { metacarpal_ref = value; }
Ref<UltraleapBone> get_metacarpal() { return metacarpal; }
void set_metacarpal(Ref<UltraleapBone> value) { metacarpal = value; }
Ref<UltraleapBone> get_proximal() { return proximal_ref; }
void set_proximal(Ref<UltraleapBone> value) { proximal_ref = value; }
Ref<UltraleapBone> get_proximal() { return proximal; }
void set_proximal(Ref<UltraleapBone> value) { proximal = value; }
Ref<UltraleapBone> get_intermediate() { return intermediate_ref; }
void set_intermediate(Ref<UltraleapBone> value) { intermediate_ref = value; }
Ref<UltraleapBone> get_intermediate() { return intermediate; }
void set_intermediate(Ref<UltraleapBone> value) { intermediate = value; }
Ref<UltraleapBone> get_distal() { return distal_ref; }
void set_distal(Ref<UltraleapBone> value) { distal_ref = value; }
Ref<UltraleapBone> get_distal() { return distal; }
void set_distal(Ref<UltraleapBone> value) { distal = value; }
bool get_is_extended() { return is_extended; }
void set_is_extended(bool value) { is_extended = value; }
@ -59,10 +59,10 @@ public:
bones = Array();
}
if (bones.size() == 0) {
bones.append(metacarpal_ref);
bones.append(proximal_ref);
bones.append(intermediate_ref);
bones.append(distal_ref);
bones.append(metacarpal);
bones.append(proximal);
bones.append(intermediate);
bones.append(distal);
}
return bones;
}
@ -72,10 +72,10 @@ protected:
static void _bind_methods();
private:
Ref<UltraleapBone> metacarpal_ref;
Ref<UltraleapBone> proximal_ref;
Ref<UltraleapBone> intermediate_ref;
Ref<UltraleapBone> distal_ref;
Ref<UltraleapBone> metacarpal;
Ref<UltraleapBone> proximal;
Ref<UltraleapBone> intermediate;
Ref<UltraleapBone> distal;
Array bones;
};

View File

@ -89,15 +89,15 @@ void UltraleapFrame::fill_frame_data(Ref<UltraleapFrame> ul_frame, const LEAP_TR
for (size_t i = 0; i < frame->nHands; i++)
{
if (frame->pHands[i].type == eLeapHandType_Left) {
if (ul_frame->get_left_hand() == NULL) {
ul_frame->set_left_hand(Ref<UltraleapHand>(memnew(UltraleapHand)));
if (!ul_frame->left_hand.is_valid()) {
ul_frame->left_hand.instantiate();
}
UltraleapHand::fill_hand_data(ul_frame->get_left_hand(), &frame->pHands[i], rigging_transform);
ul_frame->is_left_hand_visible = true;
}
else {
if (ul_frame->get_right_hand() == NULL) {
ul_frame->set_right_hand(Ref<UltraleapHand>(memnew(UltraleapHand)));
if (!ul_frame->right_hand.is_valid()) {
ul_frame->right_hand.instantiate();
}
UltraleapHand::fill_hand_data(ul_frame->get_right_hand(), &frame->pHands[i], rigging_transform);
ul_frame->is_right_hand_visible = true;

View File

@ -26,11 +26,11 @@ public:
float framerate;
Ref<UltraleapHand> get_left_hand() { return left_hand_ref; }
void set_left_hand(Ref<UltraleapHand> value) { left_hand_ref = value; }
Ref<UltraleapHand> get_left_hand() { return left_hand; }
void set_left_hand(Ref<UltraleapHand> value) { left_hand = value; }
Ref<UltraleapHand> get_right_hand() { return right_hand_ref; }
void set_right_hand(Ref<UltraleapHand> value) { right_hand_ref = value; }
Ref<UltraleapHand> get_right_hand() { return right_hand; }
void set_right_hand(Ref<UltraleapHand> value) { right_hand = value; }
bool get_is_left_hand_visible() { return is_left_hand_visible; }
void set_is_left_hand_visible(bool value) { is_left_hand_visible = value; }
@ -46,8 +46,8 @@ protected:
static void _bind_methods();
private:
Ref<UltraleapHand> left_hand_ref;
Ref<UltraleapHand> right_hand_ref;
Ref<UltraleapHand> left_hand;
Ref<UltraleapHand> right_hand;
};
#endif

View File

@ -240,14 +240,14 @@ void UltraleapHand::_bind_methods() {
void UltraleapHand::fill_hand_data(Ref<UltraleapHand> ul_hand, LEAP_HAND* hand, Transform3D rigging_transform) {
// For now we just check if the arm ref is not set
if (ul_hand->arm_ref == NULL) {
ul_hand->arm_ref = Ref<UltraleapBone>(memnew(UltraleapBone));
ul_hand->palm_ref = Ref<UltraleapPalm>(memnew(UltraleapPalm));
ul_hand->set_thumb(Ref<UltraleapDigit>(memnew(UltraleapDigit)));
ul_hand->set_index(Ref<UltraleapDigit>(memnew(UltraleapDigit)));
ul_hand->set_middle(Ref<UltraleapDigit>(memnew(UltraleapDigit)));
ul_hand->set_ring(Ref<UltraleapDigit>(memnew(UltraleapDigit)));
ul_hand->set_pinky(Ref<UltraleapDigit>(memnew(UltraleapDigit)));
if (ul_hand->arm == NULL) {
ul_hand->arm.instantiate();
ul_hand->palm.instantiate();
ul_hand->thumb.instantiate();
ul_hand->index.instantiate();
ul_hand->middle.instantiate();
ul_hand->ring.instantiate();
ul_hand->pinky.instantiate();
}
ul_hand->type = hand->type == eLeapHandType_Left ? UltraleapTypes::Chirality::Left : UltraleapTypes::Chirality::Right;
@ -258,7 +258,7 @@ void UltraleapHand::fill_hand_data(Ref<UltraleapHand> ul_hand, LEAP_HAND* hand,
ul_hand->grab_angle = hand->grab_angle;
ul_hand->grab_strength = hand->grab_strength;
UltraleapPalm::fill_palm_data(ul_hand->palm_ref, &hand->palm);
UltraleapPalm::fill_palm_data(ul_hand->palm, &hand->palm);
ul_hand->wrist = Transform3D(
Basis(UltraleapTypes::ultraleap_quaternion_to_godot_quaternion(&hand->palm.orientation)),
@ -271,5 +271,5 @@ void UltraleapHand::fill_hand_data(Ref<UltraleapHand> ul_hand, LEAP_HAND* hand,
UltraleapDigit::fill_digit_data(ul_hand->get_ring(), &hand->ring, UltraleapDigit::FingerType::Ring, ul_hand->wrist, rigging_transform);
UltraleapDigit::fill_digit_data(ul_hand->get_pinky(), &hand->pinky, UltraleapDigit::FingerType::Pinky, ul_hand->wrist, rigging_transform);
UltraleapBone::fill_bone_data(ul_hand->arm_ref, ul_hand->wrist, &hand->arm, UltraleapBone::BoneType::Arm, rigging_transform);
UltraleapBone::fill_bone_data(ul_hand->arm, ul_hand->wrist, &hand->arm, UltraleapBone::BoneType::Arm, rigging_transform);
}

View File

@ -69,11 +69,11 @@ public:
Ref<UltraleapDigit> get_pinky() { return pinky; }
void set_pinky(Ref<UltraleapDigit> value) { pinky = value; }
Ref<UltraleapBone> get_arm() { return arm_ref; }
void set_arm(Ref<UltraleapBone> value) { arm_ref = value; }
Ref<UltraleapBone> get_arm() { return arm; }
void set_arm(Ref<UltraleapBone> value) { arm = value; }
Ref<UltraleapPalm> get_palm() { return palm_ref; }
void set_palm(Ref<UltraleapPalm> value) { palm_ref = value; }
Ref<UltraleapPalm> get_palm() { return palm; }
void set_palm(Ref<UltraleapPalm> value) { palm = value; }
Array get_digits() {
if (digits_array == Variant::NIL) {
@ -97,8 +97,8 @@ protected:
static void _bind_methods();
private:
Ref<UltraleapBone> arm_ref;
Ref<UltraleapPalm> palm_ref;
Ref<UltraleapBone> arm;
Ref<UltraleapPalm> palm;
Array digits_array;
Ref<UltraleapDigit> thumb;

View File

@ -754,7 +754,7 @@ Ref<UltraleapDevice> UltraleapHandTracking::create_device(LEAP_DEVICE_REF ref) {
dev->id = ref.id;
dev->device_ref = ref;
dev->connection = connectionHandle;
dev->connection = &connectionHandle;
UtilityFunctions::print("Created device with ID: ", ref.id, ", type: ", deviceInfo.pid, ", serial number: ", deviceInfo.serial);