Here's my code that reads specific "blocks" of data from a RAW bitmap (24bits,8 R, 8 G, 8 B).  It's called with upper left hand location coordinates, and returns the data as a delimited string of height values (ugly, I know).
 
Because this raw file is accessed throughout a player's session, the file is opened in the init() method, and remains open (I seem to get a little better performance this way??).  The heightmap.raw file is about 12MB.
 
Any comments on my crappy code is welcome...
 
Scott
Virtopia 2 3D Project
 
public final class MapReader{
   private DataInputStream in;
   private DataOutputStream out;
 private RandomAccessFile is;
 

 public MapReader(){
  System.out.println("Initializing MapReader.");
  init();
 }
 
 public void init(){
      try {
   is = new RandomAccessFile("heightmap.raw", "r");
      }
  catch (IOException e) {     
   System.out.println("File error: " + e);
      }          
 }  
 

 public String getTerrainData(int tx, int tz, int blockSize){
  String outData="";
  int i,j;
  float scaleFactor=1.0f;
  float heightOffset=0.0f;
      float data[][] = new float[5][5];
  try{
         for (j=0;j<blockSize;j++){
   is.seek(tx*3 + (2048*3 * (tz+j) )) ;
          for (i = 0; i < blockSize; i++) {
    int data1 = (0xff) & is.readByte();
    int data2 = (0xff) & is.readByte();
    int data3 = (0xff) & is.readByte();
    data[i][j] =  (data1+data2+data3)/3.0f;
          }
  
  }
  }
  catch(IOException e){
   System.out.println("Error reading map: " + e);
  }
  DecimalFormat format = new DecimalFormat("0.00");
 
      for (j = 0;j<blockSize; j++) {
       for (i = 0;i<blockSize; i++) {
           outData = outData + format.format(((data[i][j])/scaleFactor+heightOffset)) + ",";
   }
      }
 
  return outData;
 }
 
 public void destroy(){
  try{
         is.close();
  }
  catch (IOException e){
   System.out.println("Error closing map file: " + e);
  }
  is=null;
 }
 

}
 
----- Original Message -----
Sent: Tuesday, April 30, 2002 1:15 AM
Subject: Re: [JAVA3D] Terragen

Could you send me some code along those lines.I fail to make that work.
----- Original Message -----
From: Scott
Sent: Monday, April 29, 2002 1:46 AM
Subject: Re: [JAVA3D] Terragen

I used it, along with GeoFrac2000 to generate a RAW bitmap for a heightfield.
 
I read in the values of the bitmap, each one representing a height value in a terrain.  I can send the routine to read from the RAW file if you want it... how you generate the geometry from there is up to you.
 
Scott
----- Original Message -----
Sent: Saturday, April 27, 2002 4:07 PM
Subject: [JAVA3D] Terragen

Hello Everyone
 
Has anyone ever used a file generated with Terragen on Genesis with java3D and if you have can you explain to me how you did it-including the loader you used.

Reply via email to