home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Gallery
/
INTERGAL.bin
/
intergal
/
prgs
/
idv21
/
data.z
/
WireSinus.java
< prev
next >
Wrap
Text File
|
1996-05-20
|
3KB
|
104 lines
import java.awt.*;
class WireSinus implements MyWidget {
final static int
ORG_X = 0, ORG_Y = 1, ORG_Z = 2,
ROT_X = 3, ROT_Y = 4, ROT_Z = 5,
TRA_X = 6, TRA_Y = 7,
EYE = 2700, SCREENBOARD = 250; // 3d zu 2d transformation
final static int Points=15;
int Point[][][] = null;
int s_xaxis=0,s_yaxis=0,s_zaxis=0;
int startx = 0, startz = 0;
public WireSinus()
{
Point = new int[Points][Points][8];
for(int z=0; z<Points; z++)
{
for(int x=0; x<Points; x++)
{
Point[z][x][ORG_X] = (x-Points/2)*LEN/2;
Point[z][x][ORG_Z] = (z-Points/2)*LEN/2;
}
}
}
public void newLayout()
{
for(int z=0; z<Points; z++)
{
for(int x=0; x<Points; x++)
{
Point[z][x][ORG_Y] = (SinCos.Sin((x<<6)+startx) + SinCos.Sin((z<<6)+startz))>>6;
}
}
startx+=64;
startz+=32;
}
void Rotate( int xaxis, int yaxis, int zaxis)
{
s_xaxis+=xaxis; s_yaxis+=yaxis; s_zaxis+=zaxis;
int v=Points;
while( v-- > 0) {
int i=Points;
while( i-- > 0) {
// Drehung um die x-Achse
int y1 = (SinCos.Cos(s_xaxis)*Point[v][i][ORG_Y] - SinCos.Sin(s_xaxis)*Point[v][i][ORG_Z]) >> 14,
z1 = (SinCos.Cos(s_xaxis)*Point[v][i][ORG_Z] + SinCos.Sin(s_xaxis)*Point[v][i][ORG_Y]) >> 14;
// Drehung um die y-Achse
Point[v][i][ROT_Z] = (SinCos.Cos(s_yaxis)*z1 - SinCos.Sin(s_yaxis)*Point[v][i][ORG_X]) >> 14;
int x2 = (SinCos.Cos(s_yaxis)*Point[v][i][ORG_X] + SinCos.Sin(s_yaxis)*z1 ) >> 14;
// Drehung um die z-Achse
Point[v][i][ROT_X] = (SinCos.Cos(s_zaxis)*x2 - SinCos.Sin(s_zaxis)*y1 ) >> 14;
Point[v][i][ROT_Y] = (SinCos.Cos(s_zaxis)*y1 + SinCos.Sin(s_zaxis)*x2 ) >> 14;
}
}
}
void Translate()
{
int v=Points;
while( v-- > 0)
{
int i=Points;
while( i-- > 0) {
Point[v][i][TRA_X] = SCREENBOARD*Point[v][i][ROT_X] / (EYE - Point[v][i][ROT_Z]) +LEN/2;
Point[v][i][TRA_Y] = LEN/2-SCREENBOARD*Point[v][i][ROT_Y] / (EYE - Point[v][i][ROT_Z]);
}
}
}
public void repaint(Graphics g)
{
g.setColor( Color.black );
g.fillRect( 0, 0, LEN, LEN );
g.setColor( Color.green );
newLayout();
Rotate( 4, 5, 6);
Translate();
for (int L=0; L<Points-1; L++)
{
for (int R=0; R<Points-1; R++)
{
g.drawLine(Point[L][R][TRA_X], Point[L][R][TRA_Y], Point[L][R+1][TRA_X], Point[L][R+1][TRA_Y]);
g.drawLine(Point[L][R][TRA_X], Point[L][R][TRA_Y], Point[L+1][R][TRA_X], Point[L+1][R][TRA_Y]);
}
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]);
}
for (int R=0; R<Points-1; R++)
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]);
}
}