Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
Updated for Amethyst API (K2API) v10
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Jun 17, 2022
1 parent 115f0cc commit d5fc1f0
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 59 deletions.
9 changes: 5 additions & 4 deletions DEVICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ for the app to be accessed by calling `getJointName()` before adding it the join
When a device reports itself as a spectator, it states that it won't be providing any tracking.<br>
Spectator devices, and generally all device types can poll tracking data from the host (`Amethyst`).<br>
There are several helper functions to make that easier:
- [`getHMDPosition()`](https://github.com/KinectToVR/K2TrackingDevice-Samples/blob/main/external/vendor/Amethyst_API_Devices.h#L428) - grab the VR Headset position (in meters, xyz)
- [`getHMDOrientation()`](https://github.com/KinectToVR/K2TrackingDevice-Samples/blob/main/external/vendor/Amethyst_API_Devices.h#L429) - get the VR Headset orientation (quaternion)
- [`getHMDOrientationYaw()`](https://github.com/KinectToVR/K2TrackingDevice-Samples/blob/main/external/vendor/Amethyst_API_Devices.h#L430) - get VR Headset's extracted orientation yaw (in radians, +y)
- [`getAppJointPoses()`](https://github.com/KinectToVR/K2TrackingDevice-Samples/blob/main/external/vendor/Amethyst_API_Devices.h#L438) - the most useful one, returns an array of joints from `Amethyst`,<br>
- [`getHMDPose()`](https://github.com/KinectToVR/K2TrackingDevice-Samples/blob/main/external/vendor/Amethyst_API_Devices.h#L725) - grab the VR Headset pose (position in meters and orientation as a quaternion)
Access pos via `.first` and ori via `.second`. The `Calibrated` variant makes use of your room setup.
- [`getHMDOrientationYaw()`](https://github.com/KinectToVR/K2TrackingDevice-Samples/blob/main/external/vendor/Amethyst_API_Devices.h#L740) - get VR Headset's extracted orientation yaw (in radians, +y)
The `Calibrated` variant makes use of your room setup, so it's generally better to use it.
- [`getAppJointPoses()`](https://github.com/KinectToVR/K2TrackingDevice-Samples/blob/main/external/vendor/Amethyst_API_Devices.h#L750) - the most useful one, returns an array of joints from `Amethyst`,<br>
with their final (composed) names, roles, positions & orientations and states.
<br>
<br>
Expand Down
4 changes: 2 additions & 2 deletions device_JointsBasis/DeviceHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ void DeviceHandler::update()
// and the user's head orientation

trackedJoints.at(0).update(
getHMDPosition() + Eigen::Vector3f(0, 0, 1),
getHMDOrientation(),
getHMDPose().first + Eigen::Vector3f(0, 0, 1),
getHMDPose().second,
ktvr::State_Tracked);

// Mark that we see the user
Expand Down
4 changes: 2 additions & 2 deletions device_KinectBasis_Basic/DeviceHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ void DeviceHandler::update()
// which are [ head, waist, ankles ]
// (But the sample updates all)

jointPositions[i] = getHMDPosition() + Eigen::Vector3f(i, 0, 1);
jointOrientations[i] = getHMDOrientation();
jointPositions[i] = getHMDPose().first + Eigen::Vector3f(i, 0, 1);
jointOrientations[i] = getHMDPose().second;

trackingStates[i] = ktvr::State_Tracked;
}
Expand Down
4 changes: 2 additions & 2 deletions device_KinectBasis_Full/DeviceHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ void DeviceHandler::update()

for (uint32_t i = 0; i < ktvr::Joint_Total; i++)
{
jointPositions[i] = getHMDPosition() + Eigen::Vector3f(i, 0, 1);
jointOrientations[i] = getHMDOrientation();
jointPositions[i] = getHMDPose().first + Eigen::Vector3f(i, 0, 1);
jointOrientations[i] = getHMDPose().second;

trackingStates[i] = ktvr::State_Tracked;
}
Expand Down
4 changes: 2 additions & 2 deletions device_KinectBasis_Full_Settings/DeviceHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ void DeviceHandler::update()

for (uint32_t i = 0; i < ktvr::Joint_Total; i++)
{
jointPositions[i] = getHMDPosition() + Eigen::Vector3f(i, 0, 1);
jointOrientations[i] = getHMDOrientation();
jointPositions[i] = getHMDPose().first + Eigen::Vector3f(i, 0, 1);
jointOrientations[i] = getHMDPose().second;

trackingStates[i] = ktvr::State_Tracked;
}
Expand Down
4 changes: 2 additions & 2 deletions device_KinectBasis_Simple/DeviceHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ void DeviceHandler::update()
// which are [ head, elbows, waist, knees, ankles, foot_tips ]
// (But the sample updates all)

jointPositions[i] = getHMDPosition() + Eigen::Vector3f(i, 0, 1);
jointOrientations[i] = getHMDOrientation();
jointPositions[i] = getHMDPose().first + Eigen::Vector3f(i, 0, 1);
jointOrientations[i] = getHMDPose().second;

trackingStates[i] = ktvr::State_Tracked;
}
Expand Down
132 changes: 87 additions & 45 deletions external/vendor/Amethyst_API_Devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ inline std::string WStringToString(const std::wstring& s)

namespace ktvr
{
// Interace Version
static const char* IK2API_Devices_Version = "IK2API_Version_009";
// Interface Version
static const char* IK2API_Devices_Version = "IK2API_Version_010";

// Return messaging types
enum K2InitErrorType
Expand Down Expand Up @@ -131,7 +131,7 @@ namespace ktvr

Eigen::Vector3f getJointPosition() { return jointPosition; }
Eigen::Quaternionf getJointOrientation() { return jointOrientation; }
JointTrackingState getTrackingState() { return trackingState; }
JointTrackingState getTrackingState() { return trackingState; } // ITrackedJointState

// For servers!
void update(Eigen::Vector3f position,
Expand Down Expand Up @@ -720,20 +720,34 @@ namespace ktvr
[[nodiscard]] bool isAppOrientationSupported() const { return appOrientationSupported; } // Math-based

/* Helper functions which may be internally called by the device plugin */
Eigen::Vector3f (*getHMDPosition)(); // Get the HMD Position
Eigen::Vector3f (*getHMDPositionCalibrated)(); // Get the HMD Position, calibrated
Eigen::Quaternionf (*getHMDOrientation)(); // Get the HMD Rotation
Eigen::Quaternionf (*getHMDOrientationCalibrated)(); // Get the HMD Rotation, calibrated
float (*getHMDOrientationYaw)(); // Get the HMD Yaw, exclusively
float (*getHMDOrientationYawCalibrated)(); // Get the HMD Yaw, exclusively & calibrated

// Get the raw openvr's HMD pose
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getHMDPose;
// Get the openvr's HMD pose, but un-wrapped aka "calibrated" using the vr room center
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getHMDPoseCalibrated;

// Get the raw openvr's left controller pose
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getLeftControllerPose;
// Get the openvr's left controller pose, but un-wrapped aka "calibrated" using the vr room center
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getLeftControllerPoseCalibrated;

// Get the raw openvr's right controller pose
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getRightControllerPose;
// Get the openvr's right controller pose, but un-wrapped aka "calibrated" using the vr room center
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getRightControllerPoseCalibrated;

// Get the HMD Yaw (exclusively)
std::function<float()> getHMDOrientationYaw;
// Get the HMD Yaw (exclusively), but un-wrapped aka "calibrated" using the vr room center
std::function<float()> getHMDOrientationYawCalibrated;

/*
* Helper to get all joints' positions from the app,
* which are sent to the openvr server driver.
* Note: if joint's unused, its trackingState will be 0
* Note: if joint's unused, its trackingState will be ITrackedJointState::State_NotTracked
* Note: Waist,LFoot,RFoot,LElbow,RElbow,LKnee,RKnee
*/
std::array<K2TrackedJoint, 7> (*getAppJointPoses)();
std::function<std::array<K2TrackedJoint, 7>()> getAppJointPoses;

// To support settings daemon and register the layout root,
// the device must properly report it first
Expand All @@ -750,31 +764,31 @@ namespace ktvr
Interface::LayoutRoot* layoutRoot;

// Create a text block
Interface::TextBlock* (*CreateTextBlock)(const std::wstring& text);
std::function<Interface::TextBlock* (const std::wstring& text)> CreateTextBlock;

// Create a labeled button
Interface::Button* (*CreateButton)(const std::wstring& content);
std::function<Interface::Button* (const std::wstring& content)> CreateButton;

// Create a number box
Interface::NumberBox* (*CreateNumberBox)(const int& value);
std::function<Interface::NumberBox* (const int& value)> CreateNumberBox;

// Create a combo box
Interface::ComboBox* (*CreateComboBox)(const std::vector<std::wstring>& entries);
std::function<Interface::ComboBox* (const std::vector<std::wstring>& entries)> CreateComboBox;

// Create a check box
Interface::CheckBox* (*CreateCheckBox)();
std::function<Interface::CheckBox* ()> CreateCheckBox;

// Create a toggle switch
Interface::ToggleSwitch* (*CreateToggleSwitch)();
std::function<Interface::ToggleSwitch* ()> CreateToggleSwitch;

// Create a text box
Interface::TextBox* (*CreateTextBox)();
std::function<Interface::TextBox* ()> CreateTextBox;

// Create a progress ring
Interface::ProgressRing* (*CreateProgressRing)();
std::function<Interface::ProgressRing* ()> CreateProgressRing;

// Create a progress bar
Interface::ProgressBar* (*CreateProgressBar)();
std::function<Interface::ProgressBar* ()> CreateProgressBar;

protected:
K2DeviceCharacteristics deviceCharacteristics = K2_Character_Unknown;
Expand Down Expand Up @@ -918,20 +932,34 @@ namespace ktvr
[[nodiscard]] bool isSkeletonTracked() const { return skeletonTracked; }

/* Helper functions which may be internally called by the device plugin */
Eigen::Vector3f (*getHMDPosition)(); // Get the HMD Position
Eigen::Vector3f (*getHMDPositionCalibrated)(); // Get the HMD Position, calibrated
Eigen::Quaternionf (*getHMDOrientation)(); // Get the HMD Rotation
Eigen::Quaternionf (*getHMDOrientationCalibrated)(); // Get the HMD Rotation, calibrated
float (*getHMDOrientationYaw)(); // Get the HMD Yaw, exclusively
float (*getHMDOrientationYawCalibrated)(); // Get the HMD Yaw, exclusively & calibrated

// Get the raw openvr's HMD pose
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getHMDPose;
// Get the openvr's HMD pose, but un-wrapped aka "calibrated" using the vr room center
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getHMDPoseCalibrated;

// Get the raw openvr's left controller pose
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getLeftControllerPose;
// Get the openvr's left controller pose, but un-wrapped aka "calibrated" using the vr room center
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getLeftControllerPoseCalibrated;

// Get the raw openvr's right controller pose
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getRightControllerPose;
// Get the openvr's right controller pose, but un-wrapped aka "calibrated" using the vr room center
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getRightControllerPoseCalibrated;

// Get the HMD Yaw (exclusively)
std::function<float()> getHMDOrientationYaw;
// Get the HMD Yaw (exclusively), but un-wrapped aka "calibrated" using the vr room center
std::function<float()> getHMDOrientationYawCalibrated;

/*
* Helper to get all joints' positions from the app,
* which are sent to the openvr server driver.
* Note: if joint's unused, its trackingState will be 0
* Note: if joint's unused, its trackingState will be ITrackedJointState::State_NotTracked
* Note: Waist,LFoot,RFoot,LElbow,RElbow,LKnee,RKnee
*/
std::array<K2TrackedJoint, 7> (*getAppJointPoses)();
std::function<std::array<K2TrackedJoint, 7>()> getAppJointPoses;

// To support settings daemon and register the layout root,
// the device must properly report it first
Expand All @@ -948,31 +976,31 @@ namespace ktvr
Interface::LayoutRoot* layoutRoot;

// Create a text block
Interface::TextBlock* (*CreateTextBlock)(const std::wstring& text);
std::function<Interface::TextBlock* (const std::wstring& text)> CreateTextBlock;

// Create a labeled button
Interface::Button* (*CreateButton)(const std::wstring& content);
std::function<Interface::Button* (const std::wstring& content)> CreateButton;

// Create a number box
Interface::NumberBox* (*CreateNumberBox)(const int& value);
std::function<Interface::NumberBox* (const int& value)> CreateNumberBox;

// Create a combo box
Interface::ComboBox* (*CreateComboBox)(const std::vector<std::wstring>& entries);
std::function<Interface::ComboBox* (const std::vector<std::wstring>& entries)> CreateComboBox;

// Create a check box
Interface::CheckBox* (*CreateCheckBox)();
std::function<Interface::CheckBox* ()> CreateCheckBox;

// Create a toggle switch
Interface::ToggleSwitch* (*CreateToggleSwitch)();
std::function<Interface::ToggleSwitch* ()> CreateToggleSwitch;

// Create a text box
Interface::TextBox* (*CreateTextBox)();
std::function<Interface::TextBox* ()> CreateTextBox;

// Create a progress ring
Interface::ProgressRing* (*CreateProgressRing)();
std::function<Interface::ProgressRing* ()> CreateProgressRing;

// Create a progress bar
Interface::ProgressBar* (*CreateProgressBar)();
std::function<Interface::ProgressBar* ()> CreateProgressBar;

protected:
K2DeviceType deviceType = K2_Unknown;
Expand Down Expand Up @@ -1010,19 +1038,33 @@ namespace ktvr
}

/* Helper functions which may be internally called by the device plugin */
Eigen::Vector3f (*getHMDPosition)(); // Get the HMD Position
Eigen::Vector3f (*getHMDPositionCalibrated)(); // Get the HMD Position, calibrated
Eigen::Quaternionf (*getHMDOrientation)(); // Get the HMD Rotation
Eigen::Quaternionf (*getHMDOrientationCalibrated)(); // Get the HMD Rotation, calibrated
float (*getHMDOrientationYaw)(); // Get the HMD Yaw, exclusively
float (*getHMDOrientationYawCalibrated)(); // Get the HMD Yaw, exclusively & calibrated

// Get the raw openvr's HMD pose
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getHMDPose;
// Get the openvr's HMD pose, but un-wrapped aka "calibrated" using the vr room center
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getHMDPoseCalibrated;

// Get the raw openvr's left controller pose
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getLeftControllerPose;
// Get the openvr's left controller pose, but un-wrapped aka "calibrated" using the vr room center
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getLeftControllerPoseCalibrated;

// Get the raw openvr's right controller pose
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getRightControllerPose;
// Get the openvr's right controller pose, but un-wrapped aka "calibrated" using the vr room center
std::function<std::pair<Eigen::Vector3f, Eigen::Quaternionf>()> getRightControllerPoseCalibrated;

// Get the HMD Yaw (exclusively)
std::function<float()> getHMDOrientationYaw;
// Get the HMD Yaw (exclusively), but un-wrapped aka "calibrated" using the vr room center
std::function<float()> getHMDOrientationYawCalibrated;

/*
* Helper to get all joints' positions from the app,
* which are sent to the openvr server driver.
* Note: if joint's unused, its trackingState will be 0
* Note: if joint's unused, its trackingState will be ITrackedJointState::State_NotTracked
* Note: Waist,LFoot,RFoot,LElbow,RElbow,LKnee,RKnee
*/
std::array<K2TrackedJoint, 7> (*getAppJointPoses)();
std::function<std::array<K2TrackedJoint, 7>()> getAppJointPoses;
};
}

0 comments on commit d5fc1f0

Please sign in to comment.