game programming, math and the real world rolf lakaemper, cis, temple university
TRANSCRIPT
![Page 1: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/1.jpg)
Game Programming, Math and the
Real World
Rolf Lakaemper, CIS, Temple University
![Page 2: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/2.jpg)
The Visual World:Modelling Natural Environments
![Page 3: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/3.jpg)
Modelling Natural Environments
Natural environments are needed e.g. in RPG and Strategy Games
Gothic 3,Piranha Bytes
![Page 4: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/4.jpg)
Modelling Natural Environments
Simulation is needed on different levels:Macro-terrain…
Civilization 4,Sid Meier, Firaxis
![Page 5: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/5.jpg)
Modelling Natural Environments
…Mid level (mountains, rocks, clouds)…
Gothic 3,Piranha Bytes
![Page 6: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/6.jpg)
Modelling Natural Environments
…trees, leaves…
Gothic 3,Piranha Bytes
![Page 7: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/7.jpg)
Modelling Natural Environments
Q.: How can we describe a
‘natural’ environment ?
A.: a mathematical description would be helpful
![Page 8: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/8.jpg)
Modelling Natural Environments
‘Visual Math’ = Geometry
Geometry = Euclidean Geometry (really?)
![Page 9: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/9.jpg)
Modelling Natural Environments
An attempt to model nature using
Euclidean geometry
Age of Kingdoms(shareware)
![Page 10: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/10.jpg)
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’ ?
![Page 11: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/11.jpg)
Modelling Natural Environments
New Jersey
![Page 12: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/12.jpg)
Modelling Natural Environments
New Jersey
1.2 miles 1 inchScale ~1:100000
![Page 13: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/13.jpg)
Modelling Natural Environments
Broccoli
![Page 14: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/14.jpg)
Modelling Natural Environments
Coastline 1 (computer generated)
![Page 15: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/15.jpg)
Modelling Natural Environments
Coastline 2 (computer generated)
![Page 16: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/16.jpg)
Modelling Natural Environments
Coastline 3 !
![Page 17: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/17.jpg)
Modelling Natural Environments
Observation 1:
Nature seems to be
self similaron different scales
![Page 18: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/18.jpg)
Modelling Natural Environments
Is self similarity sufficient to describe
nature ?
M.C. Escher:Circle Limits IV
![Page 19: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/19.jpg)
In a certain sense, Eucledian geometry sometimes is self similar, too.
self similar not self similar
What’s missing is some
‘roughness’
Modelling Natural Environments
![Page 20: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/20.jpg)
Modelling Natural Environments
Two waterways
![Page 21: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/21.jpg)
Modelling Natural Environments
Natural or not ?
![Page 22: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/22.jpg)
Modelling Natural Environments
A measure to describe ‘roughness’:
Fractal Dimensions
![Page 23: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/23.jpg)
Modelling Natural Environments
Motivation: Defining Dimensionality
1D: N=2 parts, scaled down bys = ½ = 1/N^(1/1)
2D: N=4 parts, scaled down bys = ½ = 1/N^(1/2)
3D: N=8 parts, scaled down bys = ½ = 1/N^(1/3)
![Page 24: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/24.jpg)
Fractals
We can also state:
N= (1/s)^D
D results from s, N :
D = log(N) / log(1/s)
![Page 25: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/25.jpg)
Fractals
Fractals
D doesn’t have to be integer…
![Page 26: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/26.jpg)
Fractals
Fractals are self similar geometric objects, which have not necessarily
an integer dimension (though their topological dimension is still integer)
![Page 27: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/27.jpg)
Fractals
The simplest: von Koch Snowflake
N=4, r=1/3
![Page 28: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/28.jpg)
What ?
Von Koch Snowflake
![Page 29: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/29.jpg)
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 !)
![Page 30: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/30.jpg)
Fractals
Von Koch Snowflake
It therefore makes sense to define its dimensionality
BETWEEN
one and two !
![Page 31: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/31.jpg)
Fractals
N = 4Scale r = 1/3
D = log(4) / log(3)
D = 1.2619
Intuitive ?
![Page 32: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/32.jpg)
Fractals
This definition of the dimensionality gives us a direct measure for the roughness of self similar objects.
![Page 33: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/33.jpg)
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, …
![Page 34: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/34.jpg)
Fractals
So let’s build fractals with a dimensionality of
x.25 !
![Page 35: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/35.jpg)
Fractals
Algorithms for Random Fractals
![Page 36: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/36.jpg)
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)
![Page 37: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/37.jpg)
Fractals
We will use
MIDPOINT DISPLACEMENT
![Page 38: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/38.jpg)
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. }
}
![Page 39: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/39.jpg)
Fractals
Result:
![Page 40: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/40.jpg)
Fractals
Result:
![Page 41: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/41.jpg)
Fractals
Extension to 2 dimensions:
The Diamond – Square Algorithm
(by Fournier, Fussel, Carpenter)
![Page 42: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/42.jpg)
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
![Page 43: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/43.jpg)
Fractals
Data Structure: (Square) Grid (“Heightfield”)
![Page 44: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/44.jpg)
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.
![Page 45: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/45.jpg)
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.
![Page 46: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/46.jpg)
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.
![Page 47: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/47.jpg)
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 ?)
Diamond Square
![Page 48: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/48.jpg)
Diamond Square
Again:
![Page 49: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/49.jpg)
Diamond Square
Some steps: taken from http://www.gameprogrammer.com/fractal.html#midpoint
![Page 50: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/50.jpg)
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
![Page 51: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/51.jpg)
Diamond Square
Dimension: 2.8
![Page 52: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/52.jpg)
Diamond Square
2.6
![Page 53: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/53.jpg)
Diamond Square
2.5
![Page 54: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/54.jpg)
Diamond Square
2.4
![Page 55: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/55.jpg)
Diamond Square
2.3
![Page 56: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/56.jpg)
Diamond Square
2.2
![Page 57: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/57.jpg)
Diamond Square
2.15
![Page 58: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/58.jpg)
Diamond Square
2.5
![Page 59: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/59.jpg)
Diamond Square
2.8
![Page 60: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/60.jpg)
Diamond Square
Some tricks: power law
![Page 61: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/61.jpg)
Diamond Square
Some tricks: power law
![Page 62: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/62.jpg)
Fractals
Remember ?
Simulation is needed on different levels. There are different
approaches and algorithms to model nature, all of them fractal, all of them taking care of the correct
dimensionality.
![Page 63: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/63.jpg)
Fractals
![Page 64: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/64.jpg)
Fractals
![Page 65: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/65.jpg)
Fractals
![Page 66: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/66.jpg)
Genres
First Fractals in GamesAnd Movies:
![Page 67: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/67.jpg)
Genres
Rescue on FractalusActivision,1986, Spectrum Version
![Page 68: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/68.jpg)
Genres
Star Trek II: The wrath of Khan (1982)
(movie)
![Page 69: Game Programming, Math and the Real World Rolf Lakaemper, CIS, Temple University](https://reader034.vdocument.in/reader034/viewer/2022050820/5697c0051a28abf838cc4b87/html5/thumbnails/69.jpg)
Conclusion:
Fractal Geometry helps to analyze and model the visual
properties of nature.
Breakout