| 
     
      
    
    
       ...etc..etc.. 
    
       
    int m_NumTris; 
   Triangle[] m_tri; 
      
    
    
       
    /* 
    
    
       This small function or should I call it a method to be more correct,
     
    
    
       loads in a set of data from a txt file in the same location as the 
    
    
       .class applet file. 
    
    
       */ 
    
    
       
    private
    void 
    
    ReadInData() 
    
    
       {   
    
    
          
    // Our .txt file name 
    
    
          
    String strFile = 
    
    "maze1.txt"; 
    
    
          
    // We'll read in all the txt 
    file in one go into this buffer 
    
    
          
    String buffer = 
    
    new
    
    
    String(); 
    
    
      
    
    
          
    //-- First we read in all the 
    juicy txt info from our txt file--// 
    
    
           
    
    
          
    // Well when ever we read or 
    write to a file, we have to test for 
    
    
          // errors!  Java won't let us compile it otherwise :-/...picky 
    compiler 
    
    
          
    try 
    
    
          
    { 
    
    
             URL theURL = 
    
    new
    
    
    URL(getDocumentBase(),strFile);  
    
    
             BufferedReader in = 
    
    new
    
    
    BufferedReader( 
    
    
                                                                        
    
    
    new
    
    
    InputStreamReader( 
    
    
                                                                        
    
    theURL.openStream())); 
    
    
             String inputLine; 
    
    
                       
    
    
             
    while 
    ((inputLine = 
    in.readLine()) != 
    
    null) 
    
    
             { 
    
    
                System.out.println(inputLine); 
    
    
                buffer += inputLine; 
    
    
                buffer += 
    
    "\n"; 
    
    
             } 
    
    
             in.close(); 
    
    
          } 
    
    
          
    catch(java.net.MalformedURLException 
    e) 
    // not really needed 
    
    
          
    { 
    
    
             System.out.println("Exception 
    :-/ "); 
    
    
          } 
    
         
    
    catch(IOException e) 
    
         
    
    {} 
    
    
                 
    
    
      
    
    
          
    // Second...we've read it all 
    in...but I just want to replace 
    
    
          // newline's with spaces...and remove commas :) 
    
    
         
    
    
         
    
    
          // Mini routine to remove char's 
    
    
          
    char 
    charA = 
    
    '\n'; 
    
    
          
    char 
    charB = 
    
    '\"'; 
    
    
          
    char 
    charC = 
    
    '\r'; 
    
    
          
    char 
    charD = 
    
    '\t'; 
    
    
                 
    
    
          
    String withChar = 
    
    " "; 
    
    
          String r = 
    ""; 
    
    
          
    for 
    (int
    
    
    i = 0; i < buffer.length(); i++)  
    
    
          { 
    
    
             
    if 
    (buffer.charAt(i) != 
    charA && 
    
    
                                 
    buffer.charAt(i) != charB && 
    
    
                                         buffer.charAt(i) != charC && 
    
    
                                         buffer.charAt(i) != charD  ) r 
    += buffer.charAt(i); 
    
    
                             else 
    r+= withChar; 
    
    
          } 
    
    
          buffer = r; 
    
    
          buffer.trim(); 
    
    
                 
    
    
      
    
    
          
    //-- Third we'll parse the data 
    we now have in our buffer that we 
    
    
          // read in --// 
    
    
                 
    
    
          
    StringTokenizer st; 
    
    
          st = 
    new
    
    
    StringTokenizer(buffer, 
    
    " "); 
    
    
          
    int 
    tokenCount = 
    st.countTokens(); 
    
    
                 
    
    
          
    int 
    tokens = 0; 
    
    
          String[] str = 
    
    new
    
    
    String[5000]; 
    
    // Big buffer 
    
    
          
    while( st.hasMoreTokens() )
     
    
    
          { 
    
    
                         
    str[tokens] = st.nextToken(); 
    
    
                         
    tokens++; 
    
    
          } 
    
    
                 
    
    
          
    // At this point, str[] is just 
    a big array of string 
    
    
          // values...such as 1, 32, 22, "0xFFFFF"...etc...all seperate 
    
    
          // and one after the other where we can put seperate them. 
    
    
                 
    
    
          
    /* 
    
    
          // Test code...dump all the parsed values 
    
    
          for( int i=0; i<tokens; i++ ) 
    
    
          { 
    
    
                         System.out.println( str[i] ); 
    
          
    } 
    
          
    */ 
    
    
           
    
    
          
    float 
    scalex = 3.0f; 
    
    
          
    float 
    scaley = 1.0f; 
    
    
          
    float 
    scalez = 3.0f; 
    
    
                 
    
    
          
    // Allocate memory so we can 
    store all the values from the txt file into our 
    
    
          // array.  I divide by 6, as there are 10 tokens of data per line 
    :) 
    
    
           
    
    
          
    m_tri = 
    
    new
    
    
    Triangle[ tokens/10 ]; 
    
    
                 
    
    
          
    int 
    c=0; 
    
    
          
    int 
    i=0; 
    
    
          
    while( c < tokens-1 ) 
    
    
          { 
    
    
             
    // Had to fix these few lines so 
    we could still use our java 
    
    
             // applet on versions 1.0...as parseFloat wasn't introduced till 
    1.2 
    
    
                         
    /* 
    
    
             float x0  = Float.parseFloat( str[c]   )   * scalex; 
    
    
             float y0  = Float.parseFloat( str[c+1] )   * scaley; 
    
    
             float z0  = Float.parseFloat( str[c+2] )   * scalez; 
    
    
             float x1  = Float.parseFloat( str[c+3] )   * scalex; 
    
    
             float y1  = Float.parseFloat( str[c+4] )   * scaley; 
    
    
             float z1  = Float.parseFloat( str[c+5] )   * scalez; 
    
    
             float x2  = Float.parseFloat( str[c+6] )   * scalex; 
    
    
             float y2  = Float.parseFloat( str[c+7] )   * scaley; 
    
    
             float z2  = Float.parseFloat( str[c+8] )   * scalez; 
    
    
             int   col = Integer.parseInt( str[c+9],16); 
    
    
             c+=10; // 10 values per line 
    
    
             */ 
    
    
                 
    
            
    
    float 
    x0  = 
    
    new
    
    
    Float( str[c]   ).floatValue()   * scalex; 
    
            
    
    float 
    y0  = 
    
    new
    
    
    Float( str[c+1] ).floatValue()   * scaley; 
    
    
             
    float 
    z0  = 
    new 
    Float( str[c+2] ).floatValue()   
    * scalez; 
    
    
             
    float 
    x1  = 
    new 
    Float( str[c+3] ).floatValue()   
    * scalex; 
    
    
             
    float 
    y1  = 
    new 
    Float( str[c+4] ).floatValue()   
    * scaley; 
    
    
             
    float 
    z1  = 
    new 
    Float( str[c+5] ).floatValue()   
    * scalez; 
    
    
             
    float 
    x2  = 
    new 
    Float( str[c+6] ).floatValue()   
    * scalex; 
    
    
             
    float 
    y2  = 
    new 
    Float( str[c+7] ).floatValue()   
    * scaley; 
    
    
             
    float 
    z2  = 
    new 
    Float( str[c+8] ).floatValue()   
    * scalez; 
    
    
             
    int   
    col = Integer.parseInt( 
    str[c+9],16); 
    
    
             c+=10; 
    
    // 10 values per line 
    
    
                       
    
            
    
    // Debug Code 
    
            
    
    /* 
    
    
             System.out.println( " x0:" + x0 + " y0:"+ y0 + " z0: "+z0 + 
     
    
    
                                 " x1:" + x1 + " y1:"+ y1 + " z1: "+z1 + 
    
    
                                 " x2:" + x2 + " y2:"+ y2 + " z2: "+z2 + 
    
                                 
    " colour:"+ col ); 
    
    
             */ 
    
    
              
    
            
    
    int 
    red = ( col >> 16 ) & 
    0xFF; 
    
            
    
    int 
    green = ( col >> 8 ) & 
    0xFF; 
    
            
    
    int 
    blue = ( col  ) & 0xFF; 
    
            
    
    Color colr = 
    
    new
    
    
    Color(red,green,blue); 
    
    
             m_tri[i] = 
    
    new
    
    
    Triangle(x0,y0,z0,  x1,y1,z1, x2,y2,z2,  colr); 
    
    
             i++; 
    
    
                       
    
    
         
    
    }// End while loop 
    
    
           
    
    
          
    m_NumTris = i; 
    
    
           
    
    
       
    }// End of ReadInData() function 
    
    
           
    
      
    
    
    ...etc...etc 
    
    
       |