Update to Ultraleap Unity Plugin 6.12.0

This commit is contained in:
SDraw 2023-09-13 19:03:49 +03:00
parent 3713253375
commit 0fccd9e892
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
2 changed files with 64 additions and 23 deletions

View file

@ -263,33 +263,52 @@ namespace Leap
return devicePose;
}
//float[] data = new float[16];
//eLeapRS result = LeapC.GetDeviceTransform(Handle, data);
float[] data = new float[16];
eLeapRS result = LeapC.GetDeviceTransform(Handle, data);
//if (result != eLeapRS.eLeapRS_Success || data == null)
//{
// devicePose = Pose.identity;
// return devicePose;
//}
if (result != eLeapRS.eLeapRS_Success || data == null)
{
devicePose = Pose.identity;
poseSet = true;
return Pose.identity;
}
//// Get transform matrix and convert to unity space by inverting Z.
//Matrix4x4 transformMatrix = 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]));
//Matrix4x4 toUnity = Matrix4x4.Scale(new Vector3(1, 1, -1));
//transformMatrix = toUnity * transformMatrix;
// 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]));
//// Identity matrix here means we have no device transform, also check validity.
//if (transformMatrix.isIdentity || !transformMatrix.ValidTRS())
//{
// devicePose = Pose.identity;
// return devicePose;
//}
//// Return the valid pose
//devicePose = new Pose(transformMatrix.GetColumn(3), transformMatrix.rotation);
// 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;

View file

@ -41,6 +41,17 @@ namespace Leap
return new Frame().CopyFrom(frame).Transform(transform);
}
/**
* Returns a new frame that is a copy of a frame, with an additional rigid
* transformation applied to it.
*
* @param transform The transformation to be applied to the copied frame.
*/
public static Frame TransformedCopy(this Frame frame, Vector3 position, Quaternion rotation)
{
return new Frame().CopyFrom(frame).Transform(new LeapTransform(position, rotation));
}
/**
* Does an in-place rigid transformation of a Hand.
*
@ -79,6 +90,17 @@ namespace Leap
return new Hand().CopyFrom(hand).Transform(transform);
}
/**
* Returns a new hand that is a copy of a hand, with an additional rigid
* transformation applied to it.
*
* @param transform The transformation to be applied to the copied hand.
*/
public static Hand TransformedCopy(this Hand hand, Vector3 position, Quaternion rotation)
{
return new Hand().CopyFrom(hand).Transform(new LeapTransform(position, rotation));
}
/**
* Does an in-place rigid transformation of a Finger.
*