home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Virtual Reality Homebrewer's Handbook
/
vr.iso
/
vroom
/
math.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-03-19
|
3KB
|
103 lines
program math;
uses graph, vroom, crt, time, fixed, cyberman;
const xdiv=20;
ydiv=20;
xunit=1;
yunit=1;
mult=(3.14159/10);
function height(x, y, t : real) : real;
begin
height:=Sin(x*mult)*Sin(y*mult)*sin(t*mult)*5;
end;
var point : array[0..xdiv,0..ydiv] of vertex;
square : array[1..xdiv,1..ydiv,1..2] of face;
surface : object3d;
x, y : integer;
ch : char;
ok, moving, mouse, cyber : boolean;
procedure Update;
var junk : boolean;
begin
if moving then
begin
for x:=0 to xdiv do
for y:=0 to ydiv do
begin
point[x,y].world.z:=real_to_fixed(height(x*xunit,y*yunit,GetSecondsTime));
end;
surface.Build_Normals;
surface.redraw:=true;
end;
if cyber then junk:=cyberman_check else if mouse then junk:=mouse_check else junk:=false;
if (KeyBoard_Check or Moving or junk) then redraw_scene;
end;
{$F+}
function My_KeyCheck(key : char) : boolean;
begin
if key='m' then
begin
moving:=not(moving);
My_KeyCheck:=true;
end
else
My_KeyCheck:=false;
end;
{$F-}
begin
mouse:=false;
cyber:=false;
if cyberman_available then cyber:=true
else if mouse_available then mouse:=true;
Init_System;
Set_Ambient_Intensity(0.5);
Set_Light(0.75,0,-1,-0.75);
Set_View(200,0,0,0,0,0);
Set_Window(-20,-15,20,15);
User_KeyCheck_Proc(My_KeyCheck);
moving:=false;
surface.Init;
for x:=0 to xdiv do
for y:=0 to ydiv do
begin
point[x,y].next:=surface.first_vertex;
surface.first_vertex:=@point[x,y];
point[x,y].data(x*xunit,y*yunit,height(x*xunit,y*yunit,GetSecondsTime));
end;
for x:=1 to xdiv do
for y:=1 to ydiv do
begin
square[x,y,1].Init(surface,2,1);
square[x,y,1].Add_Vertex(@point[x-1,y-1]);
square[x,y,1].Add_Vertex(@point[x,y-1]);
square[x,y,1].Add_Vertex(@point[x,y]);
square[x,y,1].Add_Vertex(@point[x-1,y]);
square[x,y,2].Init(surface,2,1);
square[x,y,2].Add_Vertex(@point[x-1,y]);
square[x,y,2].Add_Vertex(@point[x,y]);
square[x,y,2].Add_Vertex(@point[x,y-1]);
square[x,y,2].Add_Vertex(@point[x-1,y-1]);
end;
surface.Build_Normals;
surface.Set_Reference_Point(5,5,height(x*xunit,y*yunit,GetSecondsTime));
surface.MoveTo(0,0,0);
Redraw_Scene;
repeat
Update;
until false;
Stop_Graphics;
end.