0
votes

I know this question has been asked many times and answered, but I'm currently having no luck with any of the answers I've followed (mainly this one Mouse / Canvas X, Y to Three.js World X, Y, Z).

I've gotten object selection done and working the code I am using is as follows

onMouseMove:function(event)
{
    event.preventDefault();

    var scope       =   Game.GSThree,
        $container  =   $(scope.container.element),
        width       =   $container.width(),
        height      =   $container.height(),
        vector,
        ray,
        intersects;

    scope.mouse.x   =   (event.clientX - scope.container.padding.left) / width * 2 - 1;
    scope.mouse.y   =   - (event.clientY / height) * 2 + 1;
    scope.mouse.z   =   0.5;
    vector          =   new THREE.Vector3(scope.mouse.x , scope.mouse.y , scope.mouse.z);
    ray             =   scope.projector.pickingRay(vector.clone() , scope.camera);
    intersects      =   ray.intersectObjects(scope.tiles.children);

    if(intersects.length)
    {
        var hovered = intersects[0].object;
        scope.selectObject(hovered);
    }
}

This works fine, but actually I need to also know the exact world coordinates of my current mouse position. I am not sure if the solutions I've tried hold true for the orthographic camera, which is what I am using. If I log either scope.mouse.x or vector.x these do not give the world coordinates, ray finds the objects perfectly fine, but I don't know how to get the current coordinates of the ray in the world.

1
I posted an answer here: stackoverflow.com/a/48068550/882912KTCO

1 Answers

1
votes

I think what you are looking for is:

intersects[0].point;