0
所以這裏是我的問題,因爲我在一個項目中使用三個js,用戶給出x y
座標一個點被添加到三個js場景,我需要計算碰撞對象的位置/在這一點之前。我試着用Raycaster
,但我無法找到如何使用Raycaster
由點定義的矢量一個簡單的例子:/ 這是我到目前爲止的代碼如何從任意點Raycast
var projector = new THREE.Projector();
var directionVector = new THREE.Vector3();
/* how could i use a vector defined by my origin point
var origin = new THREE.Vector3(x, y, 0);
instead of the camera vector as used below ?
*/
projector.unprojectVector(directionVector, camera);
directionVector.sub(camera.position);
directionVector.normalize();
var ray = new THREE.Raycaster();
ray.set(camera.position,directionVector)
var intersects = ray.intersectObjects(scene.children);
if (intersects.length > 0) {
console.log(intersects);
}
呀很好地工作太感謝你了! :-) – user3491125