home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / PHRO.ZIP / BILL.PAS < prev    next >
Pascal/Delphi Source File  |  1995-07-21  |  9KB  |  318 lines

  1. {   Image Warping Source file                  }
  2. {   PHRO!                                      }
  3. {   Phred/OTM                                  }
  4. {   achalfin@uceng.uc.edu                      }
  5. {   DO NOT DISTRIBUTE THIS SOURCE FILE         }
  6. Unit Bill;
  7.  
  8. Interface
  9.  
  10. Procedure ClintonMorph;
  11.  
  12. Implementation
  13.  
  14. Uses Pcx, Polygons, Palettes;
  15.  
  16. Const
  17.   XGrid = 16;  { Number of grid points going horizontal }
  18.   YGrid = 13;  { Number of grid points going vertical   }
  19.   NumGrids = 7;
  20.  
  21. Type
  22.   tArray = Array[0..256*256-2] of Byte;
  23.   pArray = ^tArray;
  24.   PointType = Record
  25.     x, y : Integer;
  26.   End;
  27.   tGrid = Array[0..(XGrid - 1), 0..(YGrid - 1)] of PointType;
  28.   pGrid = ^tGrid;
  29.  
  30. Const
  31.   Box : Array[0..3] of PointType = ((x:-100;y:100),(x:100;y:100),
  32.                                       (x:100;y:-100),(x:-100;y:-100));
  33.  
  34.  
  35. Var
  36.   WorldPoints : Array[0..3] of PointType;
  37.   GrdPtr : Pointer;
  38.   OGrid : tGrid;
  39.   Grids : Array[0..10] of pGrid;
  40.   Billy : pArray;
  41.   vPage : pArray;
  42.   Sine, CoSine : Array[0..255] of Longint;
  43.  
  44. Procedure CalcSine;
  45.  
  46. Var
  47.   Count : Integer;
  48.  
  49. Begin
  50.   For Count := 0 to 255 do
  51.     Begin
  52.       Sine[Count] := Round(Sin(2*Pi*Count/256)*256);
  53.       CoSine[Count] := Round(Cos(2*Pi*Count/256)*256);
  54.     End;
  55. End;
  56.  
  57. Procedure RotateBox(Angle : Integer; Scale : Longint);
  58.  
  59. Var
  60.   TempX, TempY : Longint;
  61.   Count : Integer;
  62.  
  63. Begin
  64.   For Count := 0 to 3 do
  65.     Begin
  66.       TempX := Box[Count].x;
  67.       TempY := Box[Count].y;
  68.       WorldPoints[Count].x := Longint(TempX*CoSine[Angle]-TempY*Sine[Angle]) Div 256;
  69.       WorldPoints[Count].y := Longint(TempX*Sine[Angle]+TempY*CoSine[Angle]) Div 256;
  70.       WorldPoints[Count].x := (WorldPoints[Count].x * Scale) Div 256+ 160;
  71.       WorldPoints[Count].y := (WorldPoints[Count].y * Scale) Div 256 + 100;
  72.     End;
  73. End;
  74.  
  75. Procedure WhirlOut;
  76.  
  77. Var
  78.   Count, Angle : Integer;
  79.  
  80. Begin
  81.   FillChar(Mem[$A000:0], 64000, 0);
  82.   Angle := 0;
  83.   For Count := 255 downto 0 do
  84.     Begin
  85.       RotateBox(Angle, Count Shr 1);
  86.       Angle := (Angle + 1) And 255;
  87.       Asm
  88.         Les  di,VPage
  89.         db 66h; Xor  ax,ax
  90.         db 66h; Mov  cx,16000; dw 0;
  91.         db 66h; Rep  Stosw
  92.       End;
  93.       GouraudClipPolygon(WorldPoints[0].x, WorldPoints[0].y,
  94.                        WorldPoints[1].x, WorldPoints[1].y,
  95.                        WorldPoints[2].x, WorldPoints[2].y,
  96.                        100, 100, 100, Seg(VPage^));
  97.       GouraudClipPolygon(WorldPoints[0].x, WorldPoints[0].y,
  98.                        WorldPoints[2].x, WorldPoints[2].y,
  99.                        WorldPoints[3].x, WorldPoints[3].y,
  100.                        100, 100, 100,Seg(VPage^));
  101.       Asm
  102.         Push  ds
  103.         Mov   ax,$A000
  104.         Mov   es,ax
  105.         Xor   di,di
  106.         Lds   si,VPage
  107.         db 66h; Mov  cx, 16000; dw 0;
  108.         db 66h; Rep  Movsw;
  109.         Pop   ds
  110.       End;
  111.     End;
  112. End;
  113.  
  114. Procedure InitGrid;
  115. { Standardizes the grid points }
  116.  
  117. Var
  118.   x, y : Integer;
  119.  
  120. Begin
  121.   For x := 0 to (XGrid - 1) do
  122.     For y := 0 to (YGrid - 1) do
  123.       Begin
  124.         oGrid[x, y].x := x Shl 4;
  125.         oGrid[x, y].y := y Shl 4;
  126.       End;
  127. End;
  128.  
  129. Procedure DrawBill(Grid : tGrid);
  130.  
  131. Var
  132.   xCount, yCount : Integer;
  133.  
  134. Begin
  135.   Asm
  136.     Les  di,VPage
  137.     db 66h; Xor ax,ax
  138.     db 66h; Mov cx,16000; dw 0;
  139.     db 66h; Rep Stosw
  140.   End;
  141.   For xCount := 0 to (xGrid - 2) do
  142.     For yCount := 0 to (yGrid - 2) do
  143.       Begin
  144.         PhongClipPolygon(Grid[xCount, yCount].x, Grid[xCount, yCount].y,
  145.                          Grid[xCount, yCount+1].x, Grid[xCount, yCount+1].y,
  146.                          Grid[xCount+1, yCount+1].x, Grid[xCount+1, yCount+1].y,
  147.                          oGrid[xCount, yCount].x, oGrid[xCount, yCount].y,
  148.                          oGrid[xCount, yCount+1].x, oGrid[xCount, yCount+1].y,
  149.                          oGrid[xCount+1, yCount+1].x, oGrid[xCount+1, yCount+1].y,
  150.                          Seg(VPage^), Billy);
  151.         PhongClipPolygon(Grid[xCount, yCount].x, Grid[xCount, yCount].y,
  152.                          Grid[xCount+1, yCount].x, Grid[xCount+1, yCount].y,
  153.                          Grid[xCount+1, yCount+1].x, Grid[xCount+1, yCount+1].y,
  154.                          oGrid[xCount, yCount].x, oGrid[xCount, yCount].y,
  155.                          oGrid[xCount+1, yCount].x, oGrid[xCount+1, yCount].y,
  156.                          oGrid[xCount+1, yCount+1].x, oGrid[xCount+1, yCount+1].y,
  157.                          Seg(VPage^), Billy);
  158.       End;
  159.   For xCount := 0 to 199 do
  160.     Move(VPage^[xCount*320], Mem[$A000:xCount*320+32], 256);
  161. End;
  162.  
  163. Procedure Action;
  164.  
  165. Const
  166.   NumSteps = 30;
  167.  
  168. Var
  169.   TempGrid : tGrid;
  170.   ValGrid : tGrid;
  171.   StepGrid : tGrid;
  172.   Count, xCount, yCount : Integer;
  173.   FrameCount : Integer;
  174.  
  175. Begin
  176.   For Count := 0 to (NumGrids-2) do
  177.     Begin
  178.       For xCount := 0 to (xGrid-1) do
  179.         For yCount := 0 to (yGrid-1) do
  180.           Begin
  181.             ValGrid[xCount, yCount].x := Grids[Count]^[xCount, yCount].x Shl 6;
  182.             ValGrid[xCount, yCount].y := Grids[Count]^[xCount, yCount].y Shl 6;
  183.             StepGrid[xCount, yCount].x :=
  184.               (Grids[Count+1]^[xCount, yCount].x-Grids[Count]^[xCount, yCount].x) Shl 6
  185.                 Div NumSteps;
  186.             StepGrid[xCount, yCount].y :=
  187.               (Grids[Count+1]^[xCount, yCount].y-Grids[Count]^[xCount, yCount].y) Shl 6
  188.                 Div NumSteps;
  189.           End;
  190.       For FrameCount := 0 to (NumSteps-1) do
  191.         Begin
  192.           For xCount := 0 to (xGrid-1) do
  193.             For yCount := 0 to (yGrid-1) do
  194.               Begin
  195.                 TempGrid[xCount, yCount].x := ValGrid[xCount, yCount].x Shr 6;
  196.                 TempGrid[xCount, yCount].y := ValGrid[xCount, yCount].y Shr 6;
  197.                 Inc(ValGrid[xCount, yCount].x, StepGrid[xCount, yCount].x);
  198.                 Inc(ValGrid[xCount, yCount].y, StepGrid[xCount, yCount].y);
  199.               End;
  200.           DrawBill(TempGrid);
  201.         End;
  202.     End;
  203. End;
  204.  
  205. {$F+}
  206. {$L Grid.Obj}
  207. Procedure GridLocations; External;
  208. {$F-}
  209.  
  210. Procedure GetGrids;
  211.  
  212. Var
  213.   GrdSeg, GrdOfs : Word;
  214.   Count : Integer;
  215.   xCount, yCount : Integer;
  216.  
  217. Begin
  218.   GrdSeg := Seg(GrdPtr^);
  219.   GrdOfs := Ofs(GrdPtr^);
  220.   For Count := 0 to (NumGrids-2) do
  221.     Begin
  222.       New(Grids[Count]);
  223.       For xCount := 0 to (xGrid-1) do
  224.         For yCount := 0 to (yGrid-1) do
  225.           Begin
  226.             Grids[Count]^[xCount, yCount].x := MemW[GrdSeg:GrdOfs];
  227.             Inc(GrdOfs, 2);
  228.             Grids[Count]^[xCount, yCount].y := MemW[GrdSeg:GrdOfs];
  229.             Inc(GrdOfs, 2);
  230.           End;
  231.     End;
  232.   New(Grids[NumGrids-1]);
  233.   Move(Grids[0]^, Grids[NumGrids-1]^, Sizeof(tGrid));
  234. End;
  235.  
  236. Procedure FadeIn;
  237.  
  238. Type
  239.   RGB = Record
  240.     r,g,b : Byte;
  241.   End;
  242.   palette = Array[0..255] of RGB;
  243.  
  244. Var
  245.   Pal1, Pal2 : Palette;
  246.   Count, Count1 : Integer;
  247.  
  248. Begin
  249.   Move(ClintonPalettePtr^, Pal1, 768);
  250.   FillChar(Pal2, 768, 0);
  251.   For Count := 0 to 255 do
  252.     Begin
  253.       Port[$3c8] := Count1;
  254.       Port[$3c9] := Pal2[Count1].r;
  255.       Port[$3c9] := Pal2[Count1].g;
  256.       Port[$3c9] := Pal2[Count1].b;
  257.     End;
  258.   FillChar(Mem[$A000:0], 64000, 0);
  259.   DrawBill(Grids[0]^);
  260.   For Count := 0 to 63 do
  261.     Begin
  262.       For Count1 := 0 to 255 do
  263.         Begin
  264.           If Pal2[Count1].r < Pal1[Count1].r
  265.             Then Inc(Pal2[Count1].r);
  266.           If Pal2[Count1].r > Pal1[Count1].r
  267.             Then Dec(Pal2[Count1].r);
  268.           If Pal2[Count1].g < Pal1[Count1].g
  269.             Then Inc(Pal2[Count1].g);
  270.           If Pal2[Count1].g > Pal1[Count1].g
  271.             Then Dec(Pal2[Count1].g);
  272.           If Pal2[Count1].b < Pal1[Count1].b
  273.             Then Inc(Pal2[Count1].b);
  274.           If Pal2[Count1].b > Pal1[Count1].b
  275.             Then Dec(Pal2[Count1].b);
  276.         End;
  277.       Asm
  278.         Mov  dx,$3da
  279.        @Looper:
  280.         In   al,dx
  281.         And  al,8
  282.         Jz  @Looper
  283.       End;
  284.       For Count1 := 0 to 255 do
  285.         Begin
  286.           Port[$3c8] := Count1;
  287.           Port[$3c9] := Pal2[Count1].r;
  288.           Port[$3c9] := Pal2[Count1].g;
  289.           Port[$3c9] := Pal2[Count1].b;
  290.         End;
  291.     End;
  292. End;
  293.  
  294. Procedure ClintonMorph;
  295.  
  296. Var
  297.   Cheap : Pointer;
  298.  
  299. Begin
  300.   Mark(Cheap);
  301.   New(VPage);
  302.   New(Billy);
  303.   InitGrid;
  304.   DecompressPCX(Billy^, BillClintonPtr^);
  305.   GetGrids;
  306.   FadeIn;
  307.   Action;
  308.   WhirlOut;
  309.   Dispose(Billy);
  310.   Dispose(VPage);
  311.   Release(Cheap);
  312. End;
  313.  
  314.  
  315. Begin
  316.   CalcSine;
  317.   GrdPtr := @GridLocations;
  318. End.