Log in or register to post comments

freezing the AR when tracking lost

April 16, 2012 - 10:01am #1

Just wondering about the easiest way to make this happen.

I've created my own implementation of ITrackableEventHandler, so that I can control the time limit before displaying text to alert the user that tracking is lost, etc.

I'd like to be able to extend this to "freeze" the AR when the user wants. For instance, say he enables the AR via the tracker, but then wants to pull the device away and still interact with the AR. So I'd like to have a button that he can press to freeze/lock the AR at a desired view.

Any thoughts?

Re: freezing the AR when tracking lost

April 24, 2012 - 7:08pm #20

I can try that out tomorrow... but in the past I remember looking it up and learning that you can't change that setting at runtime (at least via the function call).

Re: freezing the AR when tracking lost

April 24, 2012 - 7:04pm #19
Quote:

I'm wondering if I'm going to need to do some math here.

Most likely :) Unity provides a lot of math functions that should makes things easier though.

Ideally your character controller would be completely based on the local transform of the character. So for instance, you should be saving the character's position and rotation relative to the target, not to the world, at the start.

If you're using Unity's built-in controller this might not be an option though... I'm not sure if you can change the direction of gravity for their controller.

Quote:

It's almost as if we should change the world-center-mode to no longer be "AUTO", but that can't be done on the fly.

I think this is worth trying. When WorldCenterMode is set to NONE the camera should stay stationary in the scene. You could try switching from AUTO to NONE when tracking is lost. I think you can do it like this:

QCARManager.Instance.WorldCenterMode = QCARBehaviour.WorldCenterMode.NONE;

Note this use case hasn't really been tested... Let us know how it goes!

- Kim

Re: freezing the AR when tracking lost

April 24, 2012 - 10:09am #18
jacksmash wrote:

I've figured out what is happening... somewhat.

Since I store the CharacterParent's initial position and rotation, when I "freeze" the scene (by parenting AROrigin to ARCamera), the CharacterParent still moves w.r.t. the tracker.

I think I've been staring at this for too long, because it seems to me that the solution should be simple, yet I can't see it.

Yep, this is definitely the challenge.

It's almost as if we should change the world-center-mode to no longer be "AUTO", but that can't be done on the fly.

So yeah, I need to figure out a way to tell the character what his relative movement should be. I'm wondering if I'm going to need to do some math here.

Re: freezing the AR when tracking lost

April 23, 2012 - 5:55pm #17

I've figured out what is happening... somewhat.

Since I store the CharacterParent's initial position and rotation, when I "freeze" the scene (by parenting AROrigin to ARCamera), the CharacterParent still moves w.r.t. the tracker.

I think I've been staring at this for too long, because it seems to me that the solution should be simple, yet I can't see it.

Re: freezing the AR when tracking lost

April 23, 2012 - 4:05pm #16
jacksmash wrote:

Sorry, I should clarify that the Character Controller is on the parent of the character. I need to edit my above post because I just realized that it didn't show the hierarchy correctly.

Done editing. Hopefully it makes it a little clearer.

Re: freezing the AR when tracking lost

April 23, 2012 - 3:58pm #15

Sorry, I should clarify that the Character Controller is on the parent of the character. I need to edit my above post because I just realized that it didn't show the hierarchy correctly.

Re: freezing the AR when tracking lost

April 23, 2012 - 3:47pm #14
ksiva wrote:

Is the character being moved relative to its parent? For example, you should be changing its localPosition rather than position.

Is anything about its movement dependent on the world position and forward vector of its parent?

- Kim

Yes, on every update I store the character's forward vector and then call Move (I'm using unity's Character Controller).

Thing is, I imagine it is updating the local position, because it works when AROrigin is parented to the tracker. I'm stumped.

Re: freezing the AR when tracking lost

April 23, 2012 - 3:30pm #13

Is the character being moved relative to its parent? For example, you should be changing its localPosition rather than position.

Is anything about its movement dependent on the world position and forward vector of its parent?

- Kim

Re: freezing the AR when tracking lost

April 23, 2012 - 1:38pm #12
ksiva wrote:

How about parenting it to the camera?

- Kim

I appreciate all of your input on this.

My last problem is regarding character movement. I have a character that I move around the screen, but as soon as I parent the AROrigin to the ARCamera, his movement is no relative to the AROrigin as it was previously.

For context, this is how the scene is set up PRIOR to parenting the AR to the camera:

tracker
-- AROrigin
------ SceneParent (empty)
---------- CharacterParent (CharacterController)
-------------- Character Model
---------- Scene stuff

And then, AFTER parenting the AR to the camera, I have:

ARCamera
-- AROrigin
------ SceneParent (empty)
-------- CharacterParent (CharacterController)
------------ Character Model
-------- Scene stuff

In the prior case, the character moves around just fine. In other words, his forward movement is relative to the background and the way he is facing.

In the last case (where AROrigin is parented to ARCamera), the character's movement is relative to the camera position in some way that I can't entirely figure out. As I turn the device, his movement becomes worse.

Any thoughts as to what I'm missing?

Re: freezing the AR when tracking lost

April 19, 2012 - 1:21pm #11

How about parenting it to the camera?

- Kim

Re: freezing the AR when tracking lost

April 19, 2012 - 1:17pm #10

So, yes that works to a certain extent. The only thing I need to do now is force the content to maintain its position relative to the camera...

Re: freezing the AR when tracking lost

April 19, 2012 - 12:52pm #9

Ok, I'll try that. Thanks!

ksiva wrote:

Then another option is to "unbind" the content from the trackable to freeze it. If you set the content's parent to null it should stay fixed in its last position. When tracking is found again you can reparent the content, but note you'll have to reset its localPosition and localRotation once you do.

If you have multiple objects or any objects with an offset, I suggest inserting an empty game object between your content and the target. That way you can just unbind this top level object, and when you rebind it you can set the local position and rotation to zero.

- Kim

Re: freezing the AR when tracking lost

April 19, 2012 - 12:51pm #8
ksiva wrote:

Did you try deactivating the TrackableBehaviours? Something like this:

foreach (TrackableBehaviour tb in FindObjectsOfType(typeof(TrackableBehaviour)))
{
    print("disabling trackabled named " + tb.TrackableName);
    tb.enabled = false;
}

Even with the QCARBehaviour active that should be enough to freeze the content in place.

- Kim

Yes, that works of course... but since it disables all behavior I can no longer interact with the AR. I realize that I didn't make that clear in my original question - apologies!

Re: freezing the AR when tracking lost

April 19, 2012 - 12:49pm #7

Then another option is to "unbind" the content from the trackable to freeze it. If you set the content's parent to null it should stay fixed in its last position. When tracking is found again you can reparent the content, but note you'll have to reset its localPosition and localRotation once you do.

If you have multiple objects or any objects with an offset, I suggest inserting an empty game object between your content and the target. That way you can just unbind this top level object, and when you rebind it you can set the local position and rotation to zero.

- Kim

Re: freezing the AR when tracking lost

April 19, 2012 - 12:01pm #6

Did you try deactivating the TrackableBehaviours? Something like this:

foreach (TrackableBehaviour tb in FindObjectsOfType(typeof(TrackableBehaviour)))
{
    print("disabling trackabled named " + tb.TrackableName);
    tb.enabled = false;
}

Even with the QCARBehaviour active that should be enough to freeze the content in place.

- Kim

Re: freezing the AR when tracking lost

April 18, 2012 - 6:22am #5
ksiva wrote:

You could deactivate the TrackableBehaviour attached to the target (for image targets the subclass is ImageTargetBehaviour). This will cause the OnTrackableLost method of the DefaultTrackableEventHandler to be called, however, which will turn off the renderers of any child objects. You could modify this script to ignore the OnTrackableLost call under certain conditions.

- Kim

Thanks! That seems to be the easiest thing to do. The only trouble now is that I don't really want to disable QCARBehavior, but I do need the AR to remain in position once the user "freezes" the screen. I've modified the OnTrackableLost method such that we don't lose tracking, but the AR still moves toward the target as I move the device away from the target, and so you can no longer see all of the AR even though we are ignoring the OnTrackingLost method.

Does that make sense?

Re: freezing the AR when tracking lost

April 17, 2012 - 4:51pm #4

You could deactivate the TrackableBehaviour attached to the target (for image targets the subclass is ImageTargetBehaviour). This will cause the OnTrackableLost method of the DefaultTrackableEventHandler to be called, however, which will turn off the renderers of any child objects. You could modify this script to ignore the OnTrackableLost call under certain conditions.

- Kim

Re: freezing the AR when tracking lost

April 16, 2012 - 3:06pm #3

Great! Works like a charm!

Is it possible to do this, but still maintain the camera feed? I don't want to freeze the camera feed. Just curious.

Re: freezing the AR when tracking lost

April 16, 2012 - 2:16pm #2

If you want to freeze the position of the 3D object on the screen you can disable the QCARBehaviour:

QCARBehaviour qcarBehaviour =
    (QCARBehaviour)UnityEngine.Object.FindObjectOfType(
                                        typeof(QCARBehaviour));

qcarBehaviour.enabled = false;

If you also want to freeze the camera feed it's a bit trickier. I suggest starting with the BackgroundTextureAccess sample and following the included Readme to render the camera image using the ARCamera. Then when you disable the QCARBehaviour the camera image should still be rendered.

- Kim

Log in or register to post comments