Three.js 在旋转相机的 fov 中放置一个对象

编程入门 行业动态 更新时间:2024-10-28 17:14:16
本文介绍了Three.js 在旋转相机的 fov 中放置一个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-30 14:46:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1395667.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   相机   js   fov

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!