javascript - Rotating a vector around a sphere (simulating sun) in three.js -


i trying adapt this code (which implementation of this). have gotten general visualization , rendering work, i'm trying animate realistic movement.

the point of light source determined normalized vector (for example three.vector3(1, 0.75, 0). light appear coming top right). have vector rotate around sphere in such way seems sphere orbiting light source. can't figure out how this. i've tried updating/changing position of vector. i'm not sure how calculate proper next x,y,z values. i've tried applying euler angles , rotational matrix, so:

euler = new three.euler(f,g,h, 'xyz'); matrix = new three.matrix4().makerotationfromeuler(euler); light = vector.applymatrix4(matrix); 

but here, i'm not sure how correct values of f,g,h such light doesn't wobble around sphere.

am on right track?

working example: http://jsfiddle.net/vswb9/3890/

you increasing linearly 2 of 3 coordinates in euler angles, issue.

for other rotations around x/y/z axis, best understanding/avoiding issues/coding/computational cost trust quaternions.

they rather intuitive, in threejs too. made of 4 coordinates : 3 rotation axis, , fourth rotation value.

var quat=new three.quaternion();  //we set axis around rotation occur. needs normalized var axis=new three.vector3(0,1,0).normalize(); //and angle value (radians) var angle=0;  //this light vector (=original position of light) var light=new three.vector3(1,0,0).normalize(); 

then in render loop change angle value , tell quaternion use axis above, , updating angle :

angle+=.001//(or angle -= if axis points in +y direction here) quat.setfromaxisangle(axis,angle); 

and apply :

light.applyquaternion(quat); 

updated fiddle : http://jsfiddle.net/atrahasis/0v93p2xy/


note normalized vectors :

  • a normalized vector 1-unit length.
  • ( 1 , 0 , 0 ),( 0 , 1 , 0 ),( 0 , 0 , 1 ) native-normalized vectors (and unit vectors).
  • ( 1 , .75 , 0 ) not normalized vector, length √(1²+.75²)=1.5625 (pythagoras)
  • for example ( 0.6614... , .75 , 0 ) normalized vector

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -