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.
Options

Detect Camera's relative position to a box collider like in Holograms App

In the built in Holograms app, I found that the "menu" ("adjust" button and "delete" button) will show up at different side of the box collider according to user's relative position to the Holograms, so as user goes to the other side of the Hologram, the menu also goes to the other side of the Hologram.

I am trying to implement this functionality in Unity. But I cannot figure out the logic behind to decide where the menu should shows up.

Any hints?

Best Answer

  • Options
    WanzeWanze
    edited September 2017 Answer ✓

    Okay, after two hours of work, finally find the pattern so that we can actually just use the x and z coordinate (it's more than just larger or smaller than zero) to decide the relative position of Camera to the target object.

    In case someone encountered the same issue or just curious, here is my implementation:
    Vector3 tempDiff = camera.position - transform.position;
    if (Mathf.Abs(tempDiff.x) < Mathf.Abs(tempDiff.z))
    {
    if (tempDiff.z < 0)
    {
    Debug.Log("At Front");
    }
    else
    {

                        Debug.Log("At Back");
                    }
                }
                else
                {
                    if (tempDiff.x < 0)
                    {
                        Debug.Log("At Left");
                    }
                    else
                    {
                        Debug.Log("At Right");
                    }
                }
    

    One issue though, this function need to be in the update (or a while true coroutine), so this solution eats up a lot of performance since it is doing calculations constantly. So if anyone has a better solution for detecting camera's relative position to the object, I am happy to hear about it.

Answers

  • Options
    WanzeWanze
    edited September 2017 Answer ✓

    Okay, after two hours of work, finally find the pattern so that we can actually just use the x and z coordinate (it's more than just larger or smaller than zero) to decide the relative position of Camera to the target object.

    In case someone encountered the same issue or just curious, here is my implementation:
    Vector3 tempDiff = camera.position - transform.position;
    if (Mathf.Abs(tempDiff.x) < Mathf.Abs(tempDiff.z))
    {
    if (tempDiff.z < 0)
    {
    Debug.Log("At Front");
    }
    else
    {

                        Debug.Log("At Back");
                    }
                }
                else
                {
                    if (tempDiff.x < 0)
                    {
                        Debug.Log("At Left");
                    }
                    else
                    {
                        Debug.Log("At Right");
                    }
                }
    

    One issue though, this function need to be in the update (or a while true coroutine), so this solution eats up a lot of performance since it is doing calculations constantly. So if anyone has a better solution for detecting camera's relative position to the object, I am happy to hear about it.

Sign In or Register to comment.