home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Homebrewer's Handbook / vr.iso / 3dgraph / pascal / chap2_3.bak < prev    next >
Text File  |  1996-03-19  |  2KB  |  93 lines

  1. program chap2_3;
  2.  
  3. uses graph, crt;
  4.  
  5. const xoffset=640/2;
  6.       yoffset=480/2;
  7.       xscale=1;
  8.       yscale=-1;
  9.  
  10. type point=record
  11.        xw, yw, zw : real;
  12.        xs, ys, zs : integer;
  13.      end;
  14.  
  15. var vertex : array[1..18] of point;
  16.     edges : array[1..27,1..27] of integer;
  17.     f : text;
  18.     c : integer;
  19.     ch : char;
  20.  
  21. procedure Initialise_Graphics;
  22. var Graphdriver, Graphmode, Errorcode : integer;
  23. begin
  24.      Graphdriver:=Detect;
  25.      InitGraph(Graphdriver, Graphmode,'');
  26.      Errorcode:=graphresult;
  27.      if Errorcode<>grOk then
  28.      begin
  29.           writeln('Graphics Error: ',GraphErrorMsg(ErrorCode));
  30.           writeln('Program Aborted');
  31.           Halt(1);
  32.      end;
  33.      SetLineStyle(0,0,3);
  34. end;
  35.  
  36. procedure draw_picture;
  37. var c : integer;
  38. begin
  39.      ClearDevice;
  40.      for c:=1 to 27 do
  41.           line(vertex[edges[c,1]].xs,vertex[edges[c,1]].ys,vertex[edges[c,2]].xs,vertex[edges[c,2]].ys);
  42. end;
  43.  
  44. procedure transform;
  45. var c : integer;
  46. begin
  47.      for c:=1 to 18 do
  48.      begin
  49.          vertex[c].xs:=round((vertex[c].xw*xscale)+xoffset);
  50.          vertex[c].ys:=round((vertex[c].yw*yscale)+yoffset);
  51.          vertex[c].zs:=round(vertex[c].zw);
  52.      end;
  53. end;
  54.  
  55. begin
  56.      clrscr;
  57.      writeln; writeln; writeln; writeln; writeln; writeln; writeln;
  58.      writeln('This is from Chapter 2 Step 3 of the Virtual Reality Homebrewer''s Handbook and');
  59.      writeln('shows how to draw a virtual shape in wireframe.');
  60.      writeln;
  61.      writeln;
  62.      writeln;
  63.      writeln('                Press any key to continue');
  64.      ch:=ReadKey;
  65.      {Read in vertices}
  66.      assign(f,'points.dat');
  67.      reset(f);
  68.      for c:=1 to 18 do
  69.      begin
  70.           readln(f,vertex[c].xw,vertex[c].yw,vertex[c].zw);
  71.      end;
  72.      close(f);
  73.  
  74.      {Move to z=500}
  75.      for c:=1 to 18 do
  76.      begin
  77.           vertex[c].zw:=vertex[c].zw+500;
  78.      end;
  79.  
  80.      {Read in edges}
  81.      assign(f,'edges.dat');
  82.      reset(f);
  83.      for c:=1 to 27 do
  84.          readln(f,edges[c,1], edges[c,2]);
  85.      close(f);
  86.  
  87.      Initialise_Graphics;
  88.  
  89.      transform;
  90.      draw_picture;
  91.      repeat until keypressed;
  92.      CloseGraph;
  93. end.