我正在尝试找到相对于目标脸部的光线碰撞坐标...
代码:
var fMouseX = (iX / oCanvas.width) * 2 - 1;
var fMouseY = -(iY / oCanvas.height) * 2 + 1;
//I Use OrthographicCamera
var vecOrigin = new THREE.Vector3( fMouseX, fMouseY, - 1 );
var vecTarget = new THREE.Vector3( fMouseX, fMouseY, 1 );
oProjector.unprojectVector( vecOrigin, this.__oCamera );
oProjector.unprojectVector( vecTarget, this.__oCamera );
vecTarget.subSelf( vecOrigin ).normalize();
var oRay = new THREE.Ray(vecOrigin, vecTarget);
intersects = oRay.intersectObjects([ oCylinderMesh ]);
使用intersects [0] .point,我可以将鼠标放在'screen coordinate'中,但是如何在Cylinder坐标中获得它? PS:网格不旋转,但相机可以改变位置......
非常好的框架;)
答案 0 :(得分:0)
这是我的解决方案,只需获取Cylinder绝对坐标(相对于屏幕的位置),然后itersects [0] .point sub the Cylinder绝对坐标。 以下代码可能有所帮助:
var relativeTo = function(element, ancestor) {
var offset = element.position.clone();
if (element.parent == ancestor) {
return offset;
}
return offset.addSelf(relativeTo(element.parent, ancestor));
}