Three.js place an object in rotating camera's fov

醉酒当歌 提交于 2019-12-11 16:20:52

问题


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.

How can this be done?


回答1:


You want to transform a point from camera space to world space.

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



来源:https://stackoverflow.com/questions/26910120/three-js-place-an-object-in-rotating-cameras-fov

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!