True-to-Life Terrain

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
mruno
Posts: 4
Joined: Thu Dec 22, 2011 1:45 am

True-to-Life Terrain

Post by mruno »

Hello -

I'm starting work on a flight simulator, and I've got a bit of a hangup in getting my terrain to match the scale and values of the real life equivalents. I generated a heightmap (http://db.tt/TQcs1CmP for the map itself) from the National Elevation Dataset, and would like to use it to generate the terrain for the part of the earth I'm currently flying over. When I get close to the end of a given map, I was simply going to load the next one and position it along the edge..

Will this work? Can I just load heightmaps as I go and make it seamless to the user? Is there a better way to do this?
Also, if this will work, I can't seem to get the scales correct. For example, I know that the tallest mountain around is 11,000 feet or so.. but I get 14,000 and some change in my render. I was setting the scales using 1 px = 98 feet or so (30 meters from the raw data documentation), and then multiplying that since I reduced the raw heightmap by a factor of 2 in the X and Y dimensions.

Additionally, I get the 14,000' mountain if I use 98 as a scale. If I use 197 (as below) I seem to only get a flat mesh with no mountains.

The code is almost exactly the Terrain example at this point, since I wanted to prove this would work before going on a big custom program.

I tried searching for "real life terrain" and "terrain scale" etc.. but nothing particularly useful came up :(

This is how I'm creating my TerrainSceneNode.

Code: Select all

// add terrain scene node
        scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
               "/Users/mruno/Desktop/N37W116.bmp",
              0,                                    // parent node
              -1,                                   // node id
              core::vector3df(0.f, 0.f, 0.f),               // position
              core::vector3df(0.f, 0.f, 0.f),               // rotation
              core::vector3df(197.f, 197.f, 197.f), // scale
              video::SColor ( 255, 255, 255, 255 ), // vertexColor
              5,                                    // maxLOD
              scene::ETPS_17,                               // patchSize
              10                                    // smoothFactor
          );
 
I'm printing out the height of the camera AGL (eg.. the plane's altitude) and the height of the terrain by doing this

Code: Select all

 
int height = terrain->getHeight(camera->getAbsolutePosition().X,
                                            camera->getAbsolutePosition().Z);
int cameraHeight = camera->getAbsolutePosition().Y;
int altitudeAGL = cameraHeight - height
 
I'd appreciate any help, even if it's just "hey noob, search using this term: ____".
mruno
Posts: 4
Joined: Thu Dec 22, 2011 1:45 am

Re: True-to-Life Terrain

Post by mruno »

I was able to get the terrain working, but still having issues with scale. I had exported the BMP using Pixelmator, and Irrlicht doesn't seem to like that. When I export it from Gimp it works. Interesting..

Still trying to work through having the mountains scale properly though.
Katsankat
Posts: 178
Joined: Sun Mar 12, 2006 4:15 am
Contact:

Re: True-to-Life Terrain

Post by Katsankat »

Hello, I am working on exactly the same things. Interesting.

Can I just load heightmaps as I go and make it seamless to the user?

Yes they will tile properly, if the heightmaps themselves are seamless (forget SRTM1). By the size of your file I assume it is from SRTM2, 1 arc/second, right? Note this bmp is not a bmp it can't be displayed. Irrlicht thinks it is a bmp and the bmp file loader fails. Choose another extension like hgt or raw depending if it was processed by you or not. Since it has 16 bits per pixel terrain->loadheightmapRaw() should work.

However let's be careful on the amount of data to load between frames, even if they are loaded in a separate thread because there are several tiles to load. 129X129 sized heightmaps are good candidates -even lower is better- not to mention the texture has to be loaded too, so png and jpg are respectively good choices. Hall ways 2^n+1 for width, and square images will avoid many strange problems.

I can't seem to get the scales correct

You want 197X scale yes why not. Try 128 or 256. Too big will make it flicker... Here they are scaled 512,16,512. The scale and width are used to calculate the position of each tile so experiment to find what looks best. Remember 2^n+1 size, and square images. What I do during the processing stage way before render is a first pass on the pixels to determine the maximum height (in meters), then during the second pass transform heights above zero to make them fit within the range 0-255. Negative altitudes are ignored by adjusting them to zero as this is not a submarine simulatar. That is for a heightmap stored as 8 bits per pixel, unsigned. Alternative is to use raw heightmaps to load floats directly, might say Hybrid soon. Or better 16 bits ints which is the original format.

We should definitely work on it together. Just finished the downloading part with socket.
With png heightmap 129X129 and 512X512 jpg texture that makes 130Kb per tile, to download and load into scene graph. As i was alone i planned to do Western Europe which represents 900 tiles that makes 1Gb of data for web hosting so no problem here! It is still better than what you get in Flight Simulotor X. The texture looks good enough because it is generated from the 3601X3601 pixels heightmap, with lightmapping embedded and a little bit of emissive and specular it looks grand particulary at high altitude (but this takes a while, about 10 minutes of processing for each tile, just to get a small heightmap and a small texture -and this is not a netbook computer, 3Ghz+4Gb of RAM under a tweaked Liinux). I expect to create a website with a map using Googlemap API updated with AJAX to see live where people are travelling. Posted that two days ago (was done with SRTM1). The picture is very impressive to me as i live there... Even better with SRTM2 but I won't care to post an image here since it is your project in this thread. That being said, together the world is possible.

