2011-11-19 85 views
1

我爲mouseMove和mouseDown寫了兩個非常類似的函數。雖然前者工作正常,後者繼續從var intersects = ray.intersectScene(scene)獲取空對象。three.js intersectScene獲取空對象

您可以在這裏找到完整的代碼 http://converteveryunit.com/pot/biluochun/temp/ 謝謝。

function onDocumentMouseMove(event) { 

    mouseX = event.clientX - homeWidth/2; 
    mouseY = event.clientY - homeHeight/2; 

    var vector = new THREE.Vector3((event.clientX/homeWidth) * 2 - 1, - (event.clientY/homeHeight) * 2 + 1, 0.5); 
    projector.unprojectVector(vector, camera); 

    var ray = new THREE.Ray(camera.position, vector.subSelf(camera.position).normalize()); 

    var intersects = ray.intersectScene(scene); 
} 


function onDocumentMouseDown(event) { 

    event.preventDefault(); 

    var vector = new THREE.Vector3((event.clientX/homeWidth) * 2 - 1, - (event.clientY/homeHeight) * 2 + 1, 100); 
    projector.unprojectVector(vector, camera); 

    var ray = new THREE.Ray(camera.position, vector.subSelf(camera.position).normalize()); 

    var intersects = ray.intersectScene(scene); 
    console.log(intersects); 

    } 

回答

0

我並不十分熟悉three.js所,但我不禁想知道爲什麼你的載體具有在第一功能0.5 100以第二Z分量。如果一個人工作,另一個不工作,那當然感覺像是一個體面的開始。