Initial commit of 1992 raytracing code
This commit is contained in:
commit
3f46e7dd82
42 changed files with 8483 additions and 0 deletions
194
turbo-pascal/ray6.pas
Normal file
194
turbo-pascal/ray6.pas
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
program mmmmmmmmmmmmm;
|
||||
{$X+}
|
||||
uses Crt,Modex,RayTrace;
|
||||
|
||||
{ r,g,b:0-255 }
|
||||
function Rgb(r,g,b: Integer): Integer;
|
||||
begin
|
||||
if r > 255 then r := 255;
|
||||
if g > 255 then g := 255;
|
||||
if b > 255 then b := 255;
|
||||
Rgb := (b shr 6) or ((g shr 3) and $1c) or (r and $e0);
|
||||
end;
|
||||
|
||||
procedure RgbDot(x,y,r,g,b: Integer);
|
||||
var
|
||||
r1,g1,b1,r2,g2,b2,c1,c2: Integer;
|
||||
begin
|
||||
if r > 255 then r := 255;
|
||||
if g > 255 then g := 255;
|
||||
if b > 255 then b := 255;
|
||||
if r < 0 then r := 0;
|
||||
if g < 0 then g := 0;
|
||||
if b < 0 then b := 0;
|
||||
r1 := r and $e0; g1 := g and $e0; b1 := b and $c0;
|
||||
r2 := r1 + (r mod 32)+16;
|
||||
g2 := g1 + (g mod 32)+16;
|
||||
b2 := b1 + (b mod 64)+32;
|
||||
c1 := Rgb(r1,g1,b1); c2 := Rgb(r2,g2,b2);
|
||||
if (x mod 2) = (y mod 2) then PutPixel(x,y,c1) else PutPixel(x,y,c2);
|
||||
end;
|
||||
|
||||
procedure SetUpRgb;
|
||||
var
|
||||
Clrs: array[0..255,0..2] of Byte;
|
||||
i: Integer;
|
||||
begin
|
||||
for i := 0 to 255 do begin
|
||||
Clrs[i,0] := (i and $e0) shr 2;
|
||||
Clrs[i,1] := (i and $1c) shl 1;
|
||||
Clrs[i,2] := (i and 3) shl 4;
|
||||
case Clrs[i,2] of
|
||||
15..31: Inc(Clrs[i,2],4);
|
||||
32..63: Inc(Clrs[i,2],8);
|
||||
end;
|
||||
end;
|
||||
SetColorBlock(0,256,Clrs);
|
||||
end;
|
||||
|
||||
type
|
||||
pplane = object(Plane)
|
||||
function GetColor(aray: Ray; time: Real): LongInt; virtual;
|
||||
end;
|
||||
ColorSphere = object(Sphere)
|
||||
rc,gc,bc: Byte;
|
||||
constructor Init(x,y,z,r: Real; cr,cg,cb: Byte);
|
||||
function GetColor(aray: Ray; time: Real): LongInt; virtual;
|
||||
end;
|
||||
|
||||
constructor ColorSphere.Init(x,y,z,r: Real; cr,cg,cb: Byte);
|
||||
begin
|
||||
Sphere.Init(x,y,z,r);
|
||||
rc := cr; gc := cg; bc := cb;
|
||||
end;
|
||||
|
||||
function ColorSphere.GetColor(aray: Ray; time: Real): LongInt;
|
||||
var
|
||||
r: Ray;
|
||||
c: LongInt;
|
||||
cc: record b,g,r: Byte end absolute c;
|
||||
begin
|
||||
ReflectRay(aray,time,r);
|
||||
c := Owner^.TraceRay(r);
|
||||
cc.r := Integer(cc.r) div 2 + rc;
|
||||
cc.g := Integer(cc.g) div 2 + gc;
|
||||
cc.b := Integer(cc.b) div 2 + bc;
|
||||
GetColor := c;
|
||||
end;
|
||||
|
||||
function pplane.GetColor(aray: Ray; time: Real): LongInt;
|
||||
var
|
||||
r: Ray;
|
||||
c: LongInt;
|
||||
cc: record b,g,r: Byte end absolute c;
|
||||
begin
|
||||
ReflectRay(aray,time,r);
|
||||
c := Owner^.TraceRay(r);
|
||||
cc.r := Integer(cc.r) div 2 + 128;
|
||||
cc.g := Integer(cc.g) div 2 + 128;
|
||||
cc.b := Integer(cc.b) div 2;
|
||||
GetColor := c;
|
||||
end;
|
||||
|
||||
procedure Draw(var u: Universe);
|
||||
var
|
||||
x,y: Integer;
|
||||
c: LongInt;
|
||||
begin
|
||||
x := 0;
|
||||
while (x < 320) and (not KeyPressed) do begin
|
||||
for y := 0 to 239 do begin
|
||||
c := u.TracePoint(x,239-y);
|
||||
if c <> 0 then
|
||||
RgbDot(x,y,(c and $ff0000) shr 16,(c and $ff00) shr 8,c and $ff);
|
||||
end;
|
||||
Inc(x);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure Quick(var u: Universe);
|
||||
var
|
||||
x,y: Integer;
|
||||
c: LongInt;
|
||||
r,g,b: Byte;
|
||||
begin
|
||||
x := 0;
|
||||
while (x < 160) and (not KeyPressed) do begin
|
||||
for y := 0 to 119 do begin
|
||||
c := u.TracePoint(x*2,239-(y*2));
|
||||
if c <> 0 then begin
|
||||
r := (c and $ff0000) shr 16;
|
||||
g := (c and $ff00) shr 8;
|
||||
b := c and $ff;
|
||||
RgbDot(x*2,y*2,r,g,b); RgbDot(x*2+1,y*2,r,g,b);
|
||||
RgbDot(x*2+1,y*2+1,r,g,b); RgbDot(x*2,y*2+1,r,g,b);
|
||||
end;
|
||||
end;
|
||||
Inc(x);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure Zoom(var u: Universe);
|
||||
var
|
||||
x,y,i,j: Integer;
|
||||
c: LongInt;
|
||||
r,g,b: Byte;
|
||||
begin
|
||||
x := 0;
|
||||
while (x < 80) and (not KeyPressed) do begin
|
||||
for y := 0 to 59 do begin
|
||||
c := u.TracePoint(x*4,239-(y*4));
|
||||
if c <> 0 then begin
|
||||
r := (c and $ff0000) shr 16;
|
||||
g := (c and $ff00) shr 8;
|
||||
b := c and $ff;
|
||||
for i := 0 to 3 do
|
||||
for j := 0 to 3 do
|
||||
RgbDot(x*4+i,y*4+j,r,g,b);
|
||||
end;
|
||||
end;
|
||||
Inc(x);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure Beep;
|
||||
begin
|
||||
Sound(220); { Beep }
|
||||
Delay(200); { For 200 ms }
|
||||
NoSound; { Relief! }
|
||||
end;
|
||||
|
||||
procedure TraceIt;
|
||||
var
|
||||
u: Universe;
|
||||
p: Pplane;
|
||||
pp,p1: Plane;
|
||||
r,g,b,w: ColorSphere;
|
||||
begin
|
||||
u.Init(320,240);
|
||||
p.Init (0.0, -8.0, 0.0, 0.0, 1.0, 0.0);
|
||||
pp.Init (8.0, 0.0, 0.0, 1.0, 1.0, 0.0);
|
||||
p1.Init (8.0, 30.0, 0.0, -1.0, 1.0, 0.0);
|
||||
r.Init(-15,-3,50,5, 128,0,0);
|
||||
g.Init(-10,-3,45,5, 0,128,0);
|
||||
b.Init(-5,-3,50,5, 0,0,128);
|
||||
w.Init(-10,2,47.5,5, 128,128,128);
|
||||
u.Insert(@p);
|
||||
u.Insert(@pp);
|
||||
u.Insert(@p1);
|
||||
u.Insert(@r);
|
||||
u.Insert(@g);
|
||||
u.Insert(@b);
|
||||
u.Insert(@w);
|
||||
Zoom(u);
|
||||
Beep;
|
||||
u.Done;
|
||||
end;
|
||||
|
||||
begin
|
||||
SetModeX;
|
||||
SetUpRgb;
|
||||
TraceIt;
|
||||
ReadKey;
|
||||
BiosMode(3);
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue