问题描述
限时送ChatGPT账号..我有一个固定位置的透视相机,可以通过键盘输入围绕所有 3 个轴旋转.以随机间隔,独立于用户输入,我需要将对象放置在相机的视野内,无论相机朝哪个方向看.对象还需要从相机的 fov 中心偏移特定的 x 和 y 距离,并从相机的位置偏移特定的 z 距离.我不能使用 camera.addChild 因为一旦添加了对象,我需要通过独立于相机移动的补间移动对象.
I have a fixed-position, perspective camera that rotates around all 3 axes via keyboard input. At random intervals, independent of user input, I need to place objects within the camera's field of view no matter what direction the camera is looking. The objects will also need to be offset specific x and y distances from the center of the camera's fov and offset a specific z distance from the camera's position. I cannot use camera.addChild because once the object is added I need to move the object via tweening independent of the camera's movements.
如何做到这一点?
推荐答案
您想将一个点从相机空间转换到世界空间.
You want to transform a point from camera space to world space.
在相机的坐标系中,相机位于原点,向下看它的负 z 轴.
In the camera's coordinate system, the camera is located at the origin, and is looking down its negative z-axis.
将物体放在相机前面(在相机的坐标系中).
Place the object in front of the camera (in the camera's coordinate system).
object.position.set( x, y, - z ); // z is the distance in front of the camera, and is positive
现在,将对象的位置从相机空间转换到世界空间:
Now, transform the object's position from camera space to world space:
object.position.applyMatrix4( camera.matrixWorld );
three.js r.69
three.js r.69
这篇关于Three.js 在旋转相机的 fov 中放置一个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论