Minor VT Utility for Torben Mogensen's Planet Generator

Tips for creating and manipulating planet textures for Celestia.
Topic author
TheMadVulcan
Posts: 4
Joined: 09.09.2011
With us: 13 years 2 months

Minor VT Utility for Torben Mogensen's Planet Generator

Post #1by TheMadVulcan » 12.09.2011, 23:19

I have no idea if there will be any interest in this, but I thought I would share anyway. Obviously, my C++ is poor so I'm not looking for any accolades. This utility reads a dozen or so parameters from a text file and creates 4 batch files (which can be run simultaneously) and a summary text file defining what the batch files will do. These batch files contain all the necessary commands to direct planet.exe to create VT tiles according to the specifications in the text file. I've fully populated my level6 and easily created a number of tiles for level12. I'll briefly share the back story:

As an amateur writer, I was looking for world-building aids. I wanted something realistic yet different enough to offer inspiration for a fantasy/sci-fiction setting. Searching the web for utilities in this vein led me to WinStarGen, Celestia, and Torben's Mogensen's Planet Generator. The planet generator offered something close to what I had in mind and I really enjoyed the power of Celestia and the possibility of displaying my "universe" with it's engine.

I monkeyed with the generator for a while and found a world I thought suitable. It wasn't long before I realized, however, that true utility wouldn't come from my newly made world without significant detail (resolution). After stumbling through efforts to manage unwieldly large images, I discovered Celestia's virtual textures. By carefully manipulating longitude, latitude, resolution, and magnification, I was able to use Torben's generator to create tiles. Doing this by hand quickly become onerous as I considered the 128 tiles necessary for level3.

A few days and a fair amount of teaching myself C++ and this program was born. Here's the source code. Sorry for the complete lack of comments. It's really not too complicated and function and variable names are descriptive so it shouldn't be difficult to makes sense of it.

If there's any interest in it or if there's a better place or way to post this, please let me know. I'd be glad to help make it useful to anyone.

Code: Select all

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>
using namespace std;

long double checkRange(long double interval, long double degrees) {
   int degreesTruncated;
   if(degrees>=0.0){
      degreesTruncated=ceil(degrees/interval);
   }
   else {
      degreesTruncated=floor(degrees/interval);
   }
   degrees=interval*degreesTruncated;
   return degrees;
}

long double correctLatitude(long double degreesLatitude) {
   return (degreesLatitude/2.0);
}

void fileError() {
   cout << "Proper formatting requires a 'VTMaker.txt' file which contains the following:\n";
   cout << "  - one value each for the Ice, Bump Shading, and alternate color scheme options. These are each a '1' (one) if you wish them to be applied, '0' (zero) if not.\n";
   cout << "  - an integer value defining the BaseSplit value in your .ctx file.\n";
   cout << "  - integer values for the Lowest Level (e.g. '0') and the Highest Level (e.g. '12') you wish to render.\n";
   cout << "  - an integer value defining the Tile Resolution you wish to use (a power of 2 is required for Celesitia, e.g. '512').\n";
   cout << "All of the following values MUST have a decimal component (e.g. '180.0', '.00012'):\n";
   cout << "  - an Alititude Contribution number (generally around '.4'). See planet.exe's Manual.txt for more details.\n";
   cout << "  - an Distance Contribution number (generally around '.03'). See planet.exe's Manual.txt for more details.\n";
   cout << "  - a Random Number Seed (between '.0' and '1.0').\n";
   cout << "  - the West-most Longitude of the area you wish to render (between '-180.0' and '180.0').\n";
   cout << "  - the East-most Longitude of the area you wish to render (between '-180.0' and '180.0').\n";
   cout << "  - the North-most Latitude of the area you wish to render (between '90.0' and '-90.0').\n";
   cout << "  - the South-most Latitude of the area you wish to render (between '90.0' and '-90.0').\n\n";
   cout << "All values are numberic and are to be separated by white space (spaces, tabs, or new lines).\n\n";
   cout << "EXAMPLE VTMaker.txt file:\n";
   cout << "0 0 0\n";
   cout << "0\n";
   cout << "0 3\n";
   cout << "512\n";
   cout << ".58 .031\n";
   cout << ".00021\n";
   cout << "-135.0 45.0\n";
   cout << "0.0 -45.0\n";
}

int parameterFileStatus (bool properFormatting) {
   int fileError;
   if (!properFormatting) {
      fileError = 1;
   }
   else fileError = 0;
   return fileError;
}

int main () {

   int   parameterFileError = 0;

   ifstream parameterFile;
      parameterFile.open (".\\VTMaker.txt", ios::binary);

   bool   ICE = 0,
         BUMP = 0,
         ALTERNATE_COLOR = 0;

   int      BASE_SPLIT = 0,
         PARAMETER_START_LEVEL = 0,
         PARAMETER_END_LEVEL = 0,
         TILE_RESOLUTION = 32;
            
   long double      ALTITUDE_CONTRIBUTION = 0.0,
               DISTANCE_CONTRIBUTION = 0.0,
               RANDOM_SEED = 0.0,
               PARAMETER_LEFT_LONGITUDE = -180.0,
               PARAMETER_RIGHT_LONGITUDE = 180.0,
               PARAMETER_TOP_LATITUDE = 90.0,
               PARAMETER_BOTTOM_LATITUDE = -90.0;
                  
    if (parameterFile.is_open()) {
      parameterFile >> ICE;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> BUMP;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> ALTERNATE_COLOR;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> BASE_SPLIT;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> PARAMETER_START_LEVEL;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> PARAMETER_END_LEVEL;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> TILE_RESOLUTION;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> ALTITUDE_CONTRIBUTION;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> DISTANCE_CONTRIBUTION;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> RANDOM_SEED;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> PARAMETER_LEFT_LONGITUDE;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> PARAMETER_RIGHT_LONGITUDE;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> PARAMETER_TOP_LATITUDE;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> PARAMETER_BOTTOM_LATITUDE;
      if (!parameterFile.eof()) parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      if (parameterFileError == 0) {
         ofstream batchFile[5];
            batchFile[0].open (".\\planet0.bat", ios::binary);
            batchFile[1].open (".\\planet1.bat", ios::binary);
            batchFile[2].open (".\\planet2.bat", ios::binary);
            batchFile[3].open (".\\planet3.bat", ios::binary);
            batchFile[4].open (".\\VTinfo.txt", ios::binary);

         string   options = "";
         if (ICE) options = options + "-c ";
         if (BUMP) options = options + "-B ";
         if (ALTERNATE_COLOR) options = options + "-a ";

         int   numberOfColumns = 0,
            firstColumn = 0,
            column = 0,
            numberOfRows = 0,
            firstRow = 0,
            row = 0,
            startLevel = PARAMETER_START_LEVEL,
            endLevel = PARAMETER_END_LEVEL,
            level = 0,
            magnitude = 0,
            fileNumber = 0,
            counter = 0,
            tileTotal = 0;
            
         long double   longitude = 0.0,
                  latitude = 0.0,
                  leftLongitude = 0.0,
                  rightLongitude = 0.0,
                  topLatitude = 0.0,
                  bottomLatitude = 0.0,
                  rangeLongitude = 0.0,
                  rangeLatitude = 0.0,
                  levelInterval[13];
         for(level=PARAMETER_START_LEVEL;level<=PARAMETER_END_LEVEL;level++) {
            levelInterval[level]=(360.0/pow(2.0,(level+BASE_SPLIT+1.0)));
         }
         
         for(fileNumber=0;fileNumber<=3;fileNumber++) {
            batchFile[fileNumber] << "@echo off\n";
         }
         
         fileNumber=0;
         
         if (startLevel==0&&BASE_SPLIT==0) {
            batchFile[fileNumber] << "mkdir level" << startLevel << "\n";
            batchFile[fileNumber] << "echo LEVEL:  " << startLevel << "    TILE:  tx_0_0.bmp    RESOLUTION:  " << TILE_RESOLUTION << ".\n";
            batchFile[fileNumber] << "planet -w " << TILE_RESOLUTION << " -h " << TILE_RESOLUTION << " -v " << ALTITUDE_CONTRIBUTION << " -V "
               << DISTANCE_CONTRIBUTION << " -s " << RANDOM_SEED << " -p q " << options << "-o .\\level0\\tx_0_0.bmp -m 2 -l -90 -L 0\n";
            batchFile[fileNumber] << "echo Completed.\n";
            batchFile[fileNumber] << "echo LEVEL:  " << startLevel << "    TILE:  tx_1_0.bmp    RESOLUTION:  " << TILE_RESOLUTION << ".\n";
            batchFile[fileNumber] << "planet -w " << TILE_RESOLUTION << " -h " << TILE_RESOLUTION << " -v " << ALTITUDE_CONTRIBUTION << " -V "
               << DISTANCE_CONTRIBUTION << " -s " << RANDOM_SEED << " -p q " << options << "-o .\\level0\\tx_1_0.bmp -m 2 -l 90 -L 0\n";
            batchFile[fileNumber] << "echo Completed.\n";
            batchFile[4] << "Level 0 will have 2 columns and 1 row for a total of 2 tiles.\n";
            startLevel=1;
            tileTotal=2;
         }
         
         for(level=startLevel; level<=endLevel; level++)  {
            
            batchFile[0] << "mkdir level" << level << "\n";
            batchFile[1] << "mkdir level" << level << "\n";
            batchFile[2] << "mkdir level" << level << "\n";
            batchFile[3] << "mkdir level" << level << "\n";
            
            leftLongitude = checkRange(levelInterval[level],PARAMETER_LEFT_LONGITUDE);
            rightLongitude = checkRange(levelInterval[level],PARAMETER_RIGHT_LONGITUDE);
            rangeLongitude = rightLongitude - leftLongitude;
            topLatitude = checkRange(levelInterval[level],PARAMETER_TOP_LATITUDE);
            bottomLatitude = checkRange(levelInterval[level],PARAMETER_BOTTOM_LATITUDE);
            rangeLatitude = topLatitude - bottomLatitude;

            magnitude = pow(2,level+BASE_SPLIT+1);
            
            numberOfColumns=rangeLongitude/levelInterval[level];
               if(numberOfColumns==0) {numberOfColumns=1;}
            numberOfRows=rangeLatitude/levelInterval[level];
               if(numberOfRows==0) {numberOfRows=1;}
            firstColumn=(180+leftLongitude)/levelInterval[level];
            firstRow=(90-topLatitude)/levelInterval[level];
            
            batchFile[4] << "Level " << level << " will have " << numberOfColumns << " columns and "
               << numberOfRows << " rows for a total of " << (numberOfRows*numberOfColumns) << " tiles.\n";
            
            tileTotal=(numberOfColumns*numberOfRows)+tileTotal;
                  
            latitude = topLatitude - (levelInterval[level]/2.0);
            numberOfColumns--;
            numberOfRows--;
            
            for(row=0;row<=numberOfRows;row++)  {
            
               longitude = leftLongitude + (levelInterval[level]/2.0);
               
               for(column=0;column<=numberOfColumns;column++)  {
               
                  batchFile[fileNumber] << "echo LEVEL:  " << level << "    TILE:  tx_" <<  (column+firstColumn) << "_" << (row+firstRow)
                     << ".bmp    RESOLUTION:  " << TILE_RESOLUTION << "    TILE NUMBER:  " << (counter/4)+1 << ".\n";
                  batchFile[fileNumber] << setprecision(16) << "planet -w " << TILE_RESOLUTION << " -h " << TILE_RESOLUTION << " -v "
                     << ALTITUDE_CONTRIBUTION << " -V " << DISTANCE_CONTRIBUTION << " -s " << RANDOM_SEED << " -p q " << options
                     << "-o .\\level" << level << "\\tx_" << (column+firstColumn) << "_" << (row+firstRow) << ".bmp -m " << magnitude
                     << " -l " << longitude << " -L " << correctLatitude(latitude) << "\n";
                  batchFile[fileNumber] << "echo Completed.\n";
                  longitude = longitude + levelInterval[level];
                  
                  counter++;
                  fileNumber++;
                  if (fileNumber==4) {
                     fileNumber=0;
                  }
               }
               
               latitude = latitude - levelInterval[level];
               
            }
         }
         
         batchFile[4] << "TOTAL NUMBER OF TILES:  " << tileTotal << "\n";
         batchFile[4] << "RESOLUTION:  " << TILE_RESOLUTION << "\n";
         if (ICE||BUMP||ALTERNATE_COLOR)
         {
            batchFile[4] << "OPTIONS APPLIED:\n";
            if(ICE) batchFile[4] << "    Ice Coloring\n";
            if(BUMP) batchFile[4] << "    Bump Shading\n";
            if(ALTERNATE_COLOR) batchFile[4] << "    Alternate Color Scheme\n";
         }
         batchFile[4] << "WEST-MOST LONGITUDE:  " << PARAMETER_LEFT_LONGITUDE << "\n";
         batchFile[4] << "EAST-MOST LONGITUDE:  " << PARAMETER_RIGHT_LONGITUDE << "\n";
         batchFile[4] << "NORTH-MOST LATITUDE:  " << PARAMETER_TOP_LATITUDE << "\n";
         batchFile[4] << "SOUTH-MOST LATITUDE:  " << PARAMETER_BOTTOM_LATITUDE << "\n";
            
         for (fileNumber=0; fileNumber<=4; fileNumber++) {
            batchFile[fileNumber].close();
         }
         
      } else {
         cout << "Error: Improper formatting in Paramter File.\n\n";
         fileError();
      }
      
   } else {
      cout << "Error: Unable to open Parameter file.\n\n";
      fileError();
   }
   parameterFile.close();

   return 0;
}
Last edited by TheMadVulcan on 13.09.2011, 19:44, edited 1 time in total.

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Re: Minor VT Utility for Torben Mogensen's Planet Generator

