The Mixed Reality Forums here are no longer being used or maintained.
There are a few other places we would like to direct you to for support, both from Microsoft and from the community.
The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.
For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.
If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.
And always feel free to hit us up on Twitter @MxdRealityDev.
Extracting camera position, direction and up from HolographicStereoTransform
Hello,
I'm trying to extract cameras information of each eye from HolographicStereoTransform
The following code works inside the emulator, but doesn't with the real hololens.
Do you have an idea of what's wrong ?
HolographicStereoTransform cameraProjectionTransform = cameraPose.ProjectionTransform; HolographicStereoTransform? viewTransformContainer = cameraPose.TryGetViewTransform(coordinateSystem); if (viewTransformContainer.HasValue) { HolographicStereoTransform viewTransform = viewTransformContainer.Value; Matrix4x4 ReversedMatrix; if(Matrix4x4.Invert(viewTransform, out ReversedMatrix)) { Camera.Position.X = ReversedMatrix.M41; Camera.Position.Y = ReversedMatrix.M42; Camera.Position.Z = ReversedMatrix.M43; Camera.Direction.X = -ReversedMatrix.M31; Camera.Direction.Y = -ReversedMatrix.M32; Camera.Direction.Z = -ReversedMatrix.M33; Camera.Up.X = -ReversedMatrix.M21; Camera.Up.Y = -ReversedMatrix.M22; Camera.Up.Z = -ReversedMatrix.M23; } const float Rad2Deg = 57.295779f; // 180/PI float E = cameraProjectionTransform.M22; Camera.FieldOfView = ((float)Math.Atan(1/E) * 2) * Rad2Deg; }
Best Answer
-
Patrick mod
I put this in the render loop of the spinning cube template, and it seems to work on emulator and in device.
HolographicStereoTransform cameraProjectionTransform = cameraPose->ProjectionTransform; IBox<HolographicStereoTransform>^ viewTransformContainer = cameraPose->TryGetViewTransform(m_referenceFrame->CoordinateSystem); if (viewTransformContainer != nullptr) { HolographicStereoTransform viewTransform = viewTransformContainer->Value; XMMATRIX revMat = XMMatrixInverse(nullptr, XMLoadFloat4x4((const float4x4*)&viewTransform.Left)); float4x4 floatMat; XMStoreFloat4x4(&floatMat, revMat); WCHAR msg[255]; swprintf_s(msg, L"LEFT\n%.02f %.02f %.02f\n%.02f %.02f %.02f\n%.02f %.02f %.02f\n%.02f\n", floatMat.m41, floatMat.m42, floatMat.m43, floatMat.m31, floatMat.m32, floatMat.m33, floatMat.m21, floatMat.m22, floatMat.m23, (atan(1 / cameraProjectionTransform.Left.m22) * 2 * 57.295779f)); OutputDebugString(msg); revMat = XMMatrixInverse(nullptr, XMLoadFloat4x4((const float4x4*)&viewTransform.Right)); XMStoreFloat4x4(&floatMat, revMat); swprintf_s(msg, L"RIGHT\n%.02f %.02f %.02f\n%.02f %.02f %.02f\n%.02f %.02f %.02f\n%.02f\n\n", floatMat.m41, floatMat.m42, floatMat.m43, floatMat.m31, floatMat.m32, floatMat.m33, floatMat.m21, floatMat.m22, floatMat.m23, (atan(1 / cameraProjectionTransform.Right.m22) * 2 * 57.295779f)); OutputDebugString(msg); }
creates output like:
LEFT
-2.74 0.52 1.30
0.89 0.30 -0.35
-0.30 0.95 0.05
17.07
RIGHT
-2.76 0.52 1.24
0.88 0.30 -0.36
-0.30 0.95 0.05
17.05or
LEFT
-0.00 -0.02 -0.10
0.00 0.22 0.97
0.00 0.97 -0.22
17.00
RIGHT
-0.00 -0.02 -0.10
0.00 0.22 0.97
0.00 0.97 -0.22
17.00on emulator.
===
This post provided as-is with no warranties and confers no rights. Using information provided is done at own risk.(Daddy, what does 'now formatting drive C:' mean?)
5
Answers
I put this in the render loop of the spinning cube template, and it seems to work on emulator and in device.
creates output like:
LEFT
-2.74 0.52 1.30
0.89 0.30 -0.35
-0.30 0.95 0.05
17.07
RIGHT
-2.76 0.52 1.24
0.88 0.30 -0.36
-0.30 0.95 0.05
17.05
or
LEFT
-0.00 -0.02 -0.10
0.00 0.22 0.97
0.00 0.97 -0.22
17.00
RIGHT
-0.00 -0.02 -0.10
0.00 0.22 0.97
0.00 0.97 -0.22
17.00
on emulator.
===
This post provided as-is with no warranties and confers no rights. Using information provided is done at own risk.
(Daddy, what does 'now formatting drive C:' mean?)