CaseyB
CaseyB

Reputation: 25058

Vuforia Multi Camera

I have a setup where I want to reveal some parts of the AR scene so my plan was to have the regular AR camera and then add a second camera as a child to that with a plane and a depth mask.

ARCamera
 |
 +- Camera <-- Vuforia Prefab
      |
      +- Background Plane
      |
      +- RevealCamera <- My camera
              |
              +- DepthMask Plane

But the two cameras do not stay in sync. All of my scene geometry is under one root node and never moves. I have watched the Scene window and verified that. I made sure that both cameras had the same frustum settings. So the only thing it could be at this point is that the cameras are moving differently. How could that be? Does Vuforia play some tricks with their camera?

Here's the code that I use to try to match the Vuforia camera:

[RequireComponent(typeof(Camera))]

public class FollowMainCamera : MonoBehaviour
{
    public Camera target;
    private Camera _camera;

    void Start()
    {
        _camera = GetComponent<Camera>();
    }

    void Update()
    {
        transform.position = target.transform.position;
        transform.localPosition = target.transform.localPosition;
        transform.rotation = target.transform.rotation;
        transform.localRotation = target.transform.localRotation;

        _camera.fieldOfView = target.fieldOfView;
    }
}

Upvotes: 3

Views: 2361

Answers (2)

Ankit
Ankit

Reputation: 491

The problem is “projection matrix”. It seems that Vuforia’s AR camera uses its own specific version of projection matrix, which defines how the “world” will be shown on screen. Try this

void Start()
{
SetProjectionMatrixAndFOV
}

void Update()
{
    overlayCamera.transform.position = Camera.main.transform.position;
    overlayCamera.transform.rotation = Camera.main.transform.rotation;
}


private void SetProjectionMatrixAndFOV()
{
    overlayCamera.fieldOfView = Camera.main.fieldOfView;
    overlayCamera.projectionMatrix = Camera.main.projectionMatrix;
}

Upvotes: 2

Dover8
Dover8

Reputation: 595

There is one trick that the Vuforia camera does and that is at runtime it changes the camera FOV to match that of the devices, so you'll need to update your RevealCamera to match that of the ARCamera at runtime.

Upvotes: 1

Related Questions