简体   繁体   English

相机的位置在添加到网格中时不会改变

[英]Camera's position not changing when added to a mesh

I want to realise a little TPS (the camera follow the player). 我想了解一点TPS(相机跟随播放器)。 I add the camera to a cube ( wich represents the players when he moves), and show the coordinates of the camera and the cube in : this fiddle . 我将相机添加到一个立方体中(以玩家移动时代表玩家),并在: 小提琴中显示相机和立方体的坐标。 The Camera is following the cube as well, but you can see that the camera coordinates are not changing. 摄像头也跟随立方体,但是您可以看到摄像头坐标没有变化。 There is no problems but when i want to use the picking, the coordinates are wrong because it depends on the camera. 没问题,但是当我要使用拾取时,坐标是错误的,因为它取决于相机。

I just do that : 我只是这样做:

cube.add(Camera);

Somebody have an idea ? 有人有主意吗?

When you add the camera to the cube, you make it a child object. 将相机添加到多维数据集后,便使其成为child对象。 The coordinates of a child are local coordinates relative to their parent (as are the scale and rotation), so they do not change when the parent (the cube) moves. 子项的local coordinates 相对于其父项的 local coordinates (缩放和旋转也是如此),因此当父项(立方体)移动时,它们不会更改。

What you want to know are the world coordinates of the camera. 您想知道的是相机的world coordinates There is no direct property for those as Three.js only stores the complete world matrix , but it does offer a nice helper function to extract it from that matrix: 这些没有直接属性,因为Three.js仅存储完整的世界矩阵 ,但是它确实提供了一个很好的帮助函数,可以从该矩阵中提取它:

var cameraPosition = new THREE.Vector3();
cameraPosition.setFromMatrixPosition(Camera.matrixWorld);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM