home *** CD-ROM | disk | FTP | other *** search
- program cube; { Author: William P. Smith }
- { Mitchellville, Md }
-
- { This is a real time graphics demo of a cube tumbling in }
- { 3-space. The 8088 processor is just too slow to do }
- { effectively demonstrate real time graphics, but this }
- { program can be used as a bench mark for graphics }
- { performance of future generation PCs. }
-
- const color = 4;
-
- var A,B,Ax,Bx,Ay,By,Az,Bz,TH,THx,THy,THz: real;
- T: array[1..3,1..3] of real;
- Xp,Yp: array[1..3] of integer;
- X,Y: array[1..7] of integer;
- j,offsetX,offsetY,incrX,incrY: integer;
- Video: Byte absolute $B800:0000;
-
- procedure DrawCube(THx,THy,THz: real);
- begin
- Az:=cos(THz); Ax:=cos(THx); Ay:=cos(THy);
- Bz:=sin(THz); Bx:=sin(THx); By:=sin(THy);
- t[1,1]:=Az*Ay-Bx*By*Bz; t[1,2]:=-Bz*Ax; t[1,3]:=Az*By+Ay*Bz*Bx;
- t[2,1]:=Bz*Ay+Az*Bx*By; t[2,2]:=Az*Ax; t[2,3]:=Bz*By-Az*Ay*Bx;
- t[3,1]:=-Ax*By; t[3,2]:=Bx; t[3,3]:=Ax*Ay;
- for j:=1 to 3 do begin
- xp[j]:=round(60*(t[2,j]-t[1,j]*B));
- yp[j]:=round(30*(t[3,j]-t[1,j]*A));
- end;
- X[1]:=offsetx+xp[1]; Y[1]:=offsety-yp[1];
- X[2]:=X[1]+xp[2]; Y[2]:=Y[1]-yp[2];
- X[3]:=offsetx+xp[2]; Y[3]:=offsety-yp[2];
- X[4]:=X[3]+xp[3]; Y[4]:=Y[3]-yp[3];
- X[5]:=offsetx+xp[3]; Y[5]:=offsety-yp[3];
- X[6]:=X[1]+xp[3]; Y[6]:=Y[1]-yp[3];
- X[7]:=X[2]+xp[3]; Y[7]:=Y[2]-yp[3];
-
-
- fillchar(Video,$4000,$FF);
-
- draw(OffsetX,OffsetY,X[1],Y[1],0);
- draw(X[1],Y[1],X[2],Y[2],0);
- draw(X[2],Y[2],X[3],Y[3],0);
- draw(X[3],Y[3],X[4],Y[4],0);
- draw(X[4],Y[4],X[5],Y[5],0);
- draw(X[5],Y[5],X[6],Y[6],0);
- draw(X[6],Y[6],X[7],Y[7],0);
- draw(X[7],Y[7],X[4],Y[4],0);
- draw(X[3],Y[3],OffsetX,OffsetY,0);
- draw(OffsetX,OffsetY,X[5],Y[5],0);
- draw(X[6],Y[6],X[1],Y[1],0);
- draw(X[7],Y[7],X[2],Y[2],0);
-
- end;
- procedure beep;
- begin
- sound(200);
- delay(100);
- Nosound;
- end;
- begin
- TH:=pi/4;
- A:=cos(TH); B:=sin(TH);
- offsetX:=300; offsetY:=100;
- incrX:=5; incrY:=3;
- Hires; Hirescolor(color);
- THx:=0.0; THy:=0.0; THz:=0.0;
- drawCube(THx,THy,THz);
- repeat
- THz:=THz+0.1; THx:=THX-0.1; THy:=Thy+0.1;
- drawCube(THx,THy,THz);
- if (offsetX>=500) or (offsetX<=40) then begin
- incrX:=-incrX;
- beep;
- end;
- if (offsetY<=30) or (offsetY>=180) then begin
- incrY:=-incrY;
- beep;
- end;
- offsetX:=offsetX+incrX; offsetY:=offsetY+incrY;
- until keypressed;
- end.