# Rotating an object around a rotating object

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.

## 1 Answer

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