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.
\$\begingroup\$
\$\endgroup\$
1
-
1\$\begingroup\$ What specific difficulty have you encountered in making your satellite orbit its primary? As we've told you before, even if you cannot share literal code, you can walk us through the logical steps you're following. Presumably you've also searched for existing examples of solar systems implemented with OpenGL for inspirations about how to solve this problem? Or consulted tutorials that explain it? \$\endgroup\$DMGregory– DMGregory ♦2021-09-14 12:53:24 +00:00Commented Sep 14, 2021 at 12:53
Add a comment
|
1 Answer
\$\begingroup\$
\$\endgroup\$
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