Post #2by selden » 13.09.2011, 00:02

Thanks! I expect I'll put it to some use.

I've been working on a planet myself, but haven't progressed beyond a single 8K texture image. I assume you've already worked out the color files which enable planet to generate bump and specular maps -- they're fairly straight forward.

Are you doing anything about creating rivers? Wilbur can do that, but it takes quite a while to manipulate an 8K heightmap. Unfortunately, Wilbur can't be scripted. which would make it tedious to manipulate many tiles. (I've been bugging its author about that.)

I crudely modified planet to generate 16bit pgm heightmaps (for use by Wilbur) when given a 16bit color file. Diffs are available upon request. Torben wasn't interested. :(
Selden

Topic author
TheMadVulcan
Posts: 4
Joined: 09.09.2011
With us: 13 years 2 months

Re: Minor VT Utility for Torben Mogensen's Planet Generator

Post #3by TheMadVulcan » 13.09.2011, 02:08

Great to hear! Let me know if you have any trouble with it. Sounds like you'd likely be able to modify it if you're interested in using some different features of Torben's planet.exe.


I have done some bump mapping with it using a few grey color files (some evenly distributed and others according to my preference). I briefly looked through Torben's source to try and determine the exact distribution for my shades of grey that would properly reflect the elevation, but didn't get very far. I'll get back to that and hopefully figure it out without too much trouble.

I did notice that the alternate color scheme uses a more visually pleasing elevation distribution. Mountain peaks are much peakier and look less like giant white plateaus. So I added a parameter to planet.exe that allowed me to use those elevation algorithms with or without the alternate color scheme.

Unfortunately, my ancient computer's integrated GPU doesn't handle OpenGL very well so my bump mapping has been outside of Celestia via GIMP. And since I can't find any reasonable way to make GIMP manage 8000+ pairs of images, bump mapping my VT tiles just isn't going to happen. This also means that I haven't bothered with specular mapping.


I did stumble upon Wilbur while I was searching for world-building software. It didn't seem immediately useful at the time, but I'll have to check it out again.

One of the things that I really like about doing the VTs is that I can have planet.exe render a few hundred tiles on level12 (or "higher" if I start with a higher BaseSplit) of any area that I want to develop in my narrative. To me, that means that Wilbur is potentially useful, but I'll definitely need to look into it further.

I may ask you for those modifications eventually. Your response and the information you've provided make me more intent on progressing. Thanks. :)


Once again, let me know if you're having any issues with it or anything of the sort. Would it be more beneficial if there was a pre-compiled version? If so, where's the best place to host it?

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Re: Minor VT Utility for Torben Mogensen's Planet Generator

Post #4by selden » 13.09.2011, 12:19

People already have to be able to compile programs in order to use planet, so I don't think a precompiled version of your program is necessary.

Free hosting services for Celestia Addons are available on the MotherLode at http://celestiamotherlode.net/ In general, though, binary programs are not hosted since there's always the worry about them being infected, accidentally or not. At some point you might want to consider using their services to make your planetary maps available to fans of your stories. Orion's Arm and Arcbuilder environments are already available, as well as fan-created ones for some commercial SF works.
Selden

Avatar
John Van Vliet
Posts: 2944
Joined: 28.08.2002
With us: 22 years 2 months

Re: Minor VT Utility for Torben Mogensen's Planet Generator

Post #5by John Van Vliet » 15.09.2011, 02:17

--- edit ---
Last edited by John Van Vliet on 19.10.2013, 06:41, edited 1 time in total.

Topic author
TheMadVulcan
Posts: 4
Joined: 09.09.2011
With us: 13 years 2 months

Re: Minor VT Utility for Torben Mogensen's Planet Generator

Post #6by TheMadVulcan » 17.09.2011, 00:09

Excellent! Thanks very much, John. I will definitely check those out.

I haven't gotten too far on the Wilbur front, but it does look promising. Thanks again for pointing me in that direction, selden.

Avatar
Tegmine
Posts: 200
Joined: 20.03.2011
With us: 13 years 8 months

Re: Minor VT Utility for Torben Mogensen's Planet Generator

Post #7by Tegmine » 17.09.2011, 16:55

Is there any way to show a sample of what this will do?

Thanks

-M-

Avatar
John Van Vliet
Posts: 2944
Joined: 28.08.2002
With us: 22 years 2 months

Re: Minor VT Utility for Torben Mogensen's Planet Generator

Post #8by John Van Vliet » 17.09.2011, 20:09

--- edit ---
Last edited by John Van Vliet on 19.10.2013, 06:41, edited 1 time in total.

Topic author
TheMadVulcan
Posts: 4
Joined: 09.09.2011
With us: 13 years 2 months

Re: Minor VT Utility for Torben Mogensen's Planet Generator

Post #9by TheMadVulcan » 19.09.2011, 01:13

First, here's a quick update. It's mostly to make the output file ("VTInfo.txt") more helpful. It now gives a simple ASCII representation of the area covered. It also adds a little more info to the batch files themselves so that as they run one can tell how close they are to completion.

Code: Select all

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>
using namespace std;

long double checkRange(long double interval, long double degrees) {
   int degreesTruncated;
   if(degrees>=0.0) {
      degreesTruncated=ceil(degrees/interval);
   }
   else {
      degreesTruncated=floor(degrees/interval);
   }
   degrees=interval*degreesTruncated;
   return degrees;
}

long double correctLatitude(long double degreesLatitude) {
   return (degreesLatitude/2.0);
}

void fileError() {
   cout << "Proper formatting requires a 'VTMaker.txt' file which contains the following:\n";
   cout << "  - one value each for the Ice, Bump Shading, and Alternate Color Scheme options. These are each a '1' (one) if you wish them to be applied, '0' (zero) if not.\n";
   cout << "  - an integer value defining the BaseSplit value in your .ctx file.\n";
   cout << "  - integer values for the Lowest Level (e.g. '0') and the Highest Level (e.g. '12') you wish to render.\n";
   cout << "  - an integer value defining the Tile Resolution you wish to use (a power of 2 is required for Celesitia, e.g. '512').\n";
   cout << "All of the following values MUST have a decimal component (e.g. '180.0', '.00012'):\n";
   cout << "  - an Alititude Contribution number (generally around '.4'). See planet.exe's Manual.txt for more details.\n";
   cout << "  - an Distance Contribution number (generally around '.03'). See planet.exe's Manual.txt for more details.\n";
   cout << "  - a Random Number Seed (between '.0' and '1.0').\n";
   cout << "  - the West-most Longitude of the area you wish to render (between '-180.0' and '180.0').\n";
   cout << "  - the East-most Longitude of the area you wish to render (between '-180.0' and '180.0').\n";
   cout << "  - the North-most Latitude of the area you wish to render (between '90.0' and '-90.0').\n";
   cout << "  - the South-most Latitude of the area you wish to render (between '90.0' and '-90.0').\n\n";
   cout << "All values are numberic and are to be separated by white space (spaces, tabs, or new lines).\n\n";
   cout << "EXAMPLE VTMaker.txt file:\n";
   cout << "0 0 0\n";
   cout << "0\n";
   cout << "0 3\n";
   cout << "512\n";
   cout << ".58 .031\n";
   cout << ".00021\n";
   cout << "-135.0 45.0\n";
   cout << "0.0 -45.0\n";
}

int parameterFileStatus (bool properFormatting) {
   int fileError;
   if (!properFormatting) {
      fileError = 1;
   }
   else fileError = 0;
   return fileError;
}

int main () {

   int   parameterFileError = 0;

   ifstream parameterFile;
      parameterFile.open (".\\VTMaker.txt", ios::binary);

   bool   ICE = 0,
         BUMP = 0,
         ALTERNATE_COLOR = 0;

   int      BASE_SPLIT = 0,
         PARAMETER_START_LEVEL = 0,
         PARAMETER_END_LEVEL = 0,
         TILE_RESOLUTION = 32;
            
   long double      ALTITUDE_CONTRIBUTION = 0.0,
               DISTANCE_CONTRIBUTION = 0.0,
               RANDOM_SEED = 0.0,
               PARAMETER_LEFT_LONGITUDE = -180.0,
               PARAMETER_RIGHT_LONGITUDE = 180.0,
               PARAMETER_TOP_LATITUDE = 90.0,
               PARAMETER_BOTTOM_LATITUDE = -90.0;
                  
    if (parameterFile.is_open()) {
      parameterFile >> ICE;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> BUMP;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> ALTERNATE_COLOR;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> BASE_SPLIT;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> PARAMETER_START_LEVEL;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> PARAMETER_END_LEVEL;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> TILE_RESOLUTION;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> ALTITUDE_CONTRIBUTION;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> DISTANCE_CONTRIBUTION;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> RANDOM_SEED;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> PARAMETER_LEFT_LONGITUDE;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> PARAMETER_RIGHT_LONGITUDE;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> PARAMETER_TOP_LATITUDE;
      parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      parameterFile >> PARAMETER_BOTTOM_LATITUDE;
      if (!parameterFile.eof()) parameterFileError = parameterFileError + parameterFileStatus (parameterFile.good());
      if (parameterFileError == 0) {
         ofstream batchFile[5];
            batchFile[0].open (".\\planet0.bat", ios::binary);
            batchFile[1].open (".\\planet1.bat", ios::binary);
            batchFile[2].open (".\\planet2.bat", ios::binary);
            batchFile[3].open (".\\planet3.bat", ios::binary);
            batchFile[4].open (".\\VTInfo.txt", ios::binary);

         string   options = "";
         if (ICE) options = options + "-c ";
         if (BUMP) options = options + "-B ";
         if (ALTERNATE_COLOR) options = options + "-a ";

         int   numberOfColumns = 0,
            firstColumn = 0,
            column = 0,
            numberOfRows = 0,
            firstRow = 0,
            row = 0,
            startLevel = PARAMETER_START_LEVEL,
            endLevel = PARAMETER_END_LEVEL,
            level = 0,
            magnitude = 0,
            fileNumber = 0,
            counter = 0,
            tilePercentInt1 = 0,
            tilePercentInt2 = 0,
            tileTotal = 0;
            
         long double   tilePercentDouble = 0.0,
                  longitude = 0.0,
                  latitude = 0.0,
                  leftLongitude = 0.0,
                  rightLongitude = 0.0,
                  topLatitude = 0.0,
                  bottomLatitude = 0.0,
                  rangeLongitude = 0.0,
                  rangeLatitude = 0.0,
                  levelInterval[13];
         for(level=PARAMETER_START_LEVEL;level<=PARAMETER_END_LEVEL;level++) {
            levelInterval[level]=(360.0/pow(2.0,(level+BASE_SPLIT+1.0)));
         }
         
         for(fileNumber=0;fileNumber<=3;fileNumber++) {
            batchFile[fileNumber] << "@echo off\n";
         }
         
         fileNumber=0;
         
         if (startLevel==0&&BASE_SPLIT==0) {
            batchFile[fileNumber] << "mkdir level" << startLevel << "\n";
            batchFile[fileNumber] << "echo LEVEL:  " << startLevel << "    TILE:  tx_0_0.bmp    RESOLUTION:  " << TILE_RESOLUTION << ".\n";
            batchFile[fileNumber] << "planet -w " << TILE_RESOLUTION << " -h " << TILE_RESOLUTION << " -v " << ALTITUDE_CONTRIBUTION << " -V "
               << DISTANCE_CONTRIBUTION << " -s " << RANDOM_SEED << " -p q " << options << "-o .\\level0\\tx_0_0.bmp -m 2 -l -90 -L 0\n";
            batchFile[fileNumber] << "echo Completed.\n";
            batchFile[fileNumber] << "echo LEVEL:  " << startLevel << "    TILE:  tx_1_0.bmp    RESOLUTION:  " << TILE_RESOLUTION << ".\n";
            batchFile[fileNumber] << "planet -w " << TILE_RESOLUTION << " -h " << TILE_RESOLUTION << " -v " << ALTITUDE_CONTRIBUTION << " -V "
               << DISTANCE_CONTRIBUTION << " -s " << RANDOM_SEED << " -p q " << options << "-o .\\level0\\tx_1_0.bmp -m 2 -l 90 -L 0\n";
            batchFile[fileNumber] << "echo Completed.\n";
            batchFile[4] << "Level 0 will have 2 columns and 1 row for a total of 2 tiles.\n";
            startLevel=1;
            tileTotal=2;
         }

         for(level=startLevel; level<=endLevel; level++) {
            leftLongitude = checkRange(levelInterval[level],PARAMETER_LEFT_LONGITUDE);
            rightLongitude = checkRange(levelInterval[level],PARAMETER_RIGHT_LONGITUDE);
            rangeLongitude = rightLongitude - leftLongitude;
            topLatitude = checkRange(levelInterval[level],PARAMETER_TOP_LATITUDE);
            bottomLatitude = checkRange(levelInterval[level],PARAMETER_BOTTOM_LATITUDE);
            rangeLatitude = topLatitude - bottomLatitude;

            numberOfColumns=rangeLongitude/levelInterval[level];
               if(numberOfColumns==0) {numberOfColumns=1;}
            numberOfRows=rangeLatitude/levelInterval[level];
               if(numberOfRows==0) {numberOfRows=1;}
            
            tileTotal=(numberOfColumns*numberOfRows)+tileTotal;
         }
         
         for(level=startLevel; level<=endLevel; level++) {
            
            batchFile[0] << "mkdir level" << level << "\n";
            batchFile[1] << "mkdir level" << level << "\n";
            batchFile[2] << "mkdir level" << level << "\n";
            batchFile[3] << "mkdir level" << level << "\n";
            
            leftLongitude = checkRange(levelInterval[level],PARAMETER_LEFT_LONGITUDE);
            rightLongitude = checkRange(levelInterval[level],PARAMETER_RIGHT_LONGITUDE);
            rangeLongitude = rightLongitude - leftLongitude;
            topLatitude = checkRange(levelInterval[level],PARAMETER_TOP_LATITUDE);
            bottomLatitude = checkRange(levelInterval[level],PARAMETER_BOTTOM_LATITUDE);
            rangeLatitude = topLatitude - bottomLatitude;

            magnitude = pow(2,level+BASE_SPLIT+1);
            
            numberOfColumns=rangeLongitude/levelInterval[level];
               if(numberOfColumns==0) {numberOfColumns=1;}
            numberOfRows=rangeLatitude/levelInterval[level];
               if(numberOfRows==0) {numberOfRows=1;}
            firstColumn=(180+leftLongitude)/levelInterval[level];
            firstRow=(90-topLatitude)/levelInterval[level];
            
            batchFile[4] << "Level " << level << " will have " << numberOfColumns << " columns and "
               << numberOfRows << " rows for a total of " << (numberOfRows*numberOfColumns) << " tiles.\n";
            
            latitude = topLatitude - (levelInterval[level]/2.0);
            numberOfColumns--;
            numberOfRows--;
            
            for(row=0;row<=numberOfRows;row++) {
            
               longitude = leftLongitude + (levelInterval[level]/2.0);
               
               for(column=0;column<=numberOfColumns;column++) {
               
                  tilePercentInt1=((counter/4)+1);
                  tilePercentInt2=tileTotal/4;
                  tilePercentDouble=((tilePercentInt1+0.0)/(tilePercentInt2+0.0))*100.0;
                  batchFile[fileNumber] << "echo LEVEL:  " << level << "    TILE:  tx_" <<  (column+firstColumn) << "_" << (row+firstRow)
                     << ".bmp    RESOLUTION:  " << TILE_RESOLUTION << "    TILE NUMBER:  " << (counter/4)+1 << " of "
                     << (tileTotal/4) << ".\n";
                  batchFile[fileNumber] << resetiosflags( ios::fixed | ios::showpoint );
                  batchFile[fileNumber] << setprecision(16) << "planet -w " << TILE_RESOLUTION << " -h " << TILE_RESOLUTION << " -v "
                     << ALTITUDE_CONTRIBUTION << " -V " << DISTANCE_CONTRIBUTION << " -s " << RANDOM_SEED << " -p q " << options
                     << "-o .\\level" << level << "\\tx_" << (column+firstColumn) << "_" << (row+firstRow) << ".bmp -m " << magnitude
                     << " -l " << longitude << " -L " << correctLatitude(latitude) << "\n";
                  batchFile[fileNumber] << setprecision(2) << fixed << "echo " << tilePercentDouble << "% Completed.\n";
                  longitude = longitude + levelInterval[level];
                  
                  counter++;
                  fileNumber++;
                  if (fileNumber==4) {
                     fileNumber=0;
                  }
               }
               
               latitude = latitude - levelInterval[level];
               
            }
         }
         
         batchFile[4] << "TOTAL NUMBER OF TILES:  " << tileTotal << "\n";
         batchFile[4] << "RESOLUTION:  " << TILE_RESOLUTION << "\n";
         if (ICE||BUMP||ALTERNATE_COLOR) {
            batchFile[4] << "OPTIONS APPLIED:\n";
            if(ICE) batchFile[4] << "    Ice Coloring\n";
            if(BUMP) batchFile[4] << "    Bump Shading\n";
            if(ALTERNATE_COLOR) batchFile[4] << "    Alternate Color Scheme\n";
         }
         batchFile[4] << "WEST-MOST LONGITUDE:  " << PARAMETER_LEFT_LONGITUDE << "\n";
         batchFile[4] << "EAST-MOST LONGITUDE:  " << PARAMETER_RIGHT_LONGITUDE << "\n";
         batchFile[4] << "NORTH-MOST LATITUDE:  " << PARAMETER_TOP_LATITUDE << "\n";
         batchFile[4] << "SOUTH-MOST LATITUDE:  " << PARAMETER_BOTTOM_LATITUDE << "\n\n";
            
         bool   meridianOn=1,
               equatorOn=1;
         int   testWest=(PARAMETER_LEFT_LONGITUDE/5)-0.5,
            testEast=(PARAMETER_RIGHT_LONGITUDE/5)+0.5,
            testNorth=(PARAMETER_TOP_LATITUDE/10)+0.5,
            testSouth=(PARAMETER_BOTTOM_LATITUDE/10)-0.5;
         batchFile[4] << "  -180  -150  -120  -90   -60   -30     0     30    60    90   120   150   180\n";
         for (int latLoop=9;latLoop>=-9;latLoop--) {
            if ((latLoop%3)==0) {
               if (latLoop>0) batchFile[4] << " ";
               else   if (latLoop==0) batchFile[4] << "  ";
               batchFile[4] << latLoop*10 << " ";
            }
            else batchFile[4] << "    ";
            if (latLoop==0) {
               for (int equator=-36;equator<=36;equator++) {
                  if (equator==0) {
                     batchFile[4] << "+";
                  }
                  else {
                     if(equator>=testWest&&equator<=testEast&&latLoop<=testNorth&&latLoop>=testSouth) {
                        if (equatorOn) {
                           batchFile[4] << "#";
                           equatorOn=0;
                        }
                        else {
                           batchFile[4] << "-";
                           equatorOn=1;
                        }
                     }
                     else batchFile[4] << "-";
                  }
               }
            }
            else {
               for (int longLoop=-36;longLoop<=36;longLoop++) {
                  if (longLoop==0) {
                     if(longLoop>=testWest&&longLoop<=testEast&&latLoop<=testNorth&&latLoop>=testSouth) {
                        if (meridianOn) {
                           batchFile[4] << "#";
                           meridianOn=0;
                        }
                        else {
                           batchFile[4] << "|";
                           meridianOn=1;
                        }
                     }
                     else batchFile[4] << "|";
                  }
                  else {
                     if(longLoop>=testWest&&longLoop<=testEast&&latLoop<=testNorth&&latLoop>=testSouth) batchFile[4] << "#";
                     else batchFile[4] << " ";
                  }
               }
            }
            if ((latLoop%3)==0) {
               if (latLoop>0) batchFile[4] << " ";
               else   if (latLoop==0) batchFile[4] << "  ";
               batchFile[4] << latLoop*10 << " ";
            }
            else batchFile[4] << "    ";
            batchFile[4] << "\n";
         }
         batchFile[4] << "  -180  -150  -120  -90   -60   -30     0     30    60    90   120   150   180\n";
         
         for (fileNumber=0; fileNumber<=4; fileNumber++) {
            batchFile[fileNumber].close();
         }
         
      } else {
         cout << "Error: Improper formatting in Paramter File.\n\n";
         fileError();
      }
      
   } else {
      cout << "Error: Unable to open Parameter file.\n\n";
      fileError();
   }
   parameterFile.close();

   return 0;
}


Tegmine wrote:Is there any way to show a sample of what this will do?

Thanks

-M-
The program requires you to create a file called "VTMaker.txt" which contains the following parameters:
    - one value each for the Ice, Bump Shading, and Alternate Color Scheme options. These are each a '1' (one) if you wish them to be applied, '0' (zero) if not.
    - an integer value defining the BaseSplit value in your .ctx file.
    - integer values for the Lowest Level (e.g. '0') and the Highest Level (e.g. '12') you wish to render.
    - an integer value defining the Tile Resolution you wish to use (a power of 2 is required for Celesitia, e.g. '512').
All of the following values MUST have a decimal component (e.g. '180.0', '.00012'):
    - an Alititude Contribution number (generally around '.4'). See planet.exe's Manual.txt for more details.
    - an Distance Contribution number (generally around '.03'). See planet.exe's Manual.txt for more details.
    - a Random Number Seed (between '.0' and '1.0').
    - the West-most Longitude of the area you wish to render (between '-180.0' and '180.0').
    - the East-most Longitude of the area you wish to render (between '-180.0' and '180.0').
    - the North-most Latitude of the area you wish to render (between '90.0' and '-90.0').
    - the South-most Latitude of the area you wish to render (between '90.0' and '-90.0').
All values are numberic and are to be separated by white space (spaces, tabs, or new lines).

EXAMPLE VTMaker.txt file:

Code: Select all

0 0 0
0
0 1
512
.58 .031
.00021
-135.0 45.0
0.0 -45.0


This will produce four batch files (called "planet0.bat" through "planet3.bat") and a summary text file (called "VTInfo.txt").

planet0.bat:

Code: Select all

@echo off
mkdir level0
echo LEVEL:  0    TILE:  tx_0_0.bmp    RESOLUTION:  512.
planet -w 512 -h 512 -v 0.58 -V 0.031 -s 0.00021 -p q -o .\level0\tx_0_0.bmp -m 2 -l -90 -L 0
echo Completed.
echo LEVEL:  0    TILE:  tx_1_0.bmp    RESOLUTION:  512.
planet -w 512 -h 512 -v 0.58 -V 0.031 -s 0.00021 -p q -o .\level0\tx_1_0.bmp -m 2 -l 90 -L 0
echo Completed.
mkdir level1
echo LEVEL:  1    TILE:  tx_0_1.bmp    RESOLUTION:  512    TILE NUMBER:  1 of 2.
planet -w 512 -h 512 -v 0.58 -V 0.031 -s 0.00021 -p q -o .\level1\tx_0_1.bmp -m 4 -l -135 -L -22.5
echo 50.00% Completed.
mkdir level2
echo LEVEL:  2    TILE:  tx_2_2.bmp    RESOLUTION:  512    TILE NUMBER:  2 of 2.
planet -w 512 -h 512 -v 0.58 -V 0.031 -s 0.00021 -p q -o .\level2\tx_2_2.bmp -m 8 -l -67.5 -L -11.25
echo 100.00% Completed.

planet1.bat:

Code: Select all

@echo off
mkdir level1
echo LEVEL:  1    TILE:  tx_1_1.bmp    RESOLUTION:  512    TILE NUMBER:  1 of 2.
planet -w 512 -h 512 -v 0.58 -V 0.031 -s 0.00021 -p q -o .\level1\tx_1_1.bmp -m 4 -l -45 -L -22.5
echo 50.00% Completed.
mkdir level2
echo LEVEL:  2    TILE:  tx_3_2.bmp    RESOLUTION:  512    TILE NUMBER:  2 of 2.
planet -w 512 -h 512 -v 0.58 -V 0.031 -s 0.00021 -p q -o .\level2\tx_3_2.bmp -m 8 -l -22.5 -L -11.25
echo 100.00% Completed.

planet2.bat:

Code: Select all

@echo off
mkdir level1
echo LEVEL:  1    TILE:  tx_2_1.bmp    RESOLUTION:  512    TILE NUMBER:  1 of 2.
planet -w 512 -h 512 -v 0.58 -V 0.031 -s 0.00021 -p q -o .\level1\tx_2_1.bmp -m 4 -l 45 -L -22.5
echo 50.00% Completed.
mkdir level2
echo LEVEL:  2    TILE:  tx_4_2.bmp    RESOLUTION:  512    TILE NUMBER:  2 of 2.
planet -w 512 -h 512 -v 0.58 -V 0.031 -s 0.00021 -p q -o .\level2\tx_4_2.bmp -m 8 -l 22.5 -L -11.25
echo 100.00% Completed.

planet3.bat:

Code: Select all

@echo off
mkdir level1
mkdir level2
echo LEVEL:  2    TILE:  tx_1_2.bmp    RESOLUTION:  512    TILE NUMBER:  1 of 2.
planet -w 512 -h 512 -v 0.58 -V 0.031 -s 0.00021 -p q -o .\level2\tx_1_2.bmp -m 8 -l -112.5 -L -11.25
echo 50.00% Completed.

VTInfo.txt:

Code: Select all

Level 0 will have 2 columns and 1 row for a total of 2 tiles.
Level 1 will have 3 columns and 1 rows for a total of 3 tiles.
Level 2 will have 4 columns and 1 rows for a total of 4 tiles.
TOTAL NUMBER OF TILES:  5
RESOLUTION:  512
WEST-MOST LONGITUDE:  -135
EAST-MOST LONGITUDE:  45
NORTH-MOST LATITUDE:  0
SOUTH-MOST LATITUDE:  -45

  -180  -150  -120  -90   -60   -30     0     30    60    90   120   150   180
90                                      |                                     90
                                        |                                       
                                        |                                       
60                                      |                                     60
                                        |                                       
                                        |                                       
30                                      |                                     30
                                        |                                       
                                        |                                       
  0 ---------#-#-#-#-#-#-#-#-#-#-#-#-#-#+-#-#-#-#----------------------------  0
             #####################################                               
             ###########################|#########                               
-30          #####################################                           -30
             ###########################|#########                               
             #####################################                               
-60                                     |                                    -60
                                        |                                       
                                        |                                       
-90                                     |                                    -90
  -180  -150  -120  -90   -60   -30     0     30    60    90   120   150   180

When you run the batch files, Torben's planet.exe will produce several bitmaps which you will need to convert into a image format Celestia accepts (I use .png). Use your favorite image program to convert them en masse. These files can then be used by Celestia as Virtual Texture tiles. If you're unfamiliar with how to use virtual textures, check out Selden's excellent guide and the links within.

The "power" of this utility comes when you attempt to fill or partially fill a higher level which could require hundreds, thousands, or hundreds of thousands of tiles. Using this, I've fully populated level6 with 512X512 resolution tiles. Without it (or something similar), you would need a complete image that is 65536X32768 pixels in size. Then you would have to use Fridger's utilities to split it. If you chose tiles with a larger resolution or chose to render a higher level, you would need a significantly larger file.

Feel free to post or message me if you still have questions.


Return to “Textures”