Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I currently have an earth and a moon. What I'm trying to achieve is to have the moon physically rotate around the earth horizontally along the equator along a circular path.

    moonAngle = (moonAngle + 0.5f) % 360f;
    xPath = (float) Math.sin(Math.toRadians(moonAngle)) * distance;
    yPath = (float) Math.cos(Math.toRadians(moonAngle)) * distance;

    gl.glTranslatef(xPath, yPath, -30f);

The above works fine, except the moon is rotating around the earth vertically around the Prime Meridian like a wall clock. How do I adjust the angle of rotation? I've tried modifying the glTranslatef, but with no success.

share|improve this question
What do you mean, exactly, with horizontal and vertical rotation? The first thing that comes to my mind with "horizontal rotation" is the rotationing at the start of this video: – Mutoh Jan 13 '13 at 23:07
Aren’t you just confusing Y and Z in the glTranslatef call? – sam hocevar Jan 13 '13 at 23:42
@SamHocevar The problem is that I'm trying to maintain the z-position of -30f at the same time why moving along the X and Z paths which is also the same position as the zPosition as the earth. This way if I move the Earth along the zAxis, the moon will update accordingly as well. – ChocoMan Jan 13 '13 at 23:56
@ChocoMan Then you might want to try gl.glTranslatef(xPath, 0f, yPath-30f);. But most of all you want to remove hardcoded values and use named variables for the Earth position. – sam hocevar Jan 14 '13 at 0:13
Okay, I made it into an answer, but I think the question is a bit too localised for the site. – sam hocevar Jan 14 '13 at 1:09
up vote 2 down vote accepted

The Y offset you are computing should actually be applied to the Z axis:

gl.glTranslatef(xPath, 0f, yPath - 30f);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.