home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FH-3DTUT.ZIP / TUT3.PAS < prev    next >
Pascal/Delphi Source File  |  1996-01-01  |  3KB  |  95 lines

  1. program Tutorial3; {to get the basics take a look at TUT1.PAS and TUT2.PAS}
  2. {AnyObject Rotation Interactive
  3.  Made by fh94.3 (C) 12/24/1995
  4.  Mail: fh@viktoria.drp.fmph.uniba.sk
  5.  
  6.  Based on explanation by Synergist (rhr0982@grace.rit.edu).
  7. }
  8. uses tutunit,crt;
  9.  
  10. var xt,yt,zt:real; {temp points}
  11.     ch:char; {for key you want to press}
  12.     xan,yan,zan:real; {angles for axis X,Y,Z}
  13.     sx,sy,sx1,sy1,p,zoom,p1: integer; {Screen coords X,Y}
  14.     points,lines:byte; {nr. of points and lines of the object}
  15.     obj: array[0..511] of real; {object to rotate (max 512 points}
  16.     lobj: array[0..1023] of integer; {line index of object (max 1024}
  17.  
  18. procedure readdata; {reads the datafile}
  19. var f:text;
  20. begin
  21. if ParamCount <> 1 then begin writeln('Usage: TUT3 datafile'); halt(0); end;
  22. assign(F,Paramstr(1));
  23. reset(F);
  24. readln(F,points,lines);
  25. p1:=0;
  26. for p:=1 to points do begin readln(F,obj[p1],obj[p1+1],obj[p1+2]); p1:=p1+3; end;
  27. {reads the coords of points 0 to points}
  28. p1:=0;
  29. for p:=1 to lines do begin readln(F,lobj[p1],lobj[p1+1]); p1:=p1+2; end;
  30. {reads the index of lines 0 to lines}
  31. close(F);
  32. end;
  33.  
  34. procedure draw(color:byte); {procedure to draw a cube}
  35. begin
  36.  for p:=0 to lines-1 do begin {loops for all lines}
  37.   sx:=round(zoom*obj[lobj[p*2]*3])+160; {x coord for point1}
  38.   sy:=round(zoom*obj[lobj[p*2]*3+1])+100; {y coord for point1}
  39.   sx1:=round(zoom*obj[lobj[p*2+1]*3])+160; {x coord for point2}
  40.   sy1:=round(zoom*obj[lobj[p*2+1]*3+1])+100; {y coord for point2}
  41.   drawline(SX,SY,sx1,sy1,color); {draw line between points 1&2 in current color}
  42.  end;
  43. end;
  44.  
  45. procedure calc; {calculates new values after rotate step}
  46. begin
  47. for p:=0 to points-1 do begin {repeats for all points}
  48. Yt := obj[p*3+1] * COS(Xan) - obj[p*3+2] * SIN(Xan); {read old values from the table of coord,}
  49. Zt := obj[p*3+1] * SIN(Xan) + obj[p*3+2] * COS(Xan); {rotating about x axis}
  50. obj[p*3+1] := Yt; {writes the new values back to the table}
  51. obj[p*3+2] := Zt;
  52.  
  53. Xt := obj[p*3] * COS(Yan) - obj[p*3+2] * SIN(Yan); {same as above, for Y axis}
  54. Zt := obj[p*3] * SIN(Yan) + obj[p*3+2] * COS(Yan);
  55. obj[p*3] := Xt;
  56. obj[p*3+2] := Zt;
  57.  
  58. Xt := obj[p*3] * COS(Zan) - obj[p*3+1] * SIN(Zan); {about Z axis}
  59. Yt := obj[p*3] * SIN(Zan) + obj[p*3+1] * COS(Zan);
  60. obj[p*3] := Xt;
  61. obj[p*3+1] := Yt;
  62. end;
  63. end;
  64.  
  65. begin
  66. readdata;
  67. Mcgaon;       {sets the 13h (320x200x256) mode}
  68. Zan :=  0.0;  {rotation about Z axis by this angle}
  69. Yan :=  0.0;  {rotation about Y axis by this angle}
  70. Xan :=  0.0;  {rotation about X axis by this angle}
  71. zoom:=30;     {size of the object}
  72.  
  73. {check;}
  74. draw(15);     {draws the cube}
  75. repeat        {loops ...}
  76.  ch:=readkey;
  77.  clearscreen;      {guess...:>}
  78.   case ch of
  79.    #72 : xan:=+0.05; {increases angle x}
  80.    #75 : yan:=-0.05; {decreases angle y}
  81.    'Z' : zan:=+0.05; {...}
  82.    #80 : xan:=-0.05; {...}
  83.    #77 : yan:=+0.05;
  84.    'z' : zan:=-0.05;
  85.    '+' : zoom:=zoom+5;
  86.    '-' : zoom:=zoom-5;
  87.   end;
  88. calc;         {calculates the new coords}
  89. draw(15);     {draws it again}
  90. delay(30);    {wait a sec!}
  91. until ch=#27; {... 'till you press ESC}
  92. mcgaoff;      {jump back to text mode}
  93. end.
  94.  
  95.