简体   繁体   中英

Three.js world coordinates from mouse position with Orthographic camera

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.

I think what you are looking for is:

intersects[0].point;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM