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

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

问题描述

我有建设项目three.js ......帆布,您可以拖动对象 并用摄像机视图发挥好...有一个著名的示例 - 可拖动立方体, 还有我的项目是pretty的相似。

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个主要活动:鼠标松开/鼠标按下/鼠标移动...

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

好了一切正常....但现在我试图运行在iPhone上这个code,改变了我的事件 与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.

这样的事情应该工作:

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天全站免登陆