相机跟随对象旋转 [英] Camera following an objects rotation

查看:339
本文介绍了相机跟随对象旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让一个'chase'相机在一个对象上工作。

I'm trying to get a 'chase' camera working on an object.

我发现了一个例子,针对r49:

I've found an example that doe exactly what I want, however it is aimed at r49:

http://stemkoski.github.com/Three.js/Chase-Camera.html

我已尝试将其更新为新的轮播方式如下:

I've attempted to update it to the new rotation methods as follows:


var rotation_matrix = new THREE.Matrix4()。makeRotationZ(rotateAngle);
cube.matrix.multiplySelf(rotation_matrix);
cube.rotation.setEulerFromRotationMatrix(cube.matrix);

这似乎对物体工作正常,但是相机没有以同样的方式。我在这里举了一个演示:

This seems to work fine for the object, however the camera doesn't follow in the same way. I've put up a demo here:

http:// jsfiddle.net/SSEDs/

(按A和D旋转)

什么是我做错了?

推荐答案

您需要将相机添加为多维数据集的子级。它不仅工作,而且数学更简单。

You need to add the camera as a child of the cube. Not only does it work, but the math is a lot simpler.

cube.add( camera );

这里是更新的小提琴: http://jsfiddle.net/SSEDs/1/

Here is an updated fiddle: http://jsfiddle.net/SSEDs/1/ .

小提琴使用three.js r.50。
单击画布获得焦点,然后按键A和D.

The fiddle is using three.js r.50. Click on the canvas to get the focus and then press keys A and D.

这篇关于相机跟随对象旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