mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-06 03:39:23 +00:00
Custom event classes for patched methods
Update to LeapCSharp 6.15.0
This commit is contained in:
parent
4b879d53d5
commit
85925a7072
76 changed files with 3443 additions and 2187 deletions
127
ml_lme/vendor/LeapCSharp/Device.cs
vendored
127
ml_lme/vendor/LeapCSharp/Device.cs
vendored
|
@ -255,67 +255,78 @@ namespace Leap
|
|||
return devicePose;
|
||||
}
|
||||
|
||||
bool deviceTransformAvailable = LeapC.GetDeviceTransformAvailable(Handle);
|
||||
|
||||
if (!deviceTransformAvailable)
|
||||
{
|
||||
devicePose = Pose.identity;
|
||||
poseSet = true;
|
||||
return Pose.identity;
|
||||
}
|
||||
|
||||
float[] data = new float[16];
|
||||
eLeapRS result = LeapC.GetDeviceTransform(Handle, data);
|
||||
|
||||
if (result != eLeapRS.eLeapRS_Success || data == null)
|
||||
{
|
||||
devicePose = Pose.identity;
|
||||
poseSet = true;
|
||||
return Pose.identity;
|
||||
}
|
||||
|
||||
// Using the LEAP->OPENXR device transform matrix
|
||||
// Unitys matrices are generated as 4 columns:
|
||||
Matrix4x4 deviceTransform = new Matrix4x4(
|
||||
new Vector4(data[0], data[1], data[2], data[3]),
|
||||
new Vector4(data[4], data[5], data[6], data[7]),
|
||||
new Vector4(data[8], data[9], data[10], data[11]),
|
||||
new Vector4(data[12], data[13], data[14], data[15]));
|
||||
|
||||
|
||||
// An example of the expected matrix if it were 8cm forward from the head origin
|
||||
// Unitys matrices are generated as 4 columns:
|
||||
//Matrix4x4 deviceTransform = new Matrix4x4(
|
||||
// new Vector4(-0.001f, 0, 0, 0),
|
||||
// new Vector4(0, 0, -0.001f, 0),
|
||||
// new Vector4(0, -0.001f, 0, 0),
|
||||
// new Vector4(0, 0, -0.08f, 1));
|
||||
|
||||
if (deviceTransform == Matrix4x4.identity)
|
||||
{
|
||||
devicePose = Pose.identity;
|
||||
poseSet = true;
|
||||
return Pose.identity;
|
||||
}
|
||||
|
||||
Matrix4x4 openXRToUnity = new Matrix4x4(
|
||||
new Vector4(1f, 0, 0, 0),
|
||||
new Vector4(0, 1f, 0, 0),
|
||||
new Vector4(0, 0, -1f, 0),
|
||||
new Vector4(0, 0, 0, 1));
|
||||
|
||||
deviceTransform = openXRToUnity * deviceTransform;
|
||||
|
||||
Vector3 outputPos = deviceTransform.GetPosition();
|
||||
//Quaternion outputRot = deviceTransform.rotation; // Note: the matrices we receive are not rotatrion matrices. This produces unexpected results
|
||||
|
||||
devicePose = new Pose(outputPos, Quaternion.identity);
|
||||
|
||||
poseSet = true;
|
||||
return devicePose;
|
||||
return FindDeviceTransform();
|
||||
}
|
||||
}
|
||||
|
||||
internal Pose FindDeviceTransform()
|
||||
{
|
||||
// Check the service has valid support for device transforms
|
||||
LEAP_VERSION minimumServiceVersion = new LEAP_VERSION { major = 5, minor = 19, patch = 0 };
|
||||
if (!ServerStatus.IsServiceVersionValid(minimumServiceVersion))
|
||||
{
|
||||
devicePose = Pose.identity;
|
||||
poseSet = true;
|
||||
return Pose.identity;
|
||||
}
|
||||
|
||||
// Check the device transform is available before asking for one
|
||||
bool deviceTransformAvailable = LeapC.GetDeviceTransformAvailable(Handle);
|
||||
|
||||
if (!deviceTransformAvailable)
|
||||
{
|
||||
devicePose = Pose.identity;
|
||||
return Pose.identity;
|
||||
}
|
||||
|
||||
// Get the device transform data and check it is valid as data
|
||||
float[] data = new float[16];
|
||||
eLeapRS result = LeapC.GetDeviceTransform(Handle, data);
|
||||
|
||||
if (result != eLeapRS.eLeapRS_Success || data == null)
|
||||
{
|
||||
devicePose = Pose.identity;
|
||||
return Pose.identity;
|
||||
}
|
||||
|
||||
// Using the LEAP->OPENXR device transform matrix
|
||||
// Unitys matrices are generated as 4 columns:
|
||||
Matrix4x4 deviceTransform = new Matrix4x4(
|
||||
new Vector4(data[0], data[1], data[2], data[3]),
|
||||
new Vector4(data[4], data[5], data[6], data[7]),
|
||||
new Vector4(data[8], data[9], data[10], data[11]),
|
||||
new Vector4(data[12], data[13], data[14], data[15]));
|
||||
|
||||
////An example of the expected matrix if it were 8cm forward from the head origin
|
||||
//// Unitys matrices are generated as 4 columns:
|
||||
//Matrix4x4 deviceTransform = new Matrix4x4(
|
||||
// new Vector4(-0.001f, 0, 0, 0),
|
||||
// new Vector4(0, 0, -0.001f, 0),
|
||||
// new Vector4(0, -0.001f, 0, 0),
|
||||
// new Vector4(0, 0, -0.08f, 1));
|
||||
|
||||
//// An example of applying a rotation to the existing device transform
|
||||
//Matrix4x4 rotationMatrix = Matrix4x4.Rotate(Quaternion.Euler(0, 90, 0));
|
||||
//deviceTransform = deviceTransform * rotationMatrix;
|
||||
|
||||
Matrix4x4 openXRToUnitySwizzle = new Matrix4x4(
|
||||
new Vector4(1.0f, 0, 0, 0),
|
||||
new Vector4(0, 1.0f, 0, 0),
|
||||
new Vector4(0, 0, -1f, 0),
|
||||
new Vector4(0, 0, 0, 1f));
|
||||
|
||||
// Converts device transform from openxr space to unity space
|
||||
deviceTransform = openXRToUnitySwizzle.inverse * deviceTransform * openXRToUnitySwizzle;
|
||||
|
||||
Vector3 outputPos = deviceTransform.GetPosition();
|
||||
Quaternion outputRot = deviceTransform.rotation;
|
||||
|
||||
devicePose = new Pose(outputPos, outputRot);
|
||||
|
||||
poseSet = true;
|
||||
return devicePose;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the internal status field of the current device
|
||||
/// </summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue