1 / 69

Modeling Natural Environments for RPG and Strategy Games

Explore the mathematical description of natural environments for games, including fractals and Euclidean geometry. Learn how to simulate various elements to achieve a realistic in-game world.

Download Presentation

Modeling Natural Environments for RPG and Strategy Games

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University

  2. The Visual World: Modelling Natural Environments

  3. Modelling Natural Environments Natural environments are needed e.g. in RPG and Strategy Games Gothic 3, Piranha Bytes

  4. Modelling Natural Environments Simulation is needed on different levels: Macro-terrain… Civilization 4, Sid Meier, Firaxis

  5. Modelling Natural Environments …Mid level (mountains, rocks, clouds)… Gothic 3, Piranha Bytes

  6. Modelling Natural Environments …trees, leaves… Gothic 3, Piranha Bytes

  7. Modelling Natural Environments Q.: How can we describe a ‘natural’ environment ? A.: a mathematical description would be helpful

  8. Modelling Natural Environments ‘Visual Math’ = Geometry Geometry = Euclidean Geometry (really?)

  9. Modelling Natural Environments An attempt to model nature using Euclidean geometry Age of Kingdoms (shareware)

  10. Modelling Natural Environments Let’s have a look at nature to see why Euclidean geometry fails. Q.: What makes the appearance of objects in nature ‘natural’ ?

  11. Modelling Natural Environments New Jersey

  12. Modelling Natural Environments Scale ~1:100000 1.2 miles 1 inch New Jersey

  13. Modelling Natural Environments Broccoli

  14. Modelling Natural Environments Coastline 1 (computer generated)

  15. Modelling Natural Environments Coastline 2 (computer generated)

  16. Modelling Natural Environments Coastline 3 !

  17. Modelling Natural Environments Observation 1: Nature seems to be self similar on different scales

  18. Modelling Natural Environments Is self similarity sufficient to describe nature ? M.C. Escher: Circle Limits IV

  19. Modelling Natural Environments In a certain sense, Eucledian geometry sometimes is self similar, too. self similar not self similar What’s missing is some ‘roughness’

  20. Modelling Natural Environments Two waterways

  21. Modelling Natural Environments Natural or not ?

  22. Modelling Natural Environments A measure to describe ‘roughness’: Fractal Dimensions

  23. Modelling Natural Environments Motivation: Defining Dimensionality 1D: N=2 parts, scaled down by s = ½ = 1/N^(1/1) 2D: N=4 parts, scaled down by s = ½ = 1/N^(1/2) 3D: N=8 parts, scaled down by s = ½ = 1/N^(1/3)

  24. Fractals We can also state: N= (1/s)^D D results from s, N : D = log(N) / log(1/s)

  25. Fractals D doesn’t have to be integer… Fractals

  26. Fractals Fractals are self similar geometric objects, which have not necessarily an integer dimension (though their topological dimension is still integer)

  27. Fractals The simplest: von Koch Snowflake N=4, r=1/3

  28. What ? Von Koch Snowflake

  29. Fractals Von Koch Snowflake Iterating the snowflake algorithm to infinity, the boundary of the 1d snowflake becomes part of the 2d AREA of the plane it is constructed in (take it intuitively !)

  30. Fractals Von Koch Snowflake It therefore makes sense to define its dimensionality BETWEEN one and two !

  31. Fractals N = 4 Scale r = 1/3 D = log(4) / log(3) D = 1.2619 Intuitive ?

  32. Fractals This definition of the dimensionality gives us a direct measure for the roughness of self similar objects.

  33. Fractals Interestingly, studying nature shows that a fractal roughness of ~x.25 (x=1,2,3,…) seems to be found everywhere, and perceived by humans a ‘natural’ Coastlines, clouds, trees, the distribution of craters on the moon, microscopic ‘landscapes’ of molecules, …

  34. Fractals So let’s build fractals with a dimensionality of x.25 !

  35. Fractals Algorithms for Random Fractals

  36. Fractals Random fractals: In contrast to exact self similar fractals (e.g. the Koch snowflake), also termed as deterministic fractals, an additional element of randomness is added to simulate natural phenomena. An exact computation of fractals is impossible, since their level of detail is infinite ! Hence we approximate (i.e we stop the iteration on a sufficient level of detail)

  37. Fractals We will use MIDPOINT DISPLACEMENT

  38. Fractals A 1D example to draw a mountain : Start with a single horizontal line segment. Repeat for a sufficiently large number of times { Repeat over each line segment in the scene { Find the midpoint of the line segment. Displace the midpoint in Y by a random amount. Reduce the range for random numbers. } }

  39. Fractals Result:

  40. Fractals Result:

  41. Fractals Extension to 2 dimensions: The Diamond – Square Algorithm (by Fournier, Fussel, Carpenter)

  42. Fractals Data Structure: Square Grid • Store data (efficiently) in 2D Array. • Modification is very trivial. • Not possible to define all terrain features. • Good for Collision detection

  43. Fractals Data Structure: (Square) Grid (“Heightfield”)

  44. Diamond Square The basic idea: Start with an empty 2D array of points. To make it easy, it should be square, and the dimension should be a power of two, plus one (e.g. 33x33). Set the four corner points to the same height value. You've got a square.

  45. Diamond Square This is the starting-point for the iterative subdivision routine, which is in two steps: The diamond step: Take the square of four points, generate a random value at the square midpoint, where the two diagonals meet. The midpoint value is calculated by averaging the four corner values, plus a random amount. This gives you diamonds when you have multiple squares arranged in a grid.

  46. Diamond Square Step 2: The square step: Taking each diamond of four points, generate a random value at the center of the diamond. Calculate the midpoint value by averaging the corner values, plus a random amount generated in the same range as used for the diamond step. This gives you squares again.

  47. Diamond Square This is done repeatedly, but the next pass is different from the previous one in two ways. First, there are now four squares instead of one. Second, and this is main point: the range for generating random numbers has been reduced by a scaling factor r, e.g. r = 1/4 (remember the fractal dimension ?)

  48. Diamond Square Again:

  49. Diamond Square Some steps: taken from http://www.gameprogrammer.com/fractal.html#midpoint

  50. Diamond Square The scaling factor r, determining the range of random displacement R, defines the roughness ( => fractal dimension !) of the landscape. Some examples for diff. r and R R(n+1) = R(n) * 1 / (2^H), 0 < H < 1

More Related