2
votes

I'm trying to find the ray collision coordinate relative to the face targeted...

code:

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 ]);

With intersects[ 0 ].point, I can have the mouse position in 'screen coordinate', but how can I have it in Cylinder coordinate ? PS: mesh are not rotate, but camera can change position...

Really nice framework ;)

1

1 Answers

0
votes

Here is my solution, just get the Cylinder absolute coordinate (position relative to screen), then, itersects[0].point sub the Cylinder absolute coordinate. The following code may help:

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

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

    return offset.addSelf(relativeTo(element.parent, ancestor));
}