javascript - Add inertia to camera controls (Three.js) -


i've setup scene camera remains in fixed point in center of scene. user can pan camera around clicking (and holding) , dragging left mouse button. when user releases left mouse button, motion of camera stops. scene based on 1 of three.js demos see here

there bunch of event handlers used create target position camera lookat:

function ondocumentmousedown( event ) {     event.preventdefault();     isuserinteracting = true;     onpointerdownpointerx = event.clientx;     onpointerdownpointery = event.clienty;     onpointerdownlon = lon;     onpointerdownlat = lat; }  function ondocumentmousemove( event ) {     if ( isuserinteracting === true ) {         lon = ( onpointerdownpointerx - event.clientx ) * 0.1 + onpointerdownlon;         lat = ( event.clienty - onpointerdownpointery ) * 0.1 + onpointerdownlat;     } } 

and in update loop have:

// lat , long have been calculated in event handlers cursor click location   lat = math.max( - 85, math.min( 85, lat ) ); phi = three.math.degtorad( 90 - lat ); theta = three.math.degtorad( lon );  camera.target.x = (500 * math.sin( phi ) * math.cos( theta )); camera.target.y = (500 * math.cos( phi )); camera.target.z = (500 * math.sin( phi ) * math.sin( theta ));  camera.lookat( camera.target ); 

which works expected. when user clicks , drags mouse, camera rotates follow. attempting add inertia movement when user releases left mouse button camera continues rotate in direction of rotation small amount of time.

i have tried tracking change in position of mouse position in drag start , drag end events , try calculate direction of movement based on that, seems convoluted way of doing it

any suggestions on how add inertia camera controls?


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -