Assignment 4: Shape Your World

 

Behold! This assignment will awake the goddess/god in you.

 

This assignment is challenging and enlightening. It will take you on a spiritual journey, question your ability to create worlds and deepen your understanding of the daily problems of higher beings.

It will also make you examine the Diamond Square (DS) algorithm.

You need to re-program or alter JMonkey's version, and upgrade it, passing in defined height-seeds.

 

What does all this mean?

Imagine a 1025x1025 heightfield. The DS algorithm starts to determine heights randomly on resolutions of squares/diamonds of gridsize 1024, 512, 256, ..., i.e. from a coarse to a finer resolution.

An editable heightfield generator pre-defines the coarse terrain resolutions, and continues from there to randomly generate the finer granulated cells in between.

 

As an example, let's say you provide a pre-defined matrix of size 17x17, i.e. all 17x17 height values are set by you. You want to use this matrix to coarsely pre-shape a 1025x1025 heightfield.

This means, in your 1025x1025 heightfield, you set the value of every 64th row/column ( 64*(17-1) = 1024 = 1025-1), with all other cells still being undefined.

Please note, that this is exactly the defined/undefined configuration after the n-th DS step (here: n=6 (2^6 = 64), if every single D and S step is counted). Hence, if you continue a DS algorithm from there, the points in between will be defined, based on your coarse pre-shaping. (To all the people in doubt about how earth was created/developed: you can see this as a hybrid between intelligent design and shaping by nature).

The coarse matrix, which pre-defines the 17x17 height-matrix, should be created using a grey-level image, e.g. colored in paint/photoshop: white = low, black = high (gray levels in between).

 

As if that would not be enough, as a proof of your godly power, I want you to create hail (~ 1000 white spheres of epic diameter), and let it fall down from a random area above the highest peak (add thunder-sound for bonus points).

Of course the hail has to physically correctly trickle down the mountains.

Bonus: create settlements (boxes with pyramid roofs?) in nice places (you can add a plateau creator to make space for settlements).

More bonus: show your mighty hail power by interaction with the settlements.

Even more bonus: be creative. Let people climb up the mountains and slide down the slopes. Fly your camera automatically through the scenery. Let the weather-cam see the world from a falling hail-pellet. Flood your land. Grow fractal trees. Oh, it's only a week...

 

Here is your task in steps:

Starting point: my FractalHeightFieldExample code.

 

1.    you need to examine JMonkey's DS algorithm. It's easy to get into its source when you single step (F7) with a breakpoint at the object instantiation in my example program (Example 10: Fractal height field). Look how it works. At some point, when you followed its trace, it calls the D and S steps. This is where you would break in (there's a 'size' variable, that's the secret which leads to success). Do NOT create multiple independent heightfield-"patches" and put them together, this would not work (if you didn't understand this sentence, don't worry, then you didn't have a wrong idea to begin with). If you go with the JMonkey DS algorithm, which i recommend, you MUST alter it. You can also write your own DS algorithm, but that's a lot of work. Even then, I would recommend to have a look into the JMonkey code (the code is in MidpointDisplacementHeightMap.java, which you find easiest by single-stepping into it. Or find it HERE).

2.    alter the DS code (yours or JMonkey), such that the heightfield in there is preprocessed, i.e. takes an NxN matrix, and distributes its values into the appropriate places

3.    create a predefined NxN matrix, and check if your DS algorithm works

4.    write code that takes an image as input (suggested size: 17x17, but make it variable (of course: power of 2, +1)) and creates the NxN height matrix from it. HERE IS CODE TO READ AN IMAGE AND CONVERT IT INTO AN ARRAY OF GRAYVALUES.

5.    draw an image, and check your code. The resulting (suggested: 1025x1025) fractal heightfield should show the expected structure, with random variations.

6.    Make the planet physical. The lab will show how. Create hail, make it physical. Let there be hail and thunder over the land!

7.    Rest.

8.    (give proof of who's the maker: take a photo of your face, scale it down to 17x17 (or higher, if you want to be recognizable), use it as the input!)

 

 

Good luck. If this one does not impress your friends and family, they are probably atheistic. If they really like the hybrid character of the process, they are probably agnostic.

Enjoy!