Log in or register to post comments

How do i display object X distance away from marker always?

January 14, 2012 - 4:15am #1

Ok so here's what I'm looking to do. In unity say if my marker is at origin i would like to display an object X distance away from it.

Eg: Say i have a full page newspaper ad and a quarter page ad on another paper(bottom right). When the camera tracks the marker i would like my model to always be displayed at the left bottom of the newspaper.

Any suggestions?

Re: How do i display object X distance away from marker always?

January 16, 2012 - 6:55pm #5

GetSize() returns the size of the target as defined by the config.xml file. This is the size you used when you created the target in the online system. It does not change.

The size assumption trick isn't directly supported by QCAR, you'll have to do some math. You could get an estimate from the distance between the ARCamera and the target in Unity. If you assume that the device is a fixed distance from the newspaper, then the ARCamera will be farther away for small targets and closer up for large targets (imagine zooming the camera in and out so the target fills more or less of the screen).

    // Set these in the Inspector
    public Camera arCamera = null;
    public ImageTargetBehaviour imageTarget = null;

    void Update()
    {
        // Get the distance between the camera and target
        float dist = Vector3.Distance(arCamera.transform.position, imageTarget.transform.position);

        // Scale the distance by the width of the target
        dist /= imageTarget.GetSize().x;

        Debug.Log("distance: " + dist);
    }

Again, this is an imperfect way of determining target size, and most likely won't work well in a user-driven environment. If a user moves the device in or out to get the entire target in view this clearly won't work.

- Kim

Re: How do i display object X distance away from marker always?

January 16, 2012 - 5:22am #4

ok, another trick i tried was that i wait for the target to get tracked and then i make my object a child of it thus preserving the childs size. But even that doesn't seem to work.

Re: How do i display object X distance away from marker always?

January 16, 2012 - 5:09am #3

Ok. So the size assumption trick you're talking about. Should i do that by getting the pixel value of the actual target using the GetSize() method in the DefaultTrackerEventHandler component attached to each target? Because I tried doing that but that just gives me some fixed value irrespective of the distance of the target from the camera. What i would need is a variable min max value(higher val when I'm closer, less when I'm further away). If i can get that then i can make some safe assumptions.

Could you give me an example of the method you mentioned? Thanks!

Re: How do i display object X distance away from marker always?

January 15, 2012 - 9:31am #2

This comes back to the size problem. If you're using the same target, QCAR has no way of distinguishing different print sizes of that target. So if you place a model 10 units to the left of the target, that distance will scale with the size of the target.

You could make some assumption as to how far the device might be from the newspaper, and then use the size of the target in the camera view to determine which image size is being tracked. Of course this wouldn't be foolproof, in reality the user could be looking at the target from any distance.

- Kim

Log in or register to post comments