Juju's Planet Model v28
A project to explore procedural generation
- Title: Planet Model
- Description: Procedural generation example
- GM Version: Studio
- Registered: yes
- File Type: gmz and exe in a .zip
- File Size: 2.3 MB
- File Link: here
- Required Extension: none
- Required DLL: none
Key features include:
- Geodesic hex tiling - a first for GameMaker
- Real-time procedural generation that doesn't freeze the game
- Six-degrees of freedom using quaternions
- Detailed terrain engine
- Nifty little window system that allows for windows-within-windows
- Smooth frame rate throughout
In the spirit of open-source development, I'd like to share with you lot a project I've been working on for a few weeks. Ever since I laid eyes upon Planetarium, a closed-source pseudo-3D world generator made in GameMaker, I knew I wanted to make something experimental in the world generation area. I've been fascinated by world generation in general for years but only recently have had the confidence to approach something that not even the Civilization series has touched.
Geodesic domes are a way to tile a sphere with regular shapes, you may be familiar with them as they're used quite frequently for futuristic biodomes. It's not perfect but it's as close as you can mathematically get. The method is actually quite straightforward: you take a 20-sided polyhedron (i.e. a d20 die), you subdivide each triangle a few times, and then you gather up 6 adjacent triangles that share a point and call that a hexagon. Some locations (exactly twelve, actually) will be pentagons, unfortunately, but that's the price you pay. Thematically speaking, you can explain that away and simply block off those locations with big mountains! This web of hexagons can then be treated as a surface and standard procedural generation techniques can be applied to get the desired result.
Of course, this process of subdivision, collection and generation isn't instant. After the first subdivision, you have 60 triangles. Then it grows to 180, 540, 1620... at seven subdivisions, you have an eye-watering 43'740 triangles! The triangle collection and terrain generation algorithms take just as long. As a result, each step of the generation system is broken down piece by piece so that the frame rate doesn't drop crazy low. There's no awkward pause and no real loading screen - though in this stripped-down example, there's not a lot for the user to do whilst the generator is working its magic.
Part of dealing with a fully 3D model, quite different to virtually every strategy game ever made, is that the player needs to be able to explore every nook and cranny of the world. This is where a mathematical tool knowns as quaternions come in handy. Now, I'm no expert on quaternions but fortunately an old example by a chap named Boris helped me out a lot. Links to his work are included in the comments on the quaternion scripts. The rotation around the globe is fluid and completely free. You can swoop down and check out my ropey modelling skills or lean back and look at the whole globe.
There's also a neat little window system that plays nicely alongside d3d functions, an accurate in-built system that finds what tile the player is pointing at (harder than it sounds), and the terrain generator itself. These things can be flipped around and used in other projects too - they operate quite independently and there is commenting throughout.
All this stuff is absolutely free for you to use and base your games off, no credit needed (though it is appreciated). If you'd like to keep up-to-date with this engine's development, hop on over to GameMaker's Reddit community at /r/gamemaker.
Edited by Juju, 23 March 2016 - 12:07 AM.