home *** CD-ROM | disk | FTP | other *** search
- PROGRAM THREE (input,output);
- {$c-}
- {r+}
- {$i-}
- {$u+}
-
- CONST
- gbase =$b800; {graphics display}
- pi =0.0174533; {pi/180}
- eyedis =4; {distance of eye from screen}
- objdis =10; {distance of object from screen}
- xsize =15;
- ysize =15; {35}
- maxpoint =10; {max # of point for objects}
- maxface =20; {faces on an object}
- maxgon =15; {sides on a face}
- xsi =30;
- ysi =15;
- digits : array [0..30] of string[2] = ('0','1','2','3','4','5','6','7','8','9','10','11'
- ,'12','13','14','15'
- ,'16','17','18','19',
- '20','21','22','23','24','25'
- ,'26','27','28','29','30');
- TYPE
- reg_pack = record
- ax,bx,cx,dx,bp,si,di,ds,es,flags:integer;
- end;
-
- lettertype = array[0..3] of byte;
- letter = array[1..2] of lettertype;
- scrfield = array[0..8192] of byte;
- scrtype = array[1..2] of scrfield;
- line = array[0..19] of byte; {20 letters/ a byte a letter}
- menufield = array[0..31] of line; {8 lines of letters * 8 /2fields}
- menutype = array[1..2] of menufield;
- gbuff = array[0..16383] of byte;
- matrixtype = array [1..4,1..4] of real;
- matressa = array[1..35] of matrixtype;
- currentype = array[1..5] of integer;
- planetype = (xy , xz, yz, arb);
- axistype = (x , y , z , arbt);
- actiontype = (scale,refle,rotet,trans,exodus);
- point = array [1..4] of real; {x,y,z,1}
- pntlst = array [1..maxpoint] of point; {all of obj. points}
- pntptr = ^point;
- facetype =
- record
- face :array [0..maxgon] of pntptr; {all of obj. faces}
- visib:boolean;
- end; {0 is the normal}
- objectype =
- record
- pntlst: pntlst;
- pntno : integer;
- faceno: integer;
- side : array [1..maxface] of facetype;
- center: array [x..z] of real;
- end;
- grami = array [1..xsi] of byte;
- field = array [1..ysi] of grami;
- frame = array [1..2] of field;
-
- VAR
- registers :reg_pack;
- cache : gbuff ;
- outfile : file of gbuff;
- { mov : array[1..10] of frame;}
- scr1 : menutype;
- { scrsave : scrtype;}
- display : gbuff absolute gbase:$0000;
- obj1 : objectype;
- copy1 : objectype;
- current : currentype;
- matr : matressa; {array of trnsformations}
- matrcnt : integer; { # of transformations}
- form : matrixtype; {generic matrix of an operation}
- i,j,k,m : integer;
- loop,ch : char;
- xtrack : integer;
- xline : array[1..2,1..4] of real; {small axis displayed}
- yline : array[1..2,1..4] of real; {small axis displayed}
- zline : array[1..2,1..4] of real; {small axis displayed}
- zlet : letter; {containing the letter's dots}
- ylet,xlet : letter; {containing the letter's dots}
- fileno :integer;
- depth :integer;
- render :boolean;
-
- {$I matrix.pas}
- {$I matrix2.pas}
- {$i fill.pas}
- {$i ping.pong}
- { I screen.pas}
- { I axis.pas }
- { I drawline.pas}
-
-
- procedure flood(x,y,color:integer);
- begin
- if (call(true,3,x,y) = 0) and ((depth <2000)) then
- begin
- depth:=depth+1;
- k:= call(false,color,x,y);
- flood(x,y+1,color);
- flood(x+1,y,color);
- flood(x,y-1,color);
- flood(x-1,y,color);
- depth:=depth-1;
- end;
- end;
-
- procedure comein;
- var
- i,j : integer;
-
- begin
- obj1.pntlst[1,1]:= -1; obj1.pntlst[1,2] := -1; obj1.pntlst[1,3]:= 1;
- obj1.pntlst[2,1]:= 1; obj1.pntlst[2,2] := -1; obj1.pntlst[2,3]:= 1;
- obj1.pntlst[3,1]:= 1; obj1.pntlst[3,2] := 1; obj1.pntlst[3,3]:= 1;
- obj1.pntlst[4,1]:= -1; obj1.pntlst[4,2] := 1; obj1.pntlst[4,3]:= 1;
- obj1.pntlst[5,1]:= -1; obj1.pntlst[5,2] := 1; obj1.pntlst[5,3]:= -1;
- obj1.pntlst[6,1]:= 1; obj1.pntlst[6,2] := 1; obj1.pntlst[6,3]:= -1;
- obj1.pntlst[7,1]:= 1; obj1.pntlst[7,2] := -1; obj1.pntlst[7,3]:= -1;
- obj1.pntlst[8,1]:= -1; obj1.pntlst[8,2] := -1; obj1.pntlst[8,3]:= -1;
-
-
- obj1.pntno := 8;
- obj1.faceno := 6;
- obj1.center[x] := 160;
- obj1.center[y] := 100;
- obj1.center[z] := 0;
-
- for i:= 1 to 6 do
- for j:=0 to 4 do
- begin
- new(obj1.side[i].face[j]);
- new(copy1.side[i].face[j]);
- end;
-
- move(obj1,copy1,sizeof(copy1));
-
- obj1.side[1].face[1]^:=obj1.pntlst[1];
- obj1.side[1].face[2]^:=obj1.pntlst[2];
- obj1.side[1].face[3]^:=obj1.pntlst[3];
- obj1.side[1].face[4]^:=obj1.pntlst[4];
-
- obj1.side[2].face[1]^:=obj1.pntlst[2];
- obj1.side[2].face[2]^:=obj1.pntlst[7];
- obj1.side[2].face[3]^:=obj1.pntlst[6];
- obj1.side[2].face[4]^:=obj1.pntlst[3];
-
- obj1.side[3].face[1]^:=obj1.pntlst[3];
- obj1.side[3].face[2]^:=obj1.pntlst[6];
- obj1.side[3].face[3]^:=obj1.pntlst[5];
- obj1.side[3].face[4]^:=obj1.pntlst[4];
-
- obj1.side[4].face[1]^:=obj1.pntlst[1];
- obj1.side[4].face[2]^:=obj1.pntlst[4];
- obj1.side[4].face[3]^:=obj1.pntlst[5];
- obj1.side[4].face[4]^:=obj1.pntlst[8];
-
- obj1.side[5].face[1]^:=obj1.pntlst[8];
- obj1.side[5].face[2]^:=obj1.pntlst[5];
- obj1.side[5].face[3]^:=obj1.pntlst[6];
- obj1.side[5].face[4]^:=obj1.pntlst[7];
-
- obj1.side[6].face[1]^:=obj1.pntlst[1];
- obj1.side[6].face[2]^:=obj1.pntlst[8];
- obj1.side[6].face[3]^:=obj1.pntlst[7];
- obj1.side[6].face[4]^:=obj1.pntlst[2];
-
- copy1.side[1].face[1]^:=copy1.pntlst[1];
- copy1.side[1].face[2]^:=copy1.pntlst[2];
- copy1.side[1].face[3]^:=copy1.pntlst[3];
- copy1.side[1].face[4]^:=copy1.pntlst[4];
-
- copy1.side[2].face[1]^:=copy1.pntlst[2];
- copy1.side[2].face[2]^:=copy1.pntlst[7];
- copy1.side[2].face[3]^:=copy1.pntlst[6];
- copy1.side[2].face[4]^:=copy1.pntlst[3];
-
- copy1.side[3].face[1]^:=copy1.pntlst[3];
- copy1.side[3].face[2]^:=copy1.pntlst[6];
- copy1.side[3].face[3]^:=copy1.pntlst[5];
- copy1.side[3].face[4]^:=copy1.pntlst[4];
-
- copy1.side[4].face[1]^:=copy1.pntlst[1];
- copy1.side[4].face[2]^:=copy1.pntlst[4];
- copy1.side[4].face[3]^:=copy1.pntlst[5];
- copy1.side[4].face[4]^:=copy1.pntlst[8];
-
- copy1.side[5].face[1]^:=copy1.pntlst[8];
- copy1.side[5].face[2]^:=copy1.pntlst[5];
- copy1.side[5].face[3]^:=copy1.pntlst[6];
- copy1.side[5].face[4]^:=copy1.pntlst[7];
-
- copy1.side[6].face[1]^:=copy1.pntlst[1];
- copy1.side[6].face[2]^:=copy1.pntlst[8];
- copy1.side[6].face[3]^:=copy1.pntlst[7];
- copy1.side[6].face[4]^:=copy1.pntlst[2];
-
-
-
- { data2[1,1]:= 0.5; data2[1,2] := 0; data2[1,3]:=0.5;
- data2[2,1]:= 0.5; data2[2,2] := 0; data2[2,3]:=-0.5;
- data2[3,1]:=-0.5; data2[3,2] := 0; data2[3,3]:=-0.5;
- data2[4,1]:=-0.5; data2[4,2] := 0; data2[4,3]:=0.5;
- data2[5,1]:= 0; data2[5,2] := 1; data2[5,3]:=0;
- data2[5,1]:= -1; data2[5,2] := -1; data2[5,3]:= 1;
- data2[6,1]:= 1; data2[6,2] := 1; data2[6,3]:= -1;
- data2[6,1]:= 0; data2[6,2] :=-1; data2[6,3]:=0;
- octpoints :=6;
- octxpos :=160;
- octypos :=100;
- octvert :=24;
- octaux[1]:=1; octaux[2]:=2;
- octaux[3]:=2; octaux[4]:=3;
- octaux[5]:=3; octaux[6]:=4;
- octaux[7]:=4; octaux[8]:=1;
- octaux[9]:=1; octaux[10]:=5;
- octaux[11]:=2; octaux[12]:=5;
- octaux[13]:=3; octaux[14]:=5;
- octaux[15]:=4; octaux[16]:=5;
- octaux[17]:=1; octaux[18]:=6;
- octaux[19]:=2; octaux[20]:=6;
- octaux[21]:=3; octaux[22]:=6;
- octaux[23]:=4; octaux[24]:=6; }
-
- xline[1,1]:=0; xline[1,2]:=0; xline[1,3]:=0; {endpoints for the axis}
- xline[2,1]:=1; xline[2,2]:=0; xline[2,3]:=0;
- yline[1,1]:=0; yline[1,2]:=0; yline[1,3]:=0;
- yline[2,1]:=0; yline[2,2]:=1; yline[2,3]:=0;
- zline[1,1]:=0; zline[1,2]:=0; zline[1,3]:=0;
- zline[2,1]:=0; zline[2,2]:=0; zline[2,3]:=1;
-
- end; {of comein}
-
-
-
- procedure plotit(obj : objectype; offset:integer);
- var
- i,j :integer;
- temp :facetype;
- x1,x2 :real;
- y1,y2 :real;
- z1,z2 :real;
- scrn :real; {uesed for perspective}
- center :array[x..y] of integer;
- fillx :integer;
- filly :integer;
- t1,t2 :real;
- color :integer;
-
- begin
- scrn :=eyedis / objdis;
- for i:=1 to obj.faceno do
- begin
- if obj.side[i].visib then
- begin
- for j:= 1 to 4 do {for the cube}
- begin
- x1:= obj.side[i].face[j]^[1];
- y1:= obj.side[i].face[j]^[2];
- if j <> 4 then
- begin
- x2:=obj.side[i].face[j+1]^[1];
- y2:=obj.side[i].face[j+1]^[2];
- end
- else
- begin
- x2:=obj.side[i].face[1]^[1];
- y2:=obj.side[i].face[1]^[2];
- end;
- x1:= x1 * xsize +obj. center[x];
- x2:= x2 * xsize +obj. center[x];
- y1:= y1 * ysize +obj. center[y];
- y2:= y2 * ysize +obj. center[y];
- draw(round(x1),round(y1),round(x2),round(y2),1);
- end;
- if render then
- begin
- if obj.side[i].face[3]^[1] > obj.side[i].face[1]^[1] then
- t1:= abs (( obj.side[i].face[3]^[1])
- - (obj.side[i].face[1]^[1])) / 2
- + (obj.side[i].face[1]^[1])
- else
- t1:= abs ((obj.side[i].face[1]^[1])
- - (obj.side[i].face[3]^[1])) / 2
- + (obj.side[i].face[3]^[1]);
-
- if obj.side[i].face[3]^[2] > obj.side[i].face[1]^[2] then
- t2:= abs((obj.side[i].face[3]^[2])
- -(obj.side[i].face[1]^[2])) / 2
- +(obj.side[i].face[1]^[2])
- else
- t2:= abs ((obj.side[i].face[1]^[2])
- - (obj.side[i].face[3]^[2])) / 2
- + (obj.side[i].face[3]^[2]);
-
- fillx:=round(t1*xsize+obj.center[x]);
- filly:=round(t2*ysize+obj.center[y]);
- if odd(i) then color :=2
- else color :=3;
- flood(fillx,filly,color);
- end; {of render}
- end;
- end;
- end;
-
- procedure normal (var object:objectype;
- d :real; {vewing parameters}
- theta:integer; fi:integer);
- var
- u,v,n :point;
- i,j,k :integer;
- temp :facetype;
- t1,t2,t3 :point;
- sf,cf :real; {sin, cos of vewing parameters}
- st,ct :real;
- lambda :point;
- temp_L :point;
- dotnl :real;
-
- begin
- for i:= 0 to 4 do
- new(temp.face[i]);
- st :=sin(theta); ct:= cos(theta);
- sf :=sin(fi); cf:= cos(fi);
- temp_L[1]:= d * sf * ct;
- temp_L[2]:= d * sf * st;
- temp_L[3]:= d * cf;
-
- for i:= 1 to object.faceno do {every face}
- begin
- move(object.side[i],temp,sizeof(object.side[i])); { for clarity !!!}
- move(temp.face[1]^,t1,sizeof(t1)); { counterclock point 1}
- move(temp.face[2]^,t2,sizeof(t1)); { counterclock point 2}
- move(temp.face[3]^,t3,sizeof(t1)); { counterclock point 3}
-
- for j:= 1 to 3 do {x,y,z}
- begin
- u[j]:= t2[j] - t1[j];
- v[j]:= t3[j] - t1[j];
- end;
-
- n[1]:= (u[2] * v[3]) - (u[3] * v[2]); {cross product of u * v}
- n[2]:= (u[3] * v[1]) - (u[1] * v[3]);
- n[3]:= (u[1] * v[2]) - (u[2] * v[1]);
- object.side[i].face[0]^:= n; {side[0] gets the normal}
-
- for k := 1 to 3 do
- lambda [k] := temp_L[k] - temp.face[i]^[k]; {5.2 pg 187}
-
- dotnl := 0; {dot product of n*l}
- for k := 1 to 3 do
- dotnl := dotnl + object.side[i].face[0]^[k] * lambda[k];
- if dotnl > 0 then object.side[i].visib :=true
- else object.side[i].visib :=false;
- end;
- end;
-
-
-
- procedure erasescreen;
- begin
- fillchar(display,16384,char(0));
- end;
-
-
- procedure eye(theta:integer; fee:integer);
- var
- st,sf :real;
- ct,cf :real;
- te1,te2:real;
-
- begin
- init(form);
- te1 := theta *pi;
- te2 := fee *pi;
- ct := cos (te1);
- cf := cos (te2);
- st := sin (te1);
- sf := sin (te2);
- form[1,1] := -st; {page 159 park}
- form[1,2] := -ct * cf;
- form[1,3] := -ct * sf;
- form[2,1] := ct;
- form[2,2] := -st * cf;
- form[2,3] := -st * sf;
- form[3,2] := sf;
- form[3,3] := -cf;
- form[4,3] := eyedis;
- transfer(form,matr,matrcnt);
- end;
-
-
- procedure origin(object:objectype;axis:axistype; value :real);
- var
- i:integer;
-
- begin
- case axis of
- x:object.center[x]:= object.center[x]+value;
- y:object.center[y]:= object.center[y]+value;
- z:object.center[z]:= object.center[z]+value;
- end;
- end;
-
-
- procedure translate (axis : axistype; value : real; copy :objectype);
-
- begin
- case axis of
- x : begin
- for i:= 1 to copy.pntno do
- copy.pntlst[i,1]:= copy.pntlst[i,1]+value;
- end;
- y : begin
- for i:= 1 to copy.pntno do
- copy.pntlst[i,2]:= copy1.pntlst[i,2]+value;
- end;
- z : begin
- for i:= 1 to copy.pntno do
- copy.pntlst[i,3]:= copy.pntlst[i,3]+value;
- end;
- end;
- end;
-
-
- procedure rotate (axis : axistype; value:real);
- var
- cv,sv:real;
- i,j :integer;
- t1 :real;
- begin
- t1 := value *pi;
- cv := cos (t1);
- sv := sin (t1);
- init(form);
- case axis of
- x : begin
- form [2,2] := cv;
- form [2,3] := sv;
- form [3,2] := -sv;
- form [3,3] := cv;
- end;
- y : begin
- form [1,1] := cv;
- form [1,3] :=-sv;
- form [3,1] := sv;
- form [3,3] := cv;
- end;
- z : begin
- form [1,1] := cv;
- form [1,2] := sv;
- form [2,1] := -sv;
- form [2,2] := cv;
- end;
- end; {case}
- transfer(form,matr,matrcnt);
- end; {of rotate}
-
-
- procedure arbit(head :real;
- bank :real; pitch :real);
-
- var
- ch,cb,cp :real;
- sh,sb,sp :real;
-
- begin
- init(form);
- head :=(head * pi);
- bank :=(bank * pi);
- pitch:=(pitch * pi);
- ch:=cos(head);
- cb:=cos(bank);
- cp:=cos(pitch);
- sh:=sin(head);
- sb:=sin(bank);
- sp:=sin(pitch);
- form[1,1]:= (ch * cb) + (sh * sp * sb);
- form[1,2]:= -(ch * sb) + (sh * sp * cb);
- form[1,3]:= sh * cp;
- form[2,1]:= sb * cp;
- form[2,2]:= cb * cp;
- form[2,3]:= -sp;
- form[3,1]:= -(sh * cb) - (ch * sp * sb);
- form[3,2]:= (sb * sh) + (ch * sp * cb);
- form[3,3]:= ch * cp;
- transfer(form,matr,matrcnt);
- end;
-
- procedure reflection (plane :planetype);
-
- begin
- init(form);
- case plane of
- xy : begin
- form [1,1] := 1;
- form [2,2] := 1;
- form [3,3] := -1;
- form [4,4] := 1;
- end;
- yz : begin
- form [1,1] :=-1;
- form [2,2] := 1;
- form [3,3] := 1;
- form [4,4] := 1;
- end;
- xz : begin
- form [1,1] := 1;
- form [2,2] :=-1;
- form [3,3] := 1;
- form [4,4] := 1;
- end;
- end; {case}
- transfer(form,matr,matrcnt);
- end; {of reflect}
-
-
- procedure scaling (axis :axistype; value : real );
-
- begin
- init(form);
- case axis of
- x : form [1,1] := value;
- y : form [2,2] := value;
- z : form [3,3] := value;
- end;
- transfer(form,matr,matrcnt);
- end; {of scaling}
-
-
- {procedure choose(copy:objectype);
-
- var
- temp : array[1..4] of real;
- i,j,k : integer;
- count : integer;
- x1,x2 : integer;
- y1,y2 : integer;
- z1,z2 : integer;
-
- begin
- for i:= 1 to 4 do
- current[i] := i + 4;
- current[5] := 5;
-
- for count := 1 to 5 do
- begin
- for i:= 1 to 4 do
- temp[i] := 0;
-
- for j := 1 to 4 do
- for k := 1 to 4 do
- temp[j] := temp[j] + copy[current[count],k] * form[k,j];
-
- for i := 1 to 4 do
- copy[current[count],i]:=temp[i];
- end;
-
- for i:= 1 to 4 do
- begin
- writeln(copy[current[i] ,3]:2:2,' ',copy[current[i+1],3]:2:2);
- z1:=round(copy[current[i] ,3]);
- z2:=round(copy[current[i+1],3]);
- x1:=round(copy[current[i] ,1]*xsize+320);
- x2:=round(copy[current[i+1],1]*xsize+320);
- y1:=round(copy[current[i] ,2]*ysize+100);
- y2:=round(copy[current[i+1],2]*ysize+100);
- draw(x1,y1,x2,y2,1);
- end;
- for i:= 1 to 4 do
- begin
- hirescolor(0);
- x1:=round(copy[current[i] ,1]*xsize+320);
- x2:=round(copy[current[i+1],1]*xsize+320);
- y1:=round(copy[current[i] ,2]*ysize+100);
- y2:=round(copy[current[i+1],2]*ysize+100);
- draw(x1,y1,x2,y2,0);
- end;
- hirescolor(9);
- end;}
-
-
-
-
- begin
- fileno:=0;
- matrcnt:=0;
- graphcolormode;
- fillchar(copy1,sizeof(copy1),char(0));
- fillchar(obj1,sizeof(obj1),char(0));
- fillchar(matr,sizeof(matr),char(0));
- comein;
- for k := 0 to 19 do
- begin
- { arbit(45,45,0);}
- { eye(45,45);}
- rotate(x,k/4);rotate(y,k/4);rotate(x,k/4);
- mult(matrcnt,matr);
- transform(copy1,obj1,matr[1]);
- normal(copy1,4,0,0);
- erasescreen;
- render:=true; {fill shapes}
- plotit(copy1,0);
- savescreen;
-
- end;
- show(19);
- end.