I am building 3D solar system containing (sun > earth > moon).
I have difficult to add the part which the moon rotate around earth.
I separated between "moon" and other stars.
The problem is that the center of earth is not const like the sun.
I know that earth is in starsList[1] so I thought to translate the moon to this place but got weird result..
Someone have an idea how to do this?
mat4.identity(mvMatrix);
mat4.translate(mvMatrix, [0, 0, z]);
for (i = 0; i < starsList.length; i++) {
mvPushMatrix();
if (starsList[i].name == "moon"){
/////////
mat4.rotate(mvMatrix, degToRad(starsList[i].angle), [0, 1, 0]);
mat4.translate(mvMatrix, starsList[1].initPlace);
mat4.rotate(mvMatrix, degToRad(starsList[i].angle), [0, 1, 0]);
////////
}
else{
mat4.rotate(mvMatrix, degToRad(starsList[i].angle), [0, 1, 0]);
mat4.translate(mvMatrix, starsList[i].initPlace);
mat4.rotate(mvMatrix, degToRad(starsList[i].angle), [0, 1, 0]);
}
mvPopMatrix();
}