Mouse coordinates irrelevant after zooming, is it bug?

天涯浪子 提交于 2019-12-18 09:45:13

问题


I have a problem about getting the mouse coordinates, it behaves irrelevant after zooming.

I have a JS fiddle link of my code, it will show what the problem I face, is it bug in three.js or the way I approach to draw a line is wrong, please give your feedback.

http://jsfiddle.net/ebeit303/ceej4jxq/1/

var elem = self.renderer.domElement,
                boundingRect = elem.getBoundingClientRect(),
                x = (e.clientX - boundingRect.left) * (elem.width / boundingRect.width),
                y = (e.clientY - boundingRect.top) * (elem.height / boundingRect.height);
var vector = new THREE.Vector3((x / $("container").width()) * 2 - 1, -(y / $("container").height()) * 2 + 1, 0.5);
var pos = projector.unprojectVector(vector, camera);

var dir = pos.clone().sub(camera.position).normalize().multiplyScalar(-1);
var distance = camera.position.z / dir.z;     
var pos1 = camera.position.clone().sub(dir.multiplyScalar(distance));

Thanks in advance..


回答1:


Your camera near plane in your fiddle is 0.0001, and your camera far plane is 10,000,000,000.

Consequently, you are having numerical problems in your code when you call unprojectVector().

The issue is closely related to the depth buffer precision problems described here: http://www.opengl.org/wiki/Depth_Buffer_Precision.

Set your near plane to 1, or greater, and your far plane to the smallest value you can get away with, say 10000.

three.js r.68



来源:https://stackoverflow.com/questions/26049182/mouse-coordinates-irrelevant-after-zooming-is-it-bug

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