Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
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
Not the answer you’re looking for? Browse other questions tagged 3d rotate or ask your own question.