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

Normalize or align vector 3 z-axis to GazeNormal direction from GazeManager

hey I hope this isn't a dumb question, but any help is greatly appreciated. I'll do my best to explain the situation.

I am trying to us the INAvigationHandler to move a rather large object (the ground around me). This script worked great to move something small but when I made it very large, the axis needed to become dynamic. I realized that with this code, the x and z axis remained relative to the original direction I was looking when the scene loaded. Meaning that dragging to the left or right worked well, until I turned my head. With my head turned 180 degrees, my forward drag motion did the opposite since the axis were not changing with my direction of gaze.

I know part of my problem is how I am trying to call the variable 'GazeNormal' from GazeManager.cs. I am also unsure if the transform.rotation is going to work as well.

//Here is most of my code ////////////////////////////////

public Vector3 GazeNormal;

void SelectTarget(GameObject target)
{
    GazeManager = target.GetComponent<GazeManager>().GazeNormal;

     }

[SerializeField]
bool draggingEnabled = true;
public void SetDragging(bool enabled)
{
    draggingEnabled = enabled;
}
public void OnNavigationStarted(NavigationEventData eventData)
{
    InputManager.Instance.PushModalInputHandler(gameObject);
    lastPosition = transform.position;
}

public void OnNavigationUpdated(NavigationEventData eventData)
{
    if (draggingEnabled)
    {
        Drag(eventData.CumulativeDelta);
    }
}

public void OnNavigationCompleted(NavigationEventData eventData)
{
    InputManager.Instance.PopModalInputHandler();
}

public void OnNavigationCanceled(NavigationEventData eventData)
{
    InputManager.Instance.PopModalInputHandler();
}

void Drag(Vector3 positon)
{
    var targetPosition = lastPosition + positon * DragScale;
    if (Vector3.Distance(lastPosition, targetPosition) <= MaxDragDistance)
    {
        transform.rotation = Quaternion.Euler(GazeNormal.x, GazeNormal.y, GazeNormal.z);
        Vector3 newPosition = Vector3.Lerp(transform.position, targetPosition, DragSpeed);
        transform.position = new Vector3(newPosition.x, transform.position.y, newPosition.z);
    }
}

(Let me know what other kind of information I could include to better my questions, I appreciate any help)

Answers

  • Options

    I think I understand what you're trying to do.

    1. The proper way to access GazeManager is via the singleton instance GazeManager.Instance. Any class in the toolkit that implements Singleton should be accessed in this fashion.
    2. Use GazeManager.Instance.GazeTransform to detect the head rotation - if you're head rotates more than 90 degrees - you can dynamically adjust which axes you honor and which ones you lock.
    3. I don't think you need to be messing with transform.rotation in the dragging code - just swap out which transform.position axis to lock down.

    P.S. I think you got some of this code from my blog post? If so great! Glad I was able to help! Also I just noticed a typo in "void Drag(Vector3 positon)" - I'll get that fixed.

  • Options

    Thank you so much for responding Bill! Yes, I had got most of this code from your very well put together blog post! I have tried to learn what I could before responding.

    After doing a bunch of reading on singletons, I am still having a bit of a difficult time calling the GazeTransform variable from the GazeManager.

    I figured I'd put the line of code in here;
    public void OnNavigationStarted(NavigationEventData eventData)
    {
    GazeManager.Instance.GazeTransform(); //But I get an error on the GazeTransform.
    InputManager.Instance.PushModalInputHandler(gameObject);
    lastPosition = transform.position;
    }

    The error reads; "Non-invocable member 'GaseManager.GazeTransform' cannot be used like a method". I am assuming that I shouldn't have to change anything within the GazeManager to be able to call this information.

    Also, how would one swap out an axis in the transform.position? from my understanding the line of code above dictates the coordinates of the object, what part controls the orientation of the axis?

    Once again, thank you so much for taking the time to respond, it is teaching me a ton!

  • Options

    Yeah its a property not a method. If you're new to programming/C# (not saying you are) - you can do a "find all" in your editor of choice and search for "gazemanager.instance.gazetransform" and see some example usages in the toolkit examples.

  • Options

    Again, thank you Bill! I am actually quite new to programming, but I am taking classes and doing my best to learn. The "Find All" tip is awesome and really helps.

    Although the find all on this line of code doesn't seem to find me an example of this being used elsewhere. In fact, the only time it finds another use of GazeTransform, is within the GazeManager.
    I'd hate to take up your valuable time with my questions but how would one call a property instead of a method into another script? Or is there another example of a property being called that I could analyse further?

    As always, your input is extremely appreciated. Thank you!

Sign In or Register to comment.