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.

  • \$\begingroup\$ 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: youtube.com/watch?v=LoQYw49saqc \$\endgroup\$
    – Mutoh
    Jan 13 '13 at 23:07
  • 3
    \$\begingroup\$ Aren’t you just confusing Y and Z in the glTranslatef call? \$\endgroup\$ Jan 13 '13 at 23:42
  • \$\begingroup\$ @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. \$\endgroup\$
    – ChocoMan
    Jan 13 '13 at 23:56
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Jan 14 '13 at 0:13
  • 1
    \$\begingroup\$ Okay, I made it into an answer, but I think the question is a bit too localised for the site. \$\endgroup\$ Jan 14 '13 at 1:09

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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