delta3d

The dtTerrain Tutorial, Part 3 - Load Your Terrain

In part 1 we discussed the architecture and technology behind dtTerrain and in part 2 the process involved in writing a dtTerrain reader, renderer and decorator. For this section we will concentrate on writing and running a dtTerrain application.

1. Examining the testTerrain Application

We start off by adding the correct headers to our source file.


#include <dtTerrain/terrain.h>
#include <dtTerrain/dtedterrainreader.h>
#include <dtTerrain/soarxterrainrenderer.h>
#include <dtTerrain/vegetationdecorator.h>

You will notice that I have added a reader, renderer and a decorator. These are required in order to create a functioning dtTerrain application.

In your application you will need to create the Terrain object and pass in a cache path. The cache path will contain all of the processed terrain tile data to optimize consequent runs over individual tiles. This is the way it looks in testTerrain.


//Create our terrain and add a reader and renderer to it.
mTerrain = new dtTerrain::Terrain();
mTerrain->SetCachePath(mCachePath);

We have to create an instance of our terrain reader. In this case we are using the DTED reader we examined previously.


//Create the terrain reader...
dtTerrain::DTEDTerrainReader *reader = new  dtTerrain::DTEDTerrainReader();

We have to create an instance of our terrain renderer. In this case we are going to use the SOARX terrain renderer we examined previously.


//Create the terrain renderer...
dtTerrain::SoarXTerrainRenderer *renderer = new dtTerrain::SoarXTerrainRenderer();

Now add the reader and the renderer to the terrain object.


//Connect our reader and renderer to the terrain.
mTerrain->SetDataReader(reader);
mTerrain->SetDataRenderer(renderer);

Great! So far we have created our terrain object and added our reader and renderer. Now we need to create and add our decoration layer. The following decoration layer was extended from the base TerrainDecorationLayer abstract class. Essentially the vegetation decorator will calculate the position and transform of objects and then add them to an osg group node to be returned to our terrain.


// Add a decoration layer
mVeg = new dtTerrain::VegetationDecorator;

Since we included the vegetation decorator letís quickly define some properties that make it function correctly.


mLCCType = CreateLCCType();  
mVeg = new dtTerrain::VegetationDecorator;

// Configure the vegetation
mVeg->SetRandomSeed(27);
mVeg->SetVegetationDistance(14000.0f);
mVeg->SetLoadDistance(15000.0f);
mVeg->SetMaxObjectsPerCell(5000);

Ah you may be askingÖ what exactly is an LCCType and how do I go about creating one? Well thatís an excellent question. The vegetation uses land classification data to define the types of trees, bushes, etc. we need added to the terrain. Since we want the ability to add different models and classification types to our vegetation we have an LCCType method.

So really quick create a vector of LCCTypes and then add them to the vegetation layer.


std::vector<dtTerrain::LCCType> LCCType;

dtTerrain::LCCType water(11,"water");
water.SetRGB(110,130,177);

dtTerrain::LCCType lowResidential(21,"low residential");
lowResidential.SetRGB(253,229,228);
lowResidential.SetSlope(0,20,1);
lowResidential.SetElevation(5,2000,1);
lowResidential.SetRelativeElevation(0,80,1);
lowResidential.SetAspect(255);
lowResidential.AddModel("models/house0.ive");
lowResidential.AddModel("models/house1.ive");

dtTerrain::LCCType highResidential(22,"high residential");
highResidential.SetRGB(247,178,159);
highResidential.SetSlope(0,20,1);
highResidential.SetElevation(5,2000,1);
highResidential.SetRelativeElevation(0,80,1);
highResidential.AddModel("models/house2.ive");

dtTerrain::LCCType industrial(23,"industrial");
industrial.SetRGB(157,186,0);
industrial.SetSlope(0,20,1);
industrial.SetElevation(5,2000,1);
industrial.SetRelativeElevation(0,80,1);
industrial.SetAspect(225);
industrial.AddModel("models/industry0.ive");
industrial.AddModel("models/industry1.ive");
industrial.AddModel("models/industry2.ive");

Wow you created your vector of LCCTypes, now go ahead and add it to the vegetation decorator.


// Add the LCCTypes
mVeg->SetLCCTypes(mLCCType);

After you have added the various properties that pertain to your decorator, you will need to add it to the terrain object. The can be accomplished simply by the following code.


// Add the vegetation decoration layer to our terrain
mTerrain->AddDecorationLayer(mVeg);

Now the only thing left is to add the terrain resource to the terrain. The terrain resource path is the location of your terrain data. Take note that the terrain supports an unlimited number of resource paths.


// Load the terrain resource
mTerrain->LoadResource(mResourcePath);

Depending on what your delta3d application looks like youíll need to add the terrain object to either your camera or environment object.


// Add the terrain to our environment
mEnv->AddChild(mTerrain.get());

The above code snippets are the basic tools you need in order to create dtTerrain in a Delta3D application.

2. The Terrain in Action

The following image displays DTED data rendered by the SOARX Renderer. Note that the background is not a skybox; the distant terrain that merges with the horizon is in fact real terrain data. Amazing that you can see so far into the distance isnít it? Check it out for yourself, load up your DTED data and start walking!!!

The next image shows what happens when we zoom in on a seemingly uninteresting section of the terrain. It looks like the tessellation is pretty lowÖ doesnít it? Well take a look at the next image!

Wow! Look what happens when we turn up the tessellation. This not only creates a much smoother contour of our landscape but also increases the level of detail. This is the SOARX renderer at itís finest. The ability to dynamically change the tessellation of terrain is one of the reasons SOARX is so powerful.

You can check out the testTerrain application that is included in the Delta3D distribution. If you need help on how to run this application you can download the readme.txt off the delta3d website.

You can download all the code for this tutorial here
Note: This file is probably out of date and may/may not compile and run as-is.

This concludes our in depth look at the architecture, implementation, and technology that has formed the bases of the Delta3D Terrain API. I hope you enjoyed the read!

Click here to return to the main tutorial page.

Trackback

Trackback URL for this entry: http://delta3dengine.org/trackback.php?id=20051013154207563

No trackback comments for this entry.

About delta3d

delta3d is a game and simulation engine appropriate for a wide variety of simulation and entertainment applications. delta3d uses best-of-breed open source technologies to create a fully integrated game engine and with content creation tools.MORE

Twitter

User Functions





Don't have an account yet? Sign up as a New User!

Lost your password?