简体   繁体   English

在Three.js中使用轨道控制旋转相机时发生奇怪的晃动

[英]Strange shaking while rotating the camera with Orbit Controls in Three.js

I'm making a model of the Solar System. 我正在制作太阳系的模型。 This is my current metric: 这是我目前的指标:

scale = 0.001;
// 1 unit - 1 kilometer
var AU = 149597871 * scale;

This is how i define the camera, renderer and controls: 这就是我定义相机,渲染器和控件的方式:

camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1 * scale, 0.1 * AU);
renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
controls = new THREE.OrbitControls(camera, renderer.domElement);

Then i give the user the option to jump between the objects so this is how i set the camera after user selects a planet/moon: 然后,我为用户提供了在对象之间跳转的选项,因此这是在用户选择行星/月球之后设置摄像机的方式:

function cameraGoTo() {
    for (var i = scene.children.length - 1; i >= 0 ; i--) {
        var obj = scene.children[i];
        if (obj.name == parameters.selected) {
            controls.target = obj.position;
            camera.position.copy(obj.position);
            camera.position.y += obj.radius * 2;
        }
    }
}

The problem is that for small planets/moons ( <= 1000 km in radius) camera is shaking while rotating around the object. 问题在于 ,对于小行星/月球(半径<= 1000 km),相机在围绕物体旋转时会抖动。 I have only basic knowledge of computer graphics so i don't know either this is the problem of Orbit Controls or it has something to with renderer itself...so I've tried to set logarithmicDepthBuffer = true but it didn't help. 我只有计算机图形学的基本知识,所以我不知道这是Orbit Controls的问题,还是它与渲染器本身有关……所以我尝试将logarithmicDepthBuffer = true设置logarithmicDepthBuffer = true但没有帮助。 Also trying different scale didn't change anything. 尝试不同的scale也没有任何改变。

Thank in advance for any help/clues. 在此先感谢您的帮助/提示。

EDIT: 编辑:

Here's the fiddle: http://jsfiddle.net/twxyz/8kxcdkjj/ 这是小提琴: http : //jsfiddle.net/twxyz/8kxcdkjj/

You can see that shaking increases with any of the following: 您可以看到以下任何一种情况都会增加抖动:

  • the smaller the object, 对象越小
  • the further the object from the point of origin, 物体离原点越远,

What is the cause of this? 这是什么原因? It clearly seems it has nothing to do with the camera near/far spectrum values but is related to the distance the objects are from the center of the scene. 显然,这似乎与相机的近/远光谱值无关,但与物体离场景中心的距离有关。

I've come up with the solution. 我已经提出了解决方案。

My problem was with the floating point precision errors when dealing with objects far from the point of origin . 我的问题是处理远离原点的对象时出现浮点精度错误。 This turns out to be a very known problem and there are various solutions. 事实证明这是一个众所周知的问题,并且有各种解决方案。 I've used this one: 我已经使用了这个:

http://answers.unity3d.com/questions/54739/any-solution-for-extreamly-large-gameworlds-single.html http://answers.unity3d.com/questions/54739/any-solution-for-extreamly-large-gameworlds-single.html

What happens is basically instead of moving the camera/player, we transform whole scene relative to the camera/player that is always at the point of origin. 发生的事情基本上是代替移动相机/播放器,而是相对于始终位于原点的相机/播放器变换整个场景 In this case, Orbit Controls' target is always point of origin. 在这种情况下,Orbit Controls的目标始终是原点。

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

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