On a side note what is your Flight Dynamics Model? JSBSim looks so complicated to embed... Wonder how the guys at Outerra managed to get the chopper working.
Just my 2 sense we are in the same boat. Do you have a screenshot of Nevada? :mrgreen:
mruno
Posts: 4
Joined: Thu Dec 22, 2011 1:45 am

Re: True-to-Life Terrain

Post by mruno »

Quick reply as I'm away from my code. The dataset I was planning on using is the US National Elevation Dataset that you can download from the USGS seamless server website.

Given that the raw file for each grid that you download is about 3100x4000 pixels in size I'll have to split each one up into lots and lots of smaller tiles. I'm open to sharing knowledge as we solve problems!

How did you solve the elevation scale issue? For the raw data processing I'm just using a desktop GIS application to export the greyscale heightmap from the raw seamless DEM file, then editing the size a bit in Gimp because loading the full scale file takes waaaaay to long.

I've not even began to tackle the issues of flight dynamics, or weather, etc. For now, I'd be happy just getting the terrain the proper height and being able to color it depending on how close the camera is to it (too close, red.. further away yellow, further tan, etc). I also need to figure out how to paint water blue... I fear youre already light years ahead of me...
ACE247
Posts: 704
Joined: Tue Mar 16, 2010 12:31 am

Re: True-to-Life Terrain

Post by ACE247 »

For the terrain to display at proper elevation scaling you would have to use 32bits/pixel raw files in my experience. 8bits/pixel is not enough since elevation data from the USGS base stores floating point data so when you convert to 255 color grayscale 8bit/pixel its all converted to integers and gets way too high.
If you need more info, I've been working a lot on this, just ask.

Oh and if you want to get really proper datasets, 1. try avoiding DEM files and use GeoTIFF files instead 2. Try something like Global Mapper for extraction of elevation datasets, the dang thing is not exactly cheap,(399U$) but allows very good control over the whole process. But you're probably not so serious as to need that.

Also the GeoTIFF files come with an extra file that specifies very accurate horizontal (x,z) and vertical (y) scale and elevation range information.
mruno
Posts: 4
Joined: Thu Dec 22, 2011 1:45 am

Re: True-to-Life Terrain

Post by mruno »

I really appreciate the information. As of right now I'm opening the DEM files with MicroDEM and exporting them to GeoTIFF format in greyscale. That's what I was loading into Irrlicht after convrrting them to bmp and scaling them down some. I'll have to look at the documentation tonight for loadheightmapraw and give it a try with the raw GeoTIFF files.

As an aside, I see that with World Explorer you have easy access to all the terrain data from inside the program. On the USGS seamless server they claim TIFF format, but I can only ever find ArcGrID and GridFloat formats. Perhaps one of those will work with the load raw heightmap function.. will consult the docs next. Do you know how to get TIFF out of seamless?

MicroDEM is freeware which is what interested me... but maybe further along I can justify $300 for a better tool.
ACE247
Posts: 704
Joined: Tue Mar 16, 2010 12:31 am

Re: True-to-Life Terrain

Post by ACE247 »

You should be able to download the GeoTIFF files directly from the USGS Website (they come in a zip package together with many other data for your selection(5kb important metadata)) Converting DEM's to GeoTIFF format in MicroDEM wont help, the extra detail and info isn't there which a direct GeoTIFF file contains.

GeoTIFF also cannot be simply loaded with irrlicht as if it were a TIFF file. It contains tons of Information that is necessary and would otherwise be lost, you need to load the file in some viewer (I use Global Mapper but MicroDEM can also work for simple stuff) then crop a region and export that selection to a RAW format(Other formats mess up the data), 32bit/pixel raw is best, 16bits/pixel also works. Also would be good if you can find the maximum and minimum elevation points in your cropped area, that way you can figure out the height range in that particular map and scale your terrain accordingly. Also when you used Gimp, to read the file, it lost about half the color elevation values converting to bmp, bmp only stores 8bit/pixel and that's not enough, you will get weird "stepping" in the 3d terrain then.

Several Tutorials that may be of great help:
http://digitalmindsoft.eu/forums/showth ... rth-in-GEM
http://forums.filefront.com/fh-mapping/ ... -data.html
http://www.massgate.net/read.php?77960,111959,171840
They may not be for Irrlicht but most certainly the result is what you want :D

Edit: If you want to refine low resolution terrain with some generated High detail, L3DT is a worthwhile investment its even quite cheap and SERIOUSLY powerfull!
(It can actually IMPORT and CONVERT ANY Geographical data! ) Yeah sorry I kinda remembered that one so late... :roll:
Post Reply