Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Hololens doesn't position objects from user position using vuforia

Discussion in 'Windows Mixed Reality' started by Quben, Oct 7, 2017.

  1. Quben

    Quben

    Joined:
    Oct 2, 2012
    Posts:
    6
    What are the settings I need to do to actually setup so I can walk around an object and look at it. Tried various settings but right now the hololens only tracks the rotation of the head and not the spatial position. Which means that if I move around in the room it wont affect the camera in the game.

    Ive tried the AR camera with both World Center Mode as DEVICE_TRACKER and CAMERA. Both seem to give the wrong result.

    Do I need to manually move the camera from reading the device? Don't think its how they solved this

    In player settins I have spatialPerception selected aswell.

    I am using Unity2017.2.0b11 with vuforia.

    Any help/advice or link to a topic similar would be appreciated!
     
  2. jptsetung

    jptsetung

    Joined:
    Jan 12, 2013
    Posts:
    51
    That won't help much as I'm a beginner too, but regarding the first question of your post, and according to my tests, the camera position is changed when you move around with your hololens on your head. It's working like this on all the tutorial I've. But maybe your problem is related with binding vuforia camera and hololens camera. I didn't try integrating vuforia to hololens yet, so I can't help too much.
     
    Quben likes this.
  3. Quben

    Quben

    Joined:
    Oct 2, 2012
    Posts:
    6
    Hmm I think they changed that with the hololenscamera and the vuforia camera. Since the script doesnt longer take a camera as input (I watched the other tutorials but they seemed outdated).

    But maybe you are right and I somehow haven't created a hololens camera, just don't know how to input this to the vuforia system. I can see objects and image track them, its only the position from the hololens that seems off.

    Can you link to the tutorial you was using? I maybe can look throught that and see if I find some answers there.

    Thanks :)
     
  4. Quben

    Quben

    Joined:
    Oct 2, 2012
    Posts:
    6
    Tried now to just load a cube without vuforia and build to the hololens, that seems to work with the positional when I attached "TrackedPoseDriver" to the camera. Tried the same with vuforia, this did not work. think the vuforia renders this different. Thinking of maybe switching to pure unity and image detect some other way... According to the demos ive seen of vuforia I dont know if they have solved this, they kindof require the image to always be present.
     
  5. whitebozo

    whitebozo

    Joined:
    Oct 27, 2014
    Posts:
    24
    So I'm using vuforia and hololens. What I'm doing is using the Vuforia image to spawn the object in the correct spot in the world and then using a "keyword" like "lock" and "restart" to turn on/off the vuforia aspects of the scene and add a world anchor to the object so I can then walk around the object here is some example code of how I'm doing it. Make sure you are using Vuforia and HoloToolkit namespaces for this code to work.
    Code (CSharp):
    1.         bool VuforiaOn = true;
    2.         public DefaultTrackableEventHandler ImageTracker;
    3.  
    4.  
    5.         public void ToggleVuforia(bool Lock)
    6.         {
    7.             if (Lock && VuforiaOn)
    8.             {
    9.                 ImageTracker.Found = true;
    10.                 VuforiaBehaviour.Instance.enabled = false;
    11.                 ImageTracker.enabled = false;
    12.                 VuforiaOn = false;
    13.                 AttachWorldAnchor();
    14.             }
    15.             else if(!Lock && !VuforiaOn)
    16.             {
    17.                 VuforiaBehaviour.Instance.enabled = true;
    18.                 ImageTracker.enabled = true;
    19.                 VuforiaOn = true;
    20.                 ImageTracker.Found = false;
    21.                 RemoveWorldAnchor();
    22.             }
    23.         }
    24.  
    25.         private void AttachWorldAnchor()
    26.         {
    27.             if (WorldAnchorManager.Instance != null)
    28.             {
    29.                   WorldAnchorManager.Instance.AttachAnchor(CenteredObject);
    30.             }
    31.         }
    32.  
    33.         private void RemoveWorldAnchor()
    34.         {
    35.             if (WorldAnchorManager.Instance != null)
    36.             {
    37.                 WorldAnchorManager.Instance.RemoveAnchor(CenteredObject);
    38.             }
    39.         }
    EDIT: The "found" bool on the DefaultTrackableEventHandler is a bool that I made to trigger state changes of the Image tracker I use it and a private bool to trigger the switch events in the update like this...
    Code (CSharp):
    1.     private void Update()
    2.     {
    3.         if(Found && !Showing)
    4.         {
    5.             OnTrackingFound();
    6.             Showing = true;
    7.         }
    8.         else if(!Found && Showing)
    9.         {
    10.             OnTrackingLost();
    11.             Showing = false;
    12.         }
    13.     }
    14.     public void OnTrackableStateChanged(
    15.         TrackableBehaviour.Status previousStatus,
    16.         TrackableBehaviour.Status newStatus)
    17.     {
    18.         if (newStatus == TrackableBehaviour.Status.DETECTED ||
    19.             newStatus == TrackableBehaviour.Status.TRACKED ||
    20.             newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
    21.         {
    22.             Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
    23.             Found = true;
    24.         }
    25.         else if (previousStatus == TrackableBehaviour.Status.TRACKED &&
    26.                  newStatus == TrackableBehaviour.Status.NOT_FOUND)
    27.         {
    28.             Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
    29.             Found = false;
    30.         }
    31.         else
    32.         {
    33.             // For combo of previousStatus=UNKNOWN + newStatus=UNKNOWN|NOT_FOUND
    34.             // Vuforia is starting, but tracking has not been lost or found yet
    35.             // Call OnTrackingLost() to hide the augmentations
    36.             Found = false;
    37.         }
    38.     }
    39.  
    40.  
     
    Quben likes this.
  6. whitebozo

    whitebozo

    Joined:
    Oct 27, 2014
    Posts:
    24
    Another thing to mention about Vuforia and hololens is the size of the printed marker and the size of the tracked image object in the scene directly correlate with each other. For example if you have a 4 inch printed marker make sure your image object in the scene is set to a scale of 0.1016. Because unity units equal a meter and 4 inches = 0.1016 meters. If you don't have the scale the same as the real world object the hologram will most likely be off center or wrong sized in the view of the hololens. Hope this helps.
     
    Quben likes this.
  7. Quben

    Quben

    Joined:
    Oct 2, 2012
    Posts:
    6
    Thanks alot for your detailed response! I will try your suggestions and see if they get me closer to where I want, Thanks! :)
     
  8. Quben

    Quben

    Joined:
    Oct 2, 2012
    Posts:
    6
    Did what you suggested and it worked!

    The problem for me was like joshua suggested that I had the wrong scale on the vuforia objects (was preset to 50, now im using 0.2969768 which should be a A4 paper format.

    My solution was to enable/disable the vuforia behaviour on the camera. Then enabling all the renderers in the imagetargets and use a TrackPoseDriver on the camera.

    Also the conversion 4 inch to 0.1016 kindof worked, it did not feel so exact as I wanted it. But anyhow now I need to see if I can config that value.

    Thanks for all the input!
     
  9. whitebozo

    whitebozo

    Joined:
    Oct 27, 2014
    Posts:
    24
    No problem glad I could help.
     
  10. thanhit08

    thanhit08

    Joined:
    Mar 14, 2014
    Posts:
    1
    Thanks for your suggestion, however, I follow your instructions but my virtual object after locking continues to follow me (front hololens). Can you help me handle it?
     
  11. ThatDarnCat

    ThatDarnCat

    Unity Technologies

    Joined:
    Jan 4, 2017
    Posts:
    9
    Vuforia has a feature called extended tracking that is meant to lock the child game object in place once the image target is detected. It is in the Advanced section when looking at the Image Target Behavior (Script) component. This should get you started on getting the behavior you are looking for.

    https://library.vuforia.com/articles/Training/Extended-Tracking.html