Im trying to rotate an object around another object while maintaining its own rotation. I have each objects rotation done im just not sure how to rotate an object around another object. For example I have an array called Planets[Sun,Mercury]. I want the sun to be stationary and allow mercury to rotate around the sun on one axis.
Currently I have the sun and mercury rotating by themselves this is done by: First changing degress to radians.
function degToRad(degrees)
{
return degrees * Math.PI / 180;
}
Then in my drawScene() I rotate the matrix:
mat4.rotate(mvMatrix, degToRad(rCube), [0, 1, 0]);
and then lastly when I animate the scene I move the object using:
var lastTime = 0;
function animate() {
var timeNow = new Date().getTime();
if (lastTime != 0)
{
var elapsed = timeNow - lastTime;
rCube -= (75 * elapsed) / 1000.0;
}
lastTime = timeNow;
}
Is there anyway I can pass an origin point into
mat4.rotate(mvMatrix, degToRad(rCube), [0, 1, 0]);
to make it like:
mat4.rotate(mvMatrix, ObjectToRotateAround, degToRad(rCube), [0, 1, 0]);
I feel as if im not explaining the code I have well. If you wish to have a look it can be found here: https://copy.com/iIXsTtziJaJztzbe