缩放后鼠标坐标无关,是bug吗? [英] Mouse coordinates irrelevant after zooming, is it bug?

查看:18
本文介绍了缩放后鼠标坐标无关,是bug吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在获取鼠标坐标时遇到问题,缩放后它的行为无关紧要.

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

我有我的代码的 JS 小提琴链接,它会显示我面临的问题,是 three.js 中的错误还是我画线的方式错误,请给出您的反馈.

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));

提前致谢..

推荐答案

你的相机near平面是0.0001,你的相机far平面是10,000,000,000.

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

因此,当您调用 unprojectVector() 时,您的代码中存在数字问题.

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

该问题与此处描述的深度缓冲区精度问题密切相关:http://www.opengl.org/wiki/Depth_Buffer_Precision.

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

将您的近平面设置为 1 或更大,并将您的远平面设置为您可以摆脱的最小值,例如 10000.

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

three.js r.68

这篇关于缩放后鼠标坐标无关,是bug吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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