Jump to content

  • Log In with Google      Sign In   
  • Create Account

Crawling with ideas

World in 7 days, Days 2, 3 and 4: Stars and planetary systems

Posted by , in worldin7days 27 February 2014 - - - - - - · 762 views
worldin7days, programming, unity and 2 more...
I haven't updated in long time but this doesn't mean I haven't worked. In fact, I am splitting my work hours between this project and GAMIFICATOR™ ;) and I'm now on day 4 of making world.

Currently my galaxy can hold up to 5.4 * 10^13 stars (that's a lot). You can check out the most current version HERE (click me), the seed is set so no voice-created universes for you. The interface is clunky, sometimes it gets stuck (reload if that happens), and sometimes it generates gas giants next to the sun, with couple dozen earth sizes in diameter, and a fraction of its mass. But we're not here to nitpick, are we? We're here to generate UNIVERSES Posted Image.

So, let's do a writeup of what has happened so far (with sprinkle of pretty pictures):

What I had previously was looking pretty, but ultimately doomed to fail, as it had no level of detail progression. Which means I was limited by the amount of stars in the galaxy. Bad thing. I've started working on it, and had some pretty funky results:

Posted Image

Finally I have created really nifty looking galaxy:

Posted Image

That's more like it, but still not good enough. I needed to walk away from prettyfying, and move back towards optimisation, to allow the amount of stars that I wanted (granted, this galaxy would be more than enough for what one person can experience). So I've started implementing octree. It took me majority of Day 2, and I was left with something that visualised to this:

Posted Image

Ooh, pretty colours. Still, it didn't feel right. On third day I sat with my good friend Theo, and implemented non-persistent node implementation, that created node ID based on its location and depth, and created seed out of that. This allowed for repeatable generation of data without the need to store the data structure. The seed code looks like this:
    void FillOutNode(int x, int y, int z, int depth)
    {
        ulong mask = 0xffffffffful << (nodeDepth - depth);

        float minX = (float)((ulong)x & mask);
        float minY = (float)((ulong)y & mask);
	float minZ = (float)((ulong)z & mask);

	float length = 1 << (nodeDepth - depth);
        ulong nodeID = FindNodeIDBin (x, y, z, depth);
        int currentSeed = nodeID.GetHashCode() + universeSeed.GetHashCode();
        Random.seed = currentSeed;
                
        // STUFF HAPPENS HERE
    }
      
    ulong FindNodeIDBin(int x, int y, int z, int depth)
	{
		ulong mask = 0xffffffffful << (nodeDepth - depth);
		return ((ulong)depth << 36) | (((ulong)x & mask) << 24) | (((ulong)y & mask) << 12) | (((ulong)z & mask) << 0);
	}
Neat, eh? Well, this gave me neat spatial partitioning:

Posted Image

Rest of the day was spent on adding space navigation (ooh sexy starjump code) and starting to add proper star data generation, which continued into day four:

Posted Image

And on day four I've added planet generation:

Posted Image

Well, that's what I have so far, going into day 5, on which I'll focus on moving into planetary system mode. So far the problem is following: To allow for enough precision, I had to position the stars at pretty close locations. Going into planetary system will mean that the precision will need to be insanely higher (if we're to allow, say, visiting planets, which is the goal of this whole exercise). Smooth transitioning between different speeds will be interesting, but I think I can make it. That means also displaying of the planets and sun, which will also be fun ;).

I'll also want to do an update on GAMIFICATOR© some time before the end of the week, but don't know if I'll have time to do it. I reserved time on Sunday and Tuesday evenings for it, so that progression doesn't stop. So far so good Posted Image. The GAMIFICATOR (patent pending) started as a tool to help me become productive, and I've spent more time polishing it and being productive on it than with any other recent projects. I guess it's serving its purpose even before it's finished ;).

So, again, I hope I'll find some time to develop some more.

See you then!

===========================================================================================
Story so far:

Days 2, 3 and 4: Stars and planetary systems
Day 1: Galaxies


World in 7 days, Day 1: Galaxies

Posted by , in Programming, worldin7days 27 January 2014 - - - - - - · 903 views
programming, worldin7days and 4 more...
The thing that drew me to programming was simple: ability to create. I always loved travels, adventures and discovering the undiscovered. I used to watch this old 60s cartoon called Jonny Quest, about boy having adventures, but when I looked out the window, I only saw blocks of flats in my city, and couldn't imagine that this was possible any more, so I spent time playing with my computer. When I was bit older Cartoon Network ran a reimagining of those stories - The Real Adventures of Jonny Quest. And they had adventures IN COMPUTER!

Posted Image

Now, this later on was looked down upon as not being able to stand the test of time, but for me it was always amazing. After I saw the first episode I bought 'C++ in 24 hours' and started writing an OS/AI/VR system (do keep in mind that I was young ;) ). Obviously it didn't do much except for saying 'hello, mantis!', but it set me on a road to where I am now.

Later on I've picked up the subject of creating worlds couple times, with changes in complexity and scope. I have done some basic ROAMing planets and atmospheric scattering, but I've never put it together into a coherent project. When I was finishing my last project though, I've bumped yet another time to blog of a guy who created the most amazing planets that I ever saw - Journal of Ysaneya. Now, these days his screenshots are down, which is a real shame, because they were AMAZING. Just reading the names of the entries gave me idea, why not do what I always wanted to do? Well, the complete world is a complex piece of engineering, and seeing how Ysaneya worked on his projects for couple years and I'll be wanting to finish mine in 7 days, there will have to be some compromises. Nevertheless, I set out on a journey, and am awaiting with curiosity where it will take me.

The scope is following:

1) I want to generate at least one galaxy
2) That galaxy needs to have proper amount of stars (I'm talking billions here)
3) Each star needs to be blue, white, yellow, orange, red or brown dwarf
4) Each star may have planets around it
5) Planets may have atmosphere/water (the M-class planet, to use Star Trek terminology. I'm not a big ST buff, but I like their naming convention)
6) Planets with atmosphere/water may have plants

Soooo.

How would I divide the work:

Day 1) Shaping of galaxy, preparing density maps
Day 2) Dividing galaxy into octree, allowing for tens (or hundreds?) of billions of stars
Day 3) Go to planetary system mode, create orbits for planets, display planet/sun
Day 4) Create proper terrain on the planets
Day 5) Create atmospheric effects
Day 6) Create L-system plants
Day 7) Polish (rest?)

Yeah, I don't get any smarter or less optimistic in my estimates. But I decline to give in Posted Image

Without further ado,

DAY 1:

Posted Image

I've started by playing around with Unity and figuring out a way to most efficiently represent thousands of stars. After short deliberation I chose the new ParticleSystem. I could access all the particles as an array, and tweak their parameters. I've looked up the wikipedia article on star types, and noticed something which surprised me: most of the stars aren't in fact white, but white are just that much more visible. Which meant that Ysaneya's approach to generating galaxies (using octree to look up stars depending on their colour) made sense. Well, that much I didn't doubt.

To generate correct shape I have combined a bell curve with the equation of:
float a = 2;
float b = 2;
float c = 0.7f;
float d = 0;
float e = 2.71828f;
					
probability = Mathf.Pow (a * e, -((dist * b)*(dist * b)) / (2 * c * c) + d);
and a picture that I have drawn in GIMP

Posted Image

To get the following result:

Posted Image

You can also see 'record' 'stop' and 'play' buttons there. What do they do? Well, your voice is your key: I take the recording sample, get its hash value, and pass it as a Random's seed value. That means that each person will have his own personal universe, unique to himself (or as close to unique as the hash function allows).

Basically, this means you can create universe by saying 'BE!' ;)

That's it for tonight! See you soon!

===========================================================================================
Story so far:

Days 2, 3 and 4: Stars and Planetary Systems
Day 1: Galaxies





December 2016 »

S M T W T F S
    12 3
45678910
11121314151617
18192021222324
25262728293031