Hi guys,
I’ve got a noob question.
In my scene I have a square mesh and I set the sizes in this way:
this.object.scale.set(200, 200, 1)
When I resize my scene if I use the Perspective camera It keeps the ratio (it remains a square) instead if I use the Orthographic camera It doesn’t keep the ratio but it stretches the mesh.
I set up the cameras in this way:
Perspective
const PerspectiveCamera = (canvas) => {
const fov = (180 * (2 * Math.atan(canvas.offsetHeight / 2 / 800))) / Math.PI
const camera = new THREE.PerspectiveCamera(fov, canvas.offsetWidth / canvas.offsetHeight, 1, 10000)
camera.position.set(0, 0, 800)
return camera
}
Orthographic
const OrthographicCamera = (canvas) => {
var camera = new THREE.OrthographicCamera( canvas.offsetWidth / - 2, canvas.offsetWidth / 2, canvas.offsetHeight / 2, canvas.offsetHeight / - 2, 1, 10 );
camera.position.z = 1
return camera
}
and my resize function is:
if (resizeRenderer(this.renderer, this.parent)) {
const canvas = this.renderer.domElement
this.camera.aspect = canvas.clientWidth / canvas.clientHeight
this.camera.updateProjectionMatrix()
}
where resizeRenderer is a simple resize
const resizeRenderer = (renderer, parent) => {
const canvas = renderer.domElement
const width = parent === window ? parent.innerWidth : parent.getBoundingClientRect().width
const height = parent === window ? parent.innerHeight : parent.getBoundingClientRect().height
const canvasPixelWidth = canvas.width / window.devicePixelRatio
const canvasPixelHeight = canvas.height / window.devicePixelRatio
const needResize = canvasPixelWidth !== width || canvasPixelHeight !== height
if (needResize) {
renderer.setSize(width, height, false)
}
return needResize
}
Have I missed something or this is a normal behaviour ?
Thanks in advance and kind regards,
Davide