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
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
Any help could be appreciated.