I am currently looking for a way to have an object orbit the vector coordinates 0,0,0. For instance if the object is located at X300,Y50,Z200 than I would like it to revolve
Using the following code allows an object to move in a circular pattern.
function orbitRight() {
var x = thisObj.position.x;
var z = thisObj.position.z;
thisObj.position.x = x * Math.cos(.02) - z * Math.sin(.02);
thisObj.position.z = z * Math.cos(.02) + x * Math.sin(.02);
}
Well an orbit implies you have an axis. (0, 0, 0) is just a point in 3D space, so you'll need either another point ( -3, 8, 4 ) to then create a normalized axis from. If you use a Three.js Object3D
you can simply normalize the objects.up
property. But I digress, here's a simple vector example:
var startPoint = new THREE.Vector3( 0, 0, 0 );
var axisVector = new THREE.Vector3( -3, 8, 4);
var endPoint = new THREE.Vector3( 300, 50, 200 );
var rotation = 0.05;
var axis = startPoint.clone().sub(axisVector).normalize();
endPoint.applyAxisAngle( axis, rotation );
Here's a fiddle using two cubes instead of bare Vector3
's here Hope that helps!