2

我试图找到相对于目标面部的射线碰撞坐标......

代码:

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,我可以将鼠标位置置于“屏幕坐标”中,但如何将其置于 Cylinder 坐标中?PS:网格不旋转,但相机可以改变位置......

非常好的框架;)

4

1 回答 1

0

这是我的解决方案,只需获取 Cylinder 绝对坐标(相对于屏幕的位置),然后 itersects[0].point sub Cylinder 绝对坐标。以下代码可能会有所帮助:

var relativeTo = function(element, ancestor) {
    var offset = element.position.clone();

    if (element.parent == ancestor) {
        return offset;
    }

    return offset.addSelf(relativeTo(element.parent, ancestor));
}
于 2013-01-14T07:23:51.493 回答