Hello everyone.

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.

Pixel to Application-specified Coordante System for Unity

Hi There,
I found an example at https://docs.microsoft.com/en-us/windows/mixed-reality/locatable-camera where you convert 2D Pixel coordinates into 3D positions. How would you do this in unity (see code below)? Thank you very much in advance?

float2 ImagePosZeroToOne = float2( PixelPos.x / ImageWidth, 1.0 - (PixelPos.y / ImageHeight ) );
float2 ImagePosProjected = ( ( ImagePosZeroToOne * 2.0 ) - float2(1,1) ); // -1 to 1 space
float3 CameraSpacePos = UnProjectVector( Projection, float3( ImagePosProjected, 1) );
float3 WorldSpaceRayPoint1 = mul( CameraToWorld, float4(0,0,0,1) ); // camera location in world space
float3 WorldSpaceRayPoint2 = mul( CameraToWorld, CameraSpacePos ); // ray point in world space

public static Vector3 UnProjectVector(Matrix4x4 proj, Vector3 to)
Vector3 from = new Vector3(0, 0, 0);
var axsX = proj.GetRow(0);
var axsY = proj.GetRow(1);
var axsZ = proj.GetRow(2);
from.z = to.z / axsZ.z;
from.y = (to.y - (from.z * axsY.z)) / axsY.y;
from.x = (to.x - (from.z * axsX.z)) / axsX.x;
return from;

Sign In or Register to comment.