javascript - Three.js world coordinates from mouse position with Orthographic camera -
i know question has been asked many times , answered, i'm having no luck of answers i've followed (mainly 1 mouse / canvas x, y three.js world x, y, z).
i've gotten object selection done , working code using 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, need know exact world coordinates of current mouse position. not sure if solutions i've tried hold true orthographic camera, using. if log either scope.mouse.x
or vector.x
these not give world coordinates, ray
finds objects fine, don't know how current coordinates of ray in world.
i think looking is:
intersects[0].point;
Comments
Post a Comment