Skip to content

Commit

Permalink
add skeleton smoothing
Browse files Browse the repository at this point in the history
skeleton is now smoothed and extra thumb animation added
  • Loading branch information
mm0zct committed Aug 8, 2024
1 parent 4126c3b commit 503faec
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 18 deletions.
Binary file modified CustomHMD/.vs/CustomHMD/v16/.suo
Binary file not shown.
Binary file modified CustomHMD/.vs/CustomHMD/v16/Browse.VC.db
Binary file not shown.
10 changes: 7 additions & 3 deletions CustomHMD/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct config_data {
double world_translation[3];
vr::HmdQuaternion_t world_orientation_q;
double world_orientation_euler[3];
double skeleton_smoothing;
};

struct shared_buffer {
Expand All @@ -89,10 +90,13 @@ void log_to_buffer(std::string s) {
if (!comm_buffer) return;
WaitForSingleObject(comm_mutex, INFINITE);
for (int i = 0; i < s.size(); i++) {
comm_buffer->logging_buffer[comm_buffer->logging_offset + i] = s.c_str()[i];
if (comm_buffer->logging_offset < 1023) {
comm_buffer->logging_buffer[comm_buffer->logging_offset] = s.c_str()[i];
comm_buffer->logging_offset++;
}
}
comm_buffer->logging_buffer[comm_buffer->logging_offset + s.size()] = '\n';
comm_buffer->logging_offset += s.size() + 1;
comm_buffer->logging_buffer[comm_buffer->logging_offset] = '\n';
comm_buffer->logging_offset ++;
ReleaseMutex(comm_mutex);
return;
}
Expand Down
Binary file modified CustomHMD/Release/x64/driver_OculusTouchLink.dll
Binary file not shown.
33 changes: 23 additions & 10 deletions CustomHMD/TouchControllerDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ class CTouchControllerDriver : public vr::ITrackedDeviceServerDriver
vr::VRDriverInput()->UpdateBooleanComponent(m_compJoyt, inputState.Touches & ovrTouch_RThumb, 0);
#if DO_SKELETON

VRBoneTransform_t active_hand_pose[HSB_Count];
VRBoneTransform_t target_hand_pose[HSB_Count];
float hand_blend_fraction = inputState.HandTrigger[isRightHand];
float finger_bend_fraction = inputState.IndexTrigger[isRightHand];
if (!(inputState.Touches & ovrTouch_RThumbUp)) {
Expand All @@ -624,17 +624,22 @@ class CTouchControllerDriver : public vr::ITrackedDeviceServerDriver
}
}

for (int i = 0; i < HSB_Count; i++) active_hand_pose[i] = blend_bones(right_open_hand_pose[i], right_fist_pose[i], hand_blend_fraction);
for (int i = 0; i < HSB_Count; i++) target_hand_pose[i] = blend_bones(right_open_hand_pose[i], right_fist_pose[i], hand_blend_fraction);

for (int i = HSB_IndexFinger0; i <= HSB_IndexFinger4; i++) active_hand_pose[i] = blend_bones(right_open_hand_pose[i], right_fist_pose[i], finger_bend_fraction);
for (int i = HSB_IndexFinger0; i <= HSB_IndexFinger4; i++) target_hand_pose[i] = blend_bones(right_open_hand_pose[i], right_fist_pose[i], finger_bend_fraction);

if (finger_bend_fraction > hand_blend_fraction)
for (int i = HSB_Thumb0; i <= HSB_Thumb3; i++) active_hand_pose[i] = blend_bones(right_open_hand_pose[i], right_fist_pose[i], finger_bend_fraction);
for (int i = HSB_Thumb0; i <= HSB_Thumb3; i++) target_hand_pose[i] = blend_bones(right_open_hand_pose[i], right_fist_pose[i], finger_bend_fraction);

if (inputState.Touches & ovrTouch_RThumbUp)
{
for (int i = HSB_Thumb0; i <= HSB_Thumb3; i++) active_hand_pose[i] = right_open_hand_pose[i];
for (int i = HSB_Thumb0; i <= HSB_Thumb3; i++) target_hand_pose[i] = right_open_hand_pose[i];
}
else {
for (int i = HSB_Thumb0; i <= HSB_Thumb3; i++) target_hand_pose[i] = blend_bones(right_open_hand_pose[i], right_fist_pose[i], max(0.5, finger_bend_fraction));
}

