2016-09-08 1 views
0

장면을 클릭 할 때마다 호출하고 있습니다. 내가 더 회전을 클릭 작품을 적용하지 않은,하지만 곧 내가RayCaster는 camera.lookAt()를 호출 할 때 객체 감지를 멈 춥니 다.

scope.target.x = offset * Math.sin((scope.phi + iphi) * Math.PI/180) * Math.cos((scope.theta + itheta) * Math.PI/180); 
scope.target.y = offset * Math.cos((scope.phi + iphi) * Math.PI/180); 
scope.target.z = offset * Math.sin((scope.phi + iphi) * Math.PI/180) * Math.sin((scope.theta + itheta) * Math.PI/180); 

scope.camera.lookAt(scope.target); 

RayCaster 전화로 물건을 반환하지 않는 초기

function onMouseDown(event) { 
    controls.update(); 
    var position = new THREE.Vector3(); 
    position.setFromMatrixPosition(scene.group.children[0].matrixWorld); 
    position.normalize(); 
    console.log(position); 

    var raycaster = new THREE.Raycaster(); // create once 
    var mouse = new THREE.Vector2(); // create once 

    mouse.x = (event.clientX/renderer.domElement.width) * 2 - 1; 
    mouse.y = - (event.clientY/renderer.domElement.height) * 2 + 1; 
    //console.log(mouse); 

    raycaster.setFromCamera(mouse, camera); 

    console.log(raycaster.ray.direction); 

    var intersects = raycaster.intersectObjects(scene.group.children , false); 
    if (intersects.length > 0) { 
     intersects[ 0 ].object.material.color.set(0xff0000); 
     console.log(intersects); 
    } 
} 

.

나는 또한 레이 큐레이터가 회전 후에도 화면의 동일한 위치에서 같은 방향의 벡터를 제공한다는 것을 알게되었습니다.

그럼 내가 raycaster 수동으로

var e = new THREE.Euler(((controls.phi-90)/180)*Math.PI, 0, (controls.theta/180)*Math.PI, 'XYZ'); 
raycaster.setFromCamera(mouse, camera); 
raycaster.ray.direction.applyEuler(e); 

에 회전을 적용하려고했지만 지금은 물체의 정확한 위치에 있지으로 가까운 위치에 교차로를 얻을.

답변

0

문제는 내가 업데이트되지 하였다 세계는 카메라 업데이트에 대한

camera.updateMatrixWorld(); 

이 문제를 해결 호출 카메라 회전에 따라 조정합니다.

관련 문제