Monday, April 7, 2008

Pushing the Boundaries - Slight Return :)

I can't stay away can I.....LOL? I've literally been pushing and testing the boundaries of the CFS3 terrain engine this past week. I've also been working on and off, in between times, these last couple of months on new terrain and water polygons for the new CFS3 ETO project. In the last week, with initiatives in the CFS3 forums at Sim-Outhouse, to create an Eastern Front add-on for CFS3 I decided experiment with a mesh for that. As the Eastern front covered a large geographic area I decided to test for myself just what could be achieved as to terrain size.

First up I created a dummy theatre the same size as CFS3 ETO, only moved east, using the paramaters in the terrain SDK examples. Using some test airbases in a simple gsl file, the theatre worked. Ok next up I decided to test a mega terrain. The terrain map stretched from S.E UK in the west, to Iraq in the east, southern Scandinavia in the north and the northern part of North Africa in the south. I fully expected CFS3 to croak, or rather not start. However CFS3 started as normal and I was able to fly from a couple of my test airfields. However optimism and satisfaction were short lived when I created further test airfields in the global scenery layer and attempted to fly from them, the game seemed to clip the theatre size by itself. However at that stage I did not create a new lcf (landclass) file for the appropriate theatre size and in my earlier experiments had made an error with the image and landclass stride parameters. I will redo the experiment later to make sure. I had been in the process of creating a large map of another geographical region before the Eastern Front project came up.

I would also emphasize that for test purposes, to speed things up, I was only compiling 1km resolution mesh down to a 1km stride. It only takes a few minutes to compile terrain at this resolution. Full resolution terrains can take hours (or days) of computer number crunching to compile.

On to my findings - firstly I would say that either that some of the terrain SDK examples are incorrect or there is a bug in the ers2tiff.exe tool. Creating a terrain mesh for CFS3 is relatively easy once you have source dem data. I use a spreadsheet to calculate the approximate bounds of the terrain data. The only numbers that ers2tiff.exe requires is the theatre origin, image pixel dim, image stride, max height, outX1, outY1 (terrain extents) and the number of images in the X and Y axes. The ers2tiff tool calculates the actual extents and theatre boundary from this information. This tool will automatically clip the supplied terrain to the appropriate size given the theatre minimum extent and the theatre origin.

In CFS3 geographical co-ordinates are relative to the theatre origin i.e. the theatre centre. The terrain SDK provides example parameters of minimum co-ordinate extents of the output data, in meters relative to the origin. The SDK further states that extent of the default ETO theatre is the rectangle (-786432,-786432) to (786432, 786432). However the output parameters that ers2tiff produces using appropriate dem data are (-786432,-786432) to (785408, 785408). (785408, 785408) is the north east co-ordinate of the terrain boundary in meters relative to the theatre origin. 785408 is 1024 meters less than 786432. In other words it truncates the data by approximately 1km in the North East. Further tests reveal that regardless of minimum terrain extent or theatre origin, the tool always outputs terrain extent parameters with the the NE parameters being 1024 meters less than the SW. I don't know whether this is a bug or by design. I do vaguely recall reading posts of a 1km srtm terrain bug in FS2004 & maybe FS2002, in forums in the past - maybe it's the SRTM data (or maybe it's my imaginative memory - someone may be able to clarify)?

This may be pertinent to one problem I have discovered. If we move the theatre origin north, or create a theatre larger than the default theatre, and fly into, or create an airfield in the NE corner of the theatre and fly from it, CFS3 crashes. Everything else appears to work correctly. One can only really test the bounds of CFS3 by flying in the game until one encounters the theatre boundary. The sim will soon let you know when you're leaving the theatre.

I cannot see any input in any of the xml files that tells cfs3 how large the theatre is apart from the files in the campaign's folder and mapdat.xml. CFS3 appears to ignore these as one can use any old numbers and the theatre will function ok in quick combat. The lcf file seems to have a bearing on theatre functionality in the sim and that may set boundaries, or CFS3 may determine theatre size from the terrain archives in the mesh zips.

Anyway after exploring boundaries by flying in the simulation, CFS3 appears to calculate its boundaries based on distances calculated from it's centre origin. As we know, the earth is round thus the distance per degree of longitude or latitude differs wherever we are on the planet. A degree of longitude (E/W) is 111.32km at the equator but 55.8km at a latitude of 60°N. CFS3 calculates its longitude boundaries using 1/2 the theatre dimension size east or west along the latitude at its origin, e.g. origin latitude of 50°N (approx 71.7km per °), 30°E gives 15°19′46″E in the west 44° 40' 14"E in the east. CFS3 calculates north and south from the centre in a similar manner (distance for degree of latitude varies from 110.57km to 111.69km). Having created these boundaries CFS3 then uses a rectangle based on these geographic co-ordinates as its theatre boundary, which is ok as long as it's primary reference is geographic latitude and longitude. It's paradoxical to a certain extent given that many of the SDK calculations are based on meters usually based to the power of 2 or divisible by numbers which are to the power of 2.

Anyway the exploration continues. I will continue some tests with ers2tiff to see if it can produce output whose extent boundaries line up with the SDK documentation. Perhaps using a geotiff dem will produce different results...maybe dted0 dems will produce different results? I'll also experiment again with a mega theatre. If the NE corner bug is the only problem then maybe we can put up with that and caution users to stay clear....maybe a giant smiley...danger Will Robinson...danger Lol? I also hope to explore CFS3's landclass system....more on that later.

All this is very addictive...I keep trying to escape CFS3. There's nothing like a puzzle to maintain one's interest.

cheers

Rob