0

I'm working on a VR-World. You can turn and tilt the camera in the center of the world, but you can not move the camera around.

In the VR-World you can attach a Video to the background and play it by clicking on it or moving the crosshair over the element.

The video itself has a "normal" state. Like so: Example normal

And a "zoomed" state. Like so: Example zoom

In the zoomed state the video should not be larger than the current viewport. I do have the width and height of the video. How can I calculate the correct size of the video (or depth) to fit the size of the viewport?

I could scale the object on its current position, or I could move the object closer to the camera. I'm open for both options.

I have tried the option mentioned here: Link

let vFOV = this._engine.getCurrentCamera().fov * Math.PI / 180;
let ratio = 2 * Math.tan( vFOV / 2 );
let screen = ratio * (window.innerWidth / window.innerHeight);
let size = this._contentMesh.geometry.boundingBox.max.y;

return (size/screen) / 4;

The result of the example above is way to close at the camera. Do I overlook something?

Thank for your help!

RonH
  • 1
  • 2

1 Answers1

0
let vFOV = this._engine.getCurrentCamera().fov * Math.PI / 180;
let ratio = 2 * Math.tan( vFOV / 2 );
let size = this._contentMesh.geometry.boundingBox.max.y * 2;
return size / ratio;

If you want to set the correct Z position of the object to fit the screen: That's the answer. You can leave out width and height of the Viewport, because it doesn't matter in the calculation.

RonH
  • 1
  • 2