在iPhone上Three.js项目 - 事件的问题(选择并拖动对象)拖动、对象、事件、项目

由网友(从此江山别)分享简介:我有建设项目three.js ......帆布,您可以拖动对象并用摄像机视图发挥好...有一个著名的示例 - 可拖动立方体,还有我的项目是pretty的相似。I have building project with three.js...canvas where you can drag object and...

我有建设项目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;
阅读全文

相关推荐

最新文章