iPhone上的Three.js项目-事件问题(选择并拖动对象) [英] Three.js project on iPhone - events issue (select&drag object )

查看:203
本文介绍了iPhone上的Three.js项目-事件问题(选择并拖动对象)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有three.js的项目...画布,您可以在其中拖动对象 并同时使用相机视图进行播放...有一个著名的示例-可拖动的多维数据集" 好吧,我的项目非常相似.

I have building project with three.js... canvas where you can drag object and play with the camera view as well... there is a famous example- "Draggable Cubes", well my project is pretty similar.

在我的项目中,有3个主要事件:mouseup/mousedown/mousemove ...

On my project there are 3 main events: mouseup /mousedown/ mousemove...

一切都还好....但是现在我试图在iPhone上运行此代码,更改事件 与touchstart/touchmove/touchend ...

Well everything was ok....but now I'm trying to run this code on iPhone,changing my events with touchstart / touchmove / touchend...

移动对象功能似乎工作正常,但是当我尝试通过单击鼠标来选择对象时, 它总是被选中的对象...而不是我指向的对象....

The moving object function seems to work fine, but when I'm trying to select the object by clicking him, it's always the same object that been selected... and not the one I'm pointing on....

我想问题出在这个功能上

I guess the problem is with this function:

function onDocumentMouseDown( event ) {

            event.preventDefault();

            var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
            projector.unprojectVector( vector, camera );

            var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );

            var intersects = ray.intersectObjects( objects );

            if ( intersects.length > 0 ) {

                SELECTED = intersects[ 0 ].object;

                var intersects = ray.intersectObject( plane );
                offset.copy( intersects[ 0 ].point ).subSelf( plane.position );

            }
}

有人知道出什么问题吗?

Is anybody have an idea what is the problem?

推荐答案

在此行中:

var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );

您使用鼠标的Vector2对象,但未初始化它.

You use the mouse Vector2 object but you don't initialize it.

类似的东西应该可以工作:

Something like this should work :

mouse.x = +(event.targetTouches[0].pageX / window.innerwidth) * 2 +-1;

mouse.y = -(event.targetTouches[0].pageY / window.innerHeight) * 2 + 1;

这篇关于iPhone上的Three.js项目-事件问题(选择并拖动对象)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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