• Register

OOK, Once I Owned a Kestrel, is now being revamped. Previously, it was to be released solely on iPhone and iPad. Now, iPhone, iPad, and other mobile devices are dropped and it will be primarily a desktop project. Welcome to the new OOK. Enjoy.

Report RSS The Procedurally Generated OOK Galaxy (And the joys of shaders)

Since the last update I have done a number of things. First off, the physics is 100% working, entities are more well defined, and basic controls are functioning. You can now fly around empty space no-problem. I also defined some basic spawning functions as ease-of-use utilities. Nothing fancy there...

Posted by on

Since the last update I have done a number of things. First off, the physics is 100% working, entities are more well defined, and basic controls are functioning. You can now fly around empty space no-problem. I also defined some basic spawning functions as ease-of-use utilities. Nothing fancy there. One last small thing I did was created a bit more of the resource loader so that I could start adding ships with the aid of the developer mode I mentioned previously.

The two more interesting things that I have done include figuring out how to procedurally generate the galaxy and using shaders to create a simply parallax effect for the space background...

In the past I created the space background by rendering a bunch of polygons and shifting them depending on the player's coordinates. To create a parallax effect (see here) I rendered a couple different layers with different offsets. However, now that I have added support for GLSL shaders, I realized that I could simplify things. With only one polygon and one texture, by retrieving texels of two different parts of the image each offset by the players position differently I was able to create the same effect. The shader is super basic with excellent results. Already using shaders has paid off!

Now the fun stuff. I explored the web a bit for equations to graph the curve of a galaxy. I found just the equation:

r(t)=(s*a)/(1-a*tan(a)*log(t/a))
s=scale
a=angle or amount of spin


Simple enough, right? Yep. I used JavaScript initially with an HTML5 canvas so that I could play with the settings until they looked right. I then generated point clouds along the line. Finally, I spawned points around each point to represent planets. The final result, plus some eye candy (drop shadows):

Dl.dropbox.com

Notice that each star is represented by a 2px by 2px dot, while each planet around it is represented by a 1px by 1px dot. You may be wondering why star systems are overlapping. "WHAT THE HELL!?" It would be ridiculously big if I represented the galaxy at its actual scale in the browser, so for the visual representation I scaled it down and scaled up the star system size a bit. The final product, once I convert it to C, will be far larger with systems highly spaced out.

Finally, I would like to note that galaxies consist of billions to trillions of stars. OOK is not that big of a game. I will not be generating a trillion stars. This will have to suffice.

Stay tuned.

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: