Creating a terrain with Perlin noise
In this recipe, we will learn how to construct a surface in 3D using Perlin noise to create organic deformations that resemble a piece of terrain.
Getting ready
Include the necessary files to draw using OpenGL, Perlin noise, a Maya camera for navigation, and Cinder's math utilities. Add the following code to the top of the source file:
#include "cinder/gl/gl.h" #include "cinder/Perlin.h" #include "cinder/MayaCamUI.h" #include "cinder/CinderMath.h"
Also, add the following using
statements:
using namespace ci; using namespace ci::app; using namespace std;
How to do it…
We will create a grid of 3D points and use Perlin noise to calculate a smooth surface.
Declare
struct
to store the vertices of the terrain by adding the following code before the applications class declaration:struct Vertice{ Vec3f position; Color color; };
Add the following members to the applications class declaration:
vector< vector<Vertice> > mTerrain; int mNumRows, mNumLines...