Page 1 of 1

Planets and Gravity

Posted: Wed Oct 30, 2013 2:37 am
by andrew.207
Hey guys, I saw a cool gif the other day (friend posted it on FB) and decided to write a simple gravity thing that works across multiple planets.
Image

The math is pretty basic, essentially each planetling grabs the nearest planet and has it's valued modified according to direction and gravity. Slightly different to real life, the gravitational pull gets stronger the further away you are. Pretty C++-ish, with the polymorphism and OO.

Look at the source, learn, modify, make the planetlings bounce off the planet, whatever.

It's fairly quick, on my i5 it can handle about 5000 planetlings before it starts to dip in FPS.

License: http://www.wtfpl.net/

Image

Re: Planets and Gravity

Posted: Wed Oct 30, 2013 2:45 pm
by jjmafiae
WHAT! THIS JUST BLOWN MY MIND! good job!

Re: Planets and Gravity

Posted: Wed Oct 30, 2013 2:58 pm
by shatterblast
The concept is pretty awesome and sweet. It's like a simulated orbit I guess.

Re: Planets and Gravity

Posted: Wed Oct 30, 2013 7:38 pm
by Ranguna259
Could you try something for me, I don't have time to peek into you code right know, but could you make two objects, each one with 'gravity', and make them 'moveable' ? I want to see if they start orbiting around each other, if not it's time to start improving your code to a whole new gravitational physics level :P

And if do that you could test your code with the solar system and maybe we could make an atom simulator, that'd be cool

Re: Planets and Gravity

Posted: Wed Oct 30, 2013 8:20 pm
by andrew.207
No worries, here you go. It doesn't run off Newton's gravitational constant, it runs off whatever number you type in. I picked 80,000, not sure why.

Seems to work ok, the only awkward part was setting the initial velocities so they didn't just whack into each other.

Re: Planets and Gravity

Posted: Thu Oct 31, 2013 12:32 am
by Lafolie
You might want to check out Gravity Ghost by Erin Robinson and friends.

Re: Planets and Gravity

Posted: Thu Oct 31, 2013 6:48 pm
by Ranguna259
WOW this is just awesome, I'm definitely going to look into you code this weekend :rofl:

Keep on doing the incredibly awesome work man ^^