0
我在three.js中制作了一个射手,其中出现了用户必须射击的球体。 拍摄一个球体后,该物体消失,另一个球体弹出。我正在使用指针锁定控件。相对于三分之一球体中心的轨迹精度
我发现当球被使用镜头:
function onDocumentMouseDown(event) {
var mouse3D = new THREE.Vector3();
var raycaster = new THREE.Raycaster();
mouse3D.normalize();
controls.getDirection(mouse3D);
raycaster.set(controls.getObject().position, mouse3D);
var intersects = raycaster.intersectObjects(objects);
// Change color if hit sphere
if (intersects.length > 0) {
intersects[ 0 ].object.material.color.setHex(Math.random() * 0xffffff);
//hide shpere
object.traverse(function(child){child.visible = false;});
update_sphereplace();
}
}
这工作完全,但现在我要整合的精度特性。 我如何跟踪基于球体中心的精度?因此,例如,击中中心应该给我一个100的准确度。击中距离中心相对较远的球体应该给出接近0的准确度(但不是0,因为0会丢失球体)。
提示:创建一个'Raycaster'和[重复使用] (http://stackoverflow.com/questions/29311875/three-js-pointerlockcontrols-shooting-along-y-axis/29312773#29312773)。 – WestLangley
感谢您的建议。这将如何工作?我只是'var raycaster = new THREE.Raycaster();'onDocumentMouseDown'函数的外部,还是有更多的? – binoculars