home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Gallery
/
INTERGAL.bin
/
intergal
/
prgs
/
idv21
/
data.z
/
WireCube.java
< prev
next >
Wrap
Text File
|
1996-04-22
|
2KB
|
74 lines
import java.awt.*;
public class WireCube 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 = 4000, SCREENBOARD = 400; // 3d zu 2d transformation
final static int Points=8,
Point[][] = { { -LEN*2,LEN*2, 0, 0,0,0,0,0 },
{-LEN*2,-LEN*2, 0, 0,0,0,0,0 },
{ LEN*2,-LEN*2, 0, 0,0,0,0,0 },
{ LEN*2, LEN*2, 0, 0,0,0,0,0 },
{-LEN*2, LEN*2,-LEN*2, 0,0,0,0,0 },
{-LEN*2,-LEN*2,-LEN*2, 0,0,0,0,0 },
{ LEN*2,-LEN*2,-LEN*2, 0,0,0,0,0 },
{ LEN*2, LEN*2,-LEN*2, 0,0,0,0,0 } };
final static int Lines = 12;
final static int Line[][] = { {0,1},{1,2},{2,3},{3,0},
{4,5},{5,6},{6,7},{7,4},
{0,4},{1,5},{2,6},{3,7} };
int s_xaxis=0,s_yaxis=0,s_zaxis=0;
void Rotate( int xaxis, int yaxis, int zaxis)
{
s_xaxis+=xaxis; s_yaxis+=yaxis; s_zaxis+=zaxis;
int i=Points;
while( i-- > 0) {
// Drehung um die x-Achse
int y1 = (SinCos.Cos(s_xaxis)*Point[i][ORG_Y] - SinCos.Sin(s_xaxis)*Point[i][ORG_Z]) >> 14,
z1 = (SinCos.Cos(s_xaxis)*Point[i][ORG_Z] + SinCos.Sin(s_xaxis)*Point[i][ORG_Y]) >> 14;
// Drehung um die y-Achse
Point[i][ROT_Z] = (SinCos.Cos(s_yaxis)*z1 - SinCos.Sin(s_yaxis)*Point[i][ORG_X]) >> 14;
int x2 = (SinCos.Cos(s_yaxis)*Point[i][ORG_X] + SinCos.Sin(s_yaxis)*z1 ) >> 14;
// Drehung um die z-Achse
Point[i][ROT_X] = (SinCos.Cos(s_zaxis)*x2 - SinCos.Sin(s_zaxis)*y1 ) >> 14;
Point[i][ROT_Y] = (SinCos.Cos(s_zaxis)*y1 + SinCos.Sin(s_zaxis)*x2 ) >> 14;
}
}
void Translate()
{
int i=Points;
while( i-- > 0) {
Point[i][TRA_X] = SCREENBOARD*Point[i][ROT_X] / (EYE - Point[i][ROT_Z]) +LEN/2;
Point[i][TRA_Y] = LEN/2-SCREENBOARD*Point[i][ROT_Y] / (EYE - Point[i][ROT_Z]);
}
}
public void repaint(Graphics g)
{
g.setColor( Color.black );
g.fillRect( 0, 0, LEN, LEN );
g.setColor( Color.green );
Rotate( 2, 3, 6);
Translate();
int i=Lines;
while( i-- > 0 ) {
g.drawLine( Point[ Line[i][0] ][TRA_X], Point[ Line[i][0] ][TRA_Y],
Point[ Line[i][1] ][TRA_X], Point[ Line[i][1] ][TRA_Y] );
}
}
}