Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Math A帧/三适合屏幕-计算缩放_Math_Three.js_Webgl_Aframe_Quaternions - Fatal编程技术网

Math A帧/三适合屏幕-计算缩放

Math A帧/三适合屏幕-计算缩放,math,three.js,webgl,aframe,quaternions,Math,Three.js,Webgl,Aframe,Quaternions,我想把相机放大三倍/一帧,这样图像就适合屏幕了 这是我正在使用的代码: this._camera = document.getElementById('camera').getAttribute('camera') this._ratio = this._assetWidth/this._assetHeight this._vFOV = window.THREE.Math.degToRad( this._camera?.fov || 80 ) this._he

我想把相机放大三倍/一帧,这样图像就适合屏幕了

这是我正在使用的代码:

    this._camera = document.getElementById('camera').getAttribute('camera')
    this._ratio = this._assetWidth/this._assetHeight

    this._vFOV = window.THREE.Math.degToRad( this._camera?.fov || 80 )

    this._height = 2 * Math.tan( this._vFOV / 2 ) * this.data.distance
    this._width = this._height * this._ratio

    this._zoom = this._ratio > 1 ? this._width/window.innerWidth : this._height/window.innerHeight

    console.log(this._zoom,  this._ratio, this._width, window.innerWidth)
我已经到了需要计算缩放的部分,以便对象适合屏幕,也就是说,如果它的横向适合宽度,如果它的纵向适合高度

我想,但事实并非如此。这是为了计算相机位置,而不是缩放值

我被你如何计算缩放值所困扰


有什么线索吗?

通过以下方式将对象安装到屏幕上:

  • 改变摄像机视场
  • 放大照相机
  • 重新定位摄影机/对象
一旦你了解了公式的来源,情况就非常相似了。
我们将使用这个整洁的图像(),因为它涵盖了所有三个主题:

0。我们想要实现什么

我们希望对象(其宽度或高度的较长一侧)覆盖
胶片高度
——以便适合屏幕

1。重新计算视野

在这种情况下,我们确实知道
焦距
(相机与物体的距离)和
胶片高度
(物体宽度或高度)。感谢我们的朋友,我们可以计算
fov/2

Tan(视野/2)=(胶片高度/2)/focalLength

=>
fov=2*ATan((胶片高度/2))/focalLength*180/PI


AFRAME.registerComponent(“fit”{
init:function(){
常量平面=document.querySelector(“a平面”)
常量距离=此.el.object3D.position.distanceTo(plane.object3D.position)
var height=plane.getAttribute(“几何体”).height
var newFov=2*Math.atan((高度/2)/距离)*(180/Math.PI);//以度为单位
this.el.sceneEl.camera.fov=newFov
}
})

由于
a-frame
管理窗口/画布的大小调整,因此我认为没有必要使用窗口宽度/高度。至少当我改变一个窗口大小时,它似乎能正常工作。这是一个惊人的答案@Piotr@beek你没有任何评论就接受了答案,我担心答案是“嗯,很好”,我真的很高兴如果它有帮助,事实上你的问题让我查了一下,并试图理解它背后的数学。这是史上最好的答案!这意味着我可以看到哪个解决方案效果最好,并相应地进行调整!非常感谢你的帮助!