Mixing manual main camera move and Tracked pose driver ?

Hello all,
I use a framework that moves the main camera on input event (keyboard, mouse).
I’m trying to add (6dof) VR capabilities to my application that use that framework.

  • I would like to keep the framework input events to move my VR cameras when it moves the main camera.
  • I need to move the main camera according to my VR cameras transform to keep the framework functionalities working.

I spend one week on this problem without succes :frowning:

I made the following transform hierarchie :

  • Main Camera (_cameraMain)

  • Game Object VRHead (_head)

  • VR Camera Left (_cameraLeft)

  • VR Camera Right (_cameraRight)

Then the following script (that does not work well) :

void Update()
{
        // Get global position for each cameras
        Vector3 positionCameraLeft = getPositionCamLef(); // Mycode
        Vector3 positionCameraRight = getPositionCamRight(); // Mycode

        // Get global rotation for each cameras
        Quaternion rotationCameraLeft = getRotationCamLeft(); // Mycode
        Quaternion rotationCameraRight = getRotationCamRight(); // Mycode


        // Set head global position and rotation
        _head.transform.position = ((positionCameraLeft + positionCameraRight) / 2);
        _head.transform.rotation = Quaternion.Slerp(rotationCameraLeft, rotationCameraRight, 0.5f);

        // Set VR cameras global position and rotation
        _cameraLeft.transform.position = positionCameraLeft;
        _cameraLeft.transform.rotation = rotationCameraLeft;
        _cameraRight.transform.position = positionCameraRight;
        _cameraRight.transform.rotation = rotationCameraRight;

        // Move head with delta main camera position 
        _head.transform.position -= _previousPositionMainCamera;
        _head.transform.position += _cameraMain.transform.position;
        _head.transform.rotation *= Quaternion.Inverse(_previousRotationMainCamera);
        _head.transform.rotation *= _cameraMain.transform.rotation;

        // Update main camera position at the head position
        _cameraMain.transform.position = _head.transform.position;
        _cameraMain.transform.rotation = _head.transform.rotation;

        // Replace the head position into the main camera position
        _head.transform.localPosition = Vector3.zero;
        _head.transform.localRotation = Quaternion.identity;

        // Save transforms for next image
        _previousPositionVRCamera = _head.transform.position;
        _previousRotationVRCamera = _head.transform.rotation;
        _previousPositionMainCamera = _cameraMain.transform.position;
        _previousRotationMainCamera = _cameraMain.transform.rotation;
}

With that script, I cannot move the maincamera with my framework.
And if I force a main camera rotation, When I move the head, the direction is bad (does not take the main camera rotation into account).

I start thinking I miss something :frowning:

Any help could be appreciated.

I am new to vr devlop but i do like to keep it simlple.

Have you try to use te tracked pose Driver componnent in main camera

6570973--745231--xr.PNG ?

Hum. Seems interesting.
Could you explain me how to use it ?

you have to go in package manager

in the unity Registry scrool all down and install the 2 last xr plug in

“XR legacy” ( stand for the component you need to add

and

“XR Plugin” (is for setting up the VR devices,

Ok.
I made a very simple test :
I created a “TestTtrackedPoseDriver” GameObject and load the following script :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.XR.Interaction;


public class TestTransform : BasePoseProvider
{
    [Range(-180.0f, 180.0f)]
    public float VrRotX = 0;

    [Range(-180.0f, 180.0f)]
    public float VrRotY = 0;

    [Range(-180.0f, 180.0f)]
    public float VrRotZ = 0;

    [Range(-10.0f, 10.0f)]
    public float VrPosX = 0;

    [Range(-10.0f, 10.0f)]
    public float VrPosY = 1.7f;

    [Range(-10.0f, 10.0f)]
    public float VrPosZ = 0;

    public override bool TryGetPoseFromProvider(out Pose output)
    {
        output.position = new Vector3(VrPosX, VrPosY, VrPosZ);
        output.rotation = Quaternion.Euler(VrRotX, VrRotY, VrRotZ);

        return true;
    }
}

Then I added a tracked pose driver on my main camera and I use my Pose provider :

Now I can move my main camera using my Range parameters in my TestTrackedPoseDriver object but I cannot move the maincamera directly :frowning:

forgot to mension a step

1st remove the script and componnent you add

2 Right click in main camera

3 down to " XR "

4 click "Convert main camera to XR RIG

it will add XR Rig GameObject in hierarchy along with a camera offset script, the componnent Tracked Pose Rdiver right in the main camera

Note: Tracked pose Driver support the camera and controller in the first parameter “Device”

Thanks but that do not work in my case :frowning:

ref: https://discussions.unity.com/t/733476/12