Rotating around a moving point

Trying to get some solar system action going (not really, but similar mechanics) with three.js. I have code that kinda works but seems far from elegant. Also, the whole adding and subtracting the position business is off.

What would be the proper way to do this? I don’t think I can use a dummy object (see #1593) in this program because the center point may change during runtime.


The crucial pieces are:

mat1 = new THREE.Matrix4();
axis = new THREE.Vector3();
axis.sub(two.position, one.position);
axis.crossSelf(new THREE.Vector3(1,0,0));
mat1.makeRotationAxis(axis, 0.005);

and in animate():


renderer.render( scene, camera );


Pardon my ignorance, I’m new to 3d.

Author: Fantashit

1 thought on “Rotating around a moving point

  1. It’s much simpler than that… 🙂

    // init
    var sun = new THREE.Mesh( sunGeometry, sunMaterial );
    scene.add( sun );
    var earthPivot = new THREE.Object3D();
    sun.add( earthPivot );
    var earth = new THREE.Mesh( earthGeometry, earthMaterial );
    earth.position.x = 1000;
    earthPivot.add( earth );
    // update
    earthPivot.rotation.y += 0.1;

Comments are closed.