围绕X轴旋转相机(three.js) [英] Rotating camera around the X-axis (three.js)

查看:1250
本文介绍了围绕X轴旋转相机(three.js)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将相机旋转到场景的X轴。

此时,我的代码如下:

I am trying to rotate the camera around to X-axis of the scene.
At this point my code is like this:

rotation += 0.05;
camera.position.y = Math.sin(rotation) * 500;
camera.position.z = Math.cos(rotation) * 500;

这使得相机移动,但在旋转期间奇怪的事情发生和相机翻转,

This makes the camera move around but during the rotation something weird happens and either the camera flips, or it skips some part of the imaginary circle it's following.

推荐答案

您只提供了一段代码,所以我必须做一些假设您正在做什么。

You have only provided a snippet of code, so I have to make some assumptions about what you are doing.

此代码:

rotation += 0.05;
camera.position.x = 0;
camera.position.y = Math.sin(rotation) * 500;
camera.position.z = Math.cos(rotation) * 500;
camera.lookAt( scene.position ); // the origin

将导致您所指的翻转,因为相机试图保持

will cause the "flipping" you refer to because the camera is trying to remain "right side up", and it will quickly change orientation as it passes over the "north pole."

如果你像这样偏移摄像机的x坐标,

If you offset the camera's x-coordinate like so,

camera.position.x = 200;

相机行为会对您更自然。

the camera behavior will appear more natural to you.

这篇关于围绕X轴旋转相机(three.js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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