Bor*_*isD 2 javascript iphone 3d javascript-events three.js
我用three.js ... canvas构建项目,你可以用相机视图拖动对象和玩法......有一个着名的例子 - "可拖动立方体",我的项目非常相似.
在我的项目中有3个主要事件:mouseup/mousedown/mousemove ...
好吧一切都很好....但现在我正试图在iphone上运行此代码,用touchstart/touchmove/touchend改变我的事件......
移动对象功能似乎工作正常,但是当我试图通过点击他来选择对象时,它总是与被选中的对象相同...而不是我指向的对象....
我想问题是这个功能:
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 );
}
}
Run Code Online (Sandbox Code Playgroud)
有谁知道问题是什么???
小智 7
在这一行:
var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
Run Code Online (Sandbox Code Playgroud)
您使用鼠标Vector2对象但不初始化它.
这样的事情应该有效:
mouse.x = +(event.targetTouches[0].pageX / window.innerwidth) * 2 +-1;
mouse.y = -(event.targetTouches[0].pageY / window.innerHeight) * 2 + 1;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
754 次 |
| 最近记录: |