javascript - THREE.js - Rotate the camera just like trackball controls -


i'm using trackball controls in scene , want implement function rotate camera way dragging mouse in canvas it. how can accomplish that? i've been looking code of trackball control module, can't find start.

edit: i've been looking several pages, 3 documentation , whatnot, still can't reproduce trackball style rotation. i've been using quaternions can't reproduce behavior(or i'm missing something, probably). help?

edit 2 : i'm looking way this:

function rotatecam(angle) { // code }  var angle = 0.01; //some value rotatecam(angle); $('#button').addeventlistener('mousedown', function() { rotatecam(angle); } ); 

where button html element representing button.

i noticed trackball controls, apart of rotate via quaternion, zoom correct distances. tried read code, , got this:

function rotate(l) {     var vector = controls.target.clone();     var l = (new three.vector3()).subvectors(camera.position, vector).length();     var = camera.up.clone();     var quaternion = new three.quaternion();      // zoom correction     camera.translatez(l - l);      quaternion.setfromaxisangle(up, 0.015);     camera.position.applyquaternion(quaternion);     camera.lookat(vector);     renderer.render(scene, camera); } 

works charm...hope find useful too. ;)


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -