home *** CD-ROM | disk | FTP | other *** search
/ Internet Gallery / INTERGAL.bin / intergal / prgs / idv21 / data.z / WireSinus.java < prev    next >
Text File  |  1996-05-20  |  3KB  |  104 lines

  1. import java.awt.*;
  2.  
  3. class WireSinus implements MyWidget {
  4.     
  5.     final static    int 
  6.             ORG_X = 0, ORG_Y = 1, ORG_Z = 2,
  7.                ROT_X = 3, ROT_Y = 4, ROT_Z = 5,
  8.             TRA_X = 6, TRA_Y = 7,
  9.             EYE   = 2700, SCREENBOARD = 250;       // 3d zu 2d transformation
  10.  
  11.     final static int Points=15;
  12.     int Point[][][] = null;
  13.  
  14.     int s_xaxis=0,s_yaxis=0,s_zaxis=0;
  15.     
  16.     int startx = 0, startz = 0;     
  17.     
  18.     public WireSinus()
  19.     {
  20.         Point = new int[Points][Points][8];
  21.         
  22.         for(int z=0; z<Points; z++)
  23.         {
  24.             for(int x=0; x<Points; x++)
  25.             {
  26.                 Point[z][x][ORG_X] = (x-Points/2)*LEN/2;
  27.                 Point[z][x][ORG_Z] = (z-Points/2)*LEN/2;
  28.             }
  29.           }     
  30.     }
  31.     
  32.     public void newLayout()
  33.     {
  34.         for(int z=0; z<Points; z++)
  35.         {
  36.             for(int x=0; x<Points; x++)
  37.             {
  38.                 Point[z][x][ORG_Y] = (SinCos.Sin((x<<6)+startx) + SinCos.Sin((z<<6)+startz))>>6;
  39.             }
  40.         }
  41.         startx+=64;
  42.         startz+=32;
  43.     }
  44.  
  45.     void Rotate( int xaxis, int yaxis, int zaxis)
  46.     {
  47.         s_xaxis+=xaxis; s_yaxis+=yaxis; s_zaxis+=zaxis;
  48.         int v=Points;
  49.         while( v-- > 0) {
  50.             int i=Points;
  51.             while( i-- > 0) {
  52.             // Drehung um die x-Achse
  53.                 int y1 = (SinCos.Cos(s_xaxis)*Point[v][i][ORG_Y] - SinCos.Sin(s_xaxis)*Point[v][i][ORG_Z]) >> 14, 
  54.                     z1 = (SinCos.Cos(s_xaxis)*Point[v][i][ORG_Z] + SinCos.Sin(s_xaxis)*Point[v][i][ORG_Y]) >> 14;
  55.  
  56.             // Drehung um die y-Achse
  57.                 Point[v][i][ROT_Z] = (SinCos.Cos(s_yaxis)*z1     - SinCos.Sin(s_yaxis)*Point[v][i][ORG_X]) >> 14; 
  58.                 int x2 = (SinCos.Cos(s_yaxis)*Point[v][i][ORG_X] + SinCos.Sin(s_yaxis)*z1   )          >> 14;
  59.  
  60.             // Drehung um die z-Achse
  61.                 Point[v][i][ROT_X] = (SinCos.Cos(s_zaxis)*x2     - SinCos.Sin(s_zaxis)*y1   ) >> 14; 
  62.                 Point[v][i][ROT_Y] = (SinCos.Cos(s_zaxis)*y1     + SinCos.Sin(s_zaxis)*x2   ) >> 14; 
  63.             }    
  64.         }    
  65.     }
  66.  
  67.     void Translate()
  68.     {
  69.         int v=Points;
  70.         while( v-- > 0)
  71.         {
  72.             int i=Points;
  73.             while( i-- > 0) {
  74.                 Point[v][i][TRA_X] = SCREENBOARD*Point[v][i][ROT_X] / (EYE - Point[v][i][ROT_Z]) +LEN/2;
  75.                 Point[v][i][TRA_Y] = LEN/2-SCREENBOARD*Point[v][i][ROT_Y] / (EYE - Point[v][i][ROT_Z]);
  76.             }
  77.         }    
  78.     }
  79.  
  80.     public void repaint(Graphics g)    
  81.     {
  82.         g.setColor( Color.black );
  83.         g.fillRect( 0, 0, LEN, LEN ); 
  84.  
  85.         g.setColor( Color.green );
  86.         
  87.         newLayout();
  88.         Rotate( 4, 5, 6);
  89.         Translate();
  90.         
  91.         for (int L=0; L<Points-1; L++)
  92.             {
  93.                   for (int R=0; R<Points-1; R++)
  94.                { 
  95.                 g.drawLine(Point[L][R][TRA_X], Point[L][R][TRA_Y], Point[L][R+1][TRA_X], Point[L][R+1][TRA_Y]);
  96.                 g.drawLine(Point[L][R][TRA_X], Point[L][R][TRA_Y], Point[L+1][R][TRA_X], Point[L+1][R][TRA_Y]);
  97.                  }
  98.                g.drawLine(Point[L][Points-1][TRA_X], Point[L][Points-1][TRA_Y], Point[L+1][Points-1][TRA_X], Point[L+1][Points-1][TRA_Y]);
  99.         }
  100.         for (int R=0; R<Points-1; R++)
  101.                   g.drawLine(Point[Points-1][R][TRA_X], Point[Points-1][R][TRA_Y], Point[Points-1][R+1][TRA_X], Point[Points-1][R+1][TRA_Y]);
  102.     }
  103. }
  104.