iPhone 上的 Three.js 项目 - 事件问题(选择&拖动对象)
我有一个使用 Three.js...canvas 构建项目,您可以在其中拖动对象 并玩弄相机视图......有一个著名的例子 - “Draggable Cubes”, 我的项目非常相似。
在我的项目中,有 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 );
}
}
有人知道问题是什么吗?
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.
On my project there are 3 main events: mouseup
/mousedown
/ mousemove
...
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这一行中:
您使用鼠标 Vector2 对象,但没有初始化它。
像这样的东西应该有效:
in this line :
You use the mouse Vector2 object but you don't initialize it.
Something like this should work :