Im trying to build a model for the solar system in OpenGl, and I got the planets to move around the sun, but can't get the satellites to move around their planet. I can't share my code since this an university assignment, but my current 'orbiting' angle is 2 * glm::radians(180.0f) * (time / body.orbitPeriod) , where time is a constant that is given to us, body is the planet and .orbitPeriod is how long it takes for a planet to complete an orbit.


Same code for orbiting a planet around the sun, just replace the position of the sun with that of the planet you want to revolve around. Here's a simple 2D example using degrees, I imagine you're calculations are a bit different but might give you some idea.

angle = 360 * ((time %% satellite.orbitPeriod) / satellite.orbitPeriod)

satellite.x = body.x + COS(angle) * satellite.orbitDistance
satellite.y = body.y + SIN(angle) * satellite.orbitDistance

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.