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.
Understand when a user clicked (gaze) on particular object in DirectX (newbie)
Hi,
how I can understand when the user "clicked" on a particular object? In example on the cube of the spinningcuberender base template for Hololens?
thanks
Best Answer
-
OptionsJackson mod
You will have to perform some ray collision between the HoloLens and the holograms in your scene.
You will need a ray defined by the HoloLens position and the facing direction. Use an XMVECTOR:
https://msdn.microsoft.com/en-us/library/windows/desktop/ee420742(v=vs.85).aspxThen you will probably want to add a bounding volume to each hologram in your scene:
https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.directxcollision.boundingsphere.intersects(v=vs.85).aspx
(This is optional, but will speed up your collision detection if you have multiple holograms in your scene)Check if your ray intersects with any of the bounding volumes in your scene (that you added to your holograms)
Then check to see if the ray intersects with any of the triangles in that hologram:
https://msdn.microsoft.com/en-us/library/windows/desktop/hh855922(v=vs.85).aspxIf your ray intersects with multiple holograms' bounding volumes, you will want to check the closer hologram for triangle collision first, then break when you get a valid collision.
5
Answers
You will have to perform some ray collision between the HoloLens and the holograms in your scene.
You will need a ray defined by the HoloLens position and the facing direction. Use an XMVECTOR:
https://msdn.microsoft.com/en-us/library/windows/desktop/ee420742(v=vs.85).aspx
Then you will probably want to add a bounding volume to each hologram in your scene:
https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.directxcollision.boundingsphere.intersects(v=vs.85).aspx
(This is optional, but will speed up your collision detection if you have multiple holograms in your scene)
Check if your ray intersects with any of the bounding volumes in your scene (that you added to your holograms)
Then check to see if the ray intersects with any of the triangles in that hologram:
https://msdn.microsoft.com/en-us/library/windows/desktop/hh855922(v=vs.85).aspx
If your ray intersects with multiple holograms' bounding volumes, you will want to check the closer hologram for triangle collision first, then break when you get a valid collision.
Also note: collision can get pretty expensive as you add more objects to your scene. You may wish to register each of your holograms to a scene graph and do some space partitioning in your scene to optimize these ray checks.
Alternatively, you might want to look into using a physics engine that will do all of that for you.