for (int i = 0; i < HSB_Count; i++) active_hand_pose[i] = blend_bones(active_hand_pose[i], target_hand_pose[i], comm_buffer->config.skeleton_smoothing);
vr::VRDriverInput()->UpdateSkeletonComponent(
m_compSkel,
vr::VRSkeletalMotionRange_WithoutController,
Expand All @@ -661,7 +666,7 @@ class CTouchControllerDriver : public vr::ITrackedDeviceServerDriver

vr::VRDriverInput()->UpdateBooleanComponent(m_compSysc, inputState.Buttons & ovrButton_Enter, 0);
#if DO_LSKELETON
VRBoneTransform_t active_hand_pose[HSB_Count];
VRBoneTransform_t target_hand_pose[HSB_Count];

float hand_blend_fraction = inputState.HandTrigger[isRightHand];
float finger_bend_fraction = inputState.IndexTrigger[isRightHand];
Expand All @@ -672,17 +677,23 @@ class CTouchControllerDriver : public vr::ITrackedDeviceServerDriver
}
}

for (int i = 0; i < HSB_Count; i++) active_hand_pose[i] = blend_bones(left_open_hand_pose[i], left_fist_pose[i], hand_blend_fraction);
for (int i = 0; i < HSB_Count; i++) target_hand_pose[i] = blend_bones(left_open_hand_pose[i], left_fist_pose[i], hand_blend_fraction);

for (int i = HSB_IndexFinger0; i <= HSB_IndexFinger4; i++) active_hand_pose[i] = blend_bones(left_open_hand_pose[i], left_fist_pose[i], finger_bend_fraction);
for (int i = HSB_IndexFinger0; i <= HSB_IndexFinger4; i++) target_hand_pose[i] = blend_bones(left_open_hand_pose[i], left_fist_pose[i], finger_bend_fraction);

if (finger_bend_fraction > hand_blend_fraction)
for (int i = HSB_Thumb0; i <= HSB_Thumb3; i++) active_hand_pose[i] = blend_bones(left_open_hand_pose[i], left_fist_pose[i], finger_bend_fraction);
for (int i = HSB_Thumb0; i <= HSB_Thumb3; i++) target_hand_pose[i] = blend_bones(left_open_hand_pose[i], left_fist_pose[i], finger_bend_fraction);

if (inputState.Touches & ovrTouch_LThumbUp)
{
for (int i = HSB_Thumb0; i <= HSB_Thumb3; i++) active_hand_pose[i] = left_open_hand_pose[i];
for (int i = HSB_Thumb0; i <= HSB_Thumb3; i++) target_hand_pose[i] = left_open_hand_pose[i];
}
else {
for (int i = HSB_Thumb0; i <= HSB_Thumb3; i++) target_hand_pose[i] = blend_bones(left_open_hand_pose[i], left_fist_pose[i], max(0.5, finger_bend_fraction));
}

for (int i = 0; i < HSB_Count; i++) active_hand_pose[i] = blend_bones(active_hand_pose[i], target_hand_pose[i], comm_buffer->config.skeleton_smoothing);

vr::VRDriverInput()->UpdateSkeletonComponent(
m_compSkel,
vr::VRSkeletalMotionRange_WithoutController,
Expand Down Expand Up @@ -819,6 +830,8 @@ class CTouchControllerDriver : public vr::ITrackedDeviceServerDriver
float m_time_of_last_pose;


VRBoneTransform_t active_hand_pose[HSB_Count];

/*std::chrono::time_point<std::chrono::steady_clock> haptic_end;
float haptic_strength;
float haptic_frequency; */
Expand Down
Binary file modified ReleasePackage/OculusTouchLink.7z
Binary file not shown.
Binary file modified ReleasePackage/OculusTouchLink/bin/win64/driver_OculusTouchLink.dll
Binary file not shown.
1 change: 1 addition & 0 deletions ReleasePackage/OculusTouchLink/config.dat
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ Oculus_link
0
0
0
0.2
Binary file modified ReleasePackage/OculusTouchLink/ovr_test.exe
Binary file not shown.
Binary file modified ovr_test/.vs/ovr_test/v16/.suo
Binary file not shown.
Binary file modified ovr_test/.vs/ovr_test/v16/Browse.VC.db
Binary file not shown.
1 change: 1 addition & 0 deletions ovr_test/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct config_data {
double world_translation[3];
vr::HmdQuaternion_t world_orientation_q;
double world_orientation_euler[3];
double skeleton_smoothing;
};

struct shared_buffer {
Expand Down
38 changes: 35 additions & 3 deletions ovr_test/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define _USE_MATH_DEFINES
#include <math.h>

#define DEBUG_VIB 1
//#define DEBUG_VIB 1

class unique_window_id {
public:
Expand Down Expand Up @@ -513,12 +513,44 @@ std::vector<config_window_object> config_windows = {
SetWindowText((HWND)self->wnd, CompBuffer);
return;
} }
, { L"Reset",L"BUTTON", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_FLAT | BS_TEXT ,

, { L"skeleton smoothing",L"EDIT", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_FLAT | BS_TEXT | ES_READONLY,
default_wm_command, default_init }
, { L"0.2",L"EDIT", WS_VISIBLE | WS_CHILD | ES_NUMBER,
[](HWND window, WPARAM wp, LPARAM lp, shared_buffer* comm_buffer) {
switch (HIWORD(wp))
{
case EN_CHANGE:
{
const size_t len = 64;
WCHAR Buffer[len];
double smoothing;
GetWindowText((HWND)lp, Buffer, len);
swscanf_s(Buffer, L"%lf", &smoothing);
std::wcout << L"control text is: " << Buffer << std::endl;
std::cout << "parsed smoothing " << smoothing << std::endl;

comm_buffer->config.skeleton_smoothing = smoothing;
}
}
return;
}, [](config_window_object* self, HWND parent, shared_buffer* comm_buffer) {
self->parent = parent;
orient_q_wp = self;
const size_t len = 64;
WCHAR CompBuffer[len];
swprintf_s(CompBuffer, len, L"%.2lf", comm_buffer->config.skeleton_smoothing);
SetWindowText((HWND)self->wnd, CompBuffer);
return;
} }

, { L"Reset",L"BUTTON", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_FLAT | BS_TEXT ,
[](HWND window, WPARAM wp, LPARAM lp, shared_buffer* comm_buffer) {
reset_config_settings(comm_buffer->config);
GUI_Manager::self->reset_settings_window();
return;
}, default_init }

#ifdef DEBUG_VIB
, { L"frequency amplitude duration",L"EDIT", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_FLAT | BS_TEXT | ES_READONLY,
default_wm_command, default_init }
Expand Down Expand Up @@ -580,7 +612,7 @@ GUI_Manager::GUI_Manager(shared_buffer* comm_buffer)
{
window = CreateWindowEx(0, L"MyWindowsApp", L"OculusTouchlink Configuration",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
600, 630, 0, 0, GetModuleHandle(0), 0);
600, 650, 0, 0, GetModuleHandle(0), 0);

}

Expand Down
5 changes: 4 additions & 1 deletion ovr_test/ovr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void main_loop(ovrSession mSession, HANDLE comm_mutex, shared_buffer* comm_buffe

WaitForSingleObject(comm_mutex, INFINITE);
if (comm_buffer->logging_offset) {
for (int i = 0; i < comm_buffer->logging_offset; i++) {
for (int i = 0; ((i < 1024) && (i < comm_buffer->logging_offset)); i++) {
putc(comm_buffer->logging_buffer[i], stdout);
}
comm_buffer->logging_offset = 0;
Expand Down Expand Up @@ -263,6 +263,7 @@ void reset_config_settings(config_data& config) {
config.world_orientation_euler[0] = 0.0;
config.world_orientation_euler[1] = 0.0;
config.world_orientation_euler[2] = 0.0;
config.skeleton_smoothing = 0.2;
}

void save_config_to_file(config_data& config) {
Expand Down Expand Up @@ -308,6 +309,7 @@ void save_config_to_file(config_data& config) {
ofs << config.world_orientation_euler[1] << std::endl;
ofs << config.world_orientation_euler[2] << std::endl;
ofs << config.disable_controllers << std::endl;
ofs << config.skeleton_smoothing << std::endl;
ofs.close();
}

Expand Down Expand Up @@ -359,6 +361,7 @@ void load_config_from_file(config_data& config) {
ifs >> config.world_orientation_euler[2];

ifs >> config.disable_controllers;
ifs >> config.skeleton_smoothing;
ifs.close();
}
}
Expand Down
3 changes: 2 additions & 1 deletion ovr_test/x64/Release/config.dat
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Oculus_link
0
0
0
-0.003
0
0
1
0
Expand All @@ -23,3 +23,4 @@ Oculus_link
0
0
0
0.2
Binary file modified ovr_test/x64/Release/ovr_test.exe
Binary file not shown.

0 comments on commit 503faec

Please sign in to comment.