Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

aspect ratio for orthographic camera views incorrect upon window resize #185

Open
kfarr opened this issue May 20, 2023 · 3 comments
Open

Comments

@kfarr
Copy link
Contributor

kfarr commented May 20, 2023

there is a mechanism to recalculate the correct aspect ratio for perspective camera when window is resized, the same mechanism should exist for otho camera views (plan view and cross section)

@vincentfretin
Copy link
Contributor

You can listen to the aframe rendererresize event on sceneEl.
Example:

init() {
  this.width = 1;
  this.height = 1;
  this.size = new Vector2();
  this.rendererresize = this.rendererresize.bind(this);
  if (this.el.sceneEl.renderer) this.rendererresize();
  this.el.sceneEl.addEventListener("rendererresize", this.rendererresize);
},
rendererresize() {
  this.el.sceneEl.renderer.getSize(this.size);
  this.width = this.size.x;
  this.height = this.size.y;
  this.annotationRenderer.setSize(this.width, this.height);
},

@vincentfretin
Copy link
Contributor

I see this is also an issue in my project and aframe-inspector
The aspect ratio is done here in aframe-inspector
https://github.com/aframevr/aframe-inspector/blob/575c9106e26b41c714cc369b55c4db861315d7a0/src/lib/viewport.js#L205-L209 initially after creating the viewport so only doing inspector.camera that is the perspective camera initially. But this windowresize is not emitted afterward anywhere so the aframe resize listener is taking care of that in
https://github.com/aframevr/aframe/blob/66baa9c8128caf9199e8a773ca4d637a25947d06/src/core/scene/a-scene.js#L598-L599

Actually this windowresize event is not even needed at all, because after creating the viewport it calls this.open() that calls this.sceneEl.resize(); and before creating the viewport, we set the camera and perspective camera is the active camera.

For ortho camera, the https://github.com/aframevr/aframe/blob/66baa9c8128caf9199e8a773ca4d637a25947d06/src/core/scene/a-scene.js#L598-L599 code is executed as well but setting aspect has no effect, what we really need is modifying left and right and call updateProjectionMatrix()
https://github.com/aframevr/aframe-inspector/blob/575c9106e26b41c714cc369b55c4db861315d7a0/src/lib/cameras.js#L53-L54

@vincentfretin
Copy link
Contributor

Modifying left and right is not enough, I tried to do something like camera.left * (ratio / info.prevRatio) but it's worse, scene is distorted when zooming int/out. I don't know where the issue is. There is probably something I don't understand about ortho camera.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants