vector - three.js get double clicked 3d object -
ciao, trying accomplish this: able know wich 3d object double clicked in scene, , animate camera position bring object in center of screen.
i tried without success adapt interactive cubes example uses raycaster , projector...
http://www.gioblu.com/gio/web/solarsystem/index_backup
as can see can navigate in space , change camera position right , left mouse button. able come initial camera position (earth in center of screen) double click on planet.
why didn't had success adapting example? errors occuring? did mean this example? because raycaster , projector way looking for.
first of need eventlistener ondblclick event on container. in event function can copy&paste linked example:
1) saving mouse coordinates
mouse.x = ( event.clientx / window.innerwidth ) * 2 - 1; mouse.y = - ( event.clienty / window.innerheight ) * 2 + 1;
2) project coordinates world system via camera , create ray
var vector = new three.vector3( mouse.x, mouse.y, 1 ); projector.unprojectvector( vector, camera ); raycaster.set( camera.position, vector.sub( camera.position ).normalize() );
3) check if double clicked element planet
var intersects = raycaster.intersectobject( "your_planet" ); if ( intersects.length > 0 ) { reset camera }
hope helps!
Comments
Post a Comment