home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Virtual Reality Homebrewer's Handbook
/
vr.iso
/
vroom
/
joystick.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-03-19
|
4KB
|
132 lines
unit joystick;
interface
uses dos, vroom, fix_math;
procedure init_joystick;
procedure read_joystick_position(var ax, ay, bx, by : word);
procedure read_joystick_switch(var switch : byte);
function Joystick_Check : boolean;
implementation
var left, back, front, right, centrex, centrey : word;
procedure init_joystick;
var junk1, junk2 : word;
begin
writeln('Joystick Initialisation');
writeln;
writeln('Centre joystick and press Enter');
readln;
read_joystick_position(centrex, centrey, junk1, junk2);
writeln;
writeln('Pull joystick back and to the left and press Enter');
readln;
read_joystick_position(left, back, junk1, junk2);
writeln;
writeln('Push joystick forwards and to the right and press Enter');
readln;
read_joystick_position(right, front, junk1, junk2);
writeln;
writeln('Joystick initialisation complete');
left:=centrex-left; right:=right-centrex;
front:=centrey-front; back:=back-centrey;
end;
procedure read_joystick_position(var ax, ay, bx, by : word);
var r : registers;
begin
r.ah:=$84;
r.dx:=$01;
intr($15,r);
ax:=r.ax;
ay:=r.bx;
bx:=r.cx;
by:=r.dx;
end;
procedure read_joystick_switch(var switch : byte);
var r : registers;
begin
r.ah:=$84;
r.dx:=$00;
intr($15,r);
switch:=r.al;
end;
function Joystick_Check : boolean;
var correctkey : boolean;
ax, ay, junk1, junk2 : word;
jx, jy : integer;
switch : byte;
ca,sa,cc,sc : longint;
begin
correctkey:=false;
read_joystick_position(ax,ay,junk1,junk2);
read_joystick_switch(switch);
jy:=ay-centrey; jx:=ax-centrex;
if jy>(back/10) then
begin
correctkey:=true;
colatitude:=colatitude+jy/back;
end else
if jy<(-front/10) then
begin
correctkey:=true;
colatitude:=colatitude+jy/front;
end;
if jx<(-left/10) then
begin
correctkey:=true;
azimuth:=azimuth-jx/left;
end else
if jx>(right/10) then
begin
correctkey:=true;
azimuth:=azimuth-jx/right;
end;
if switch=224 then
begin
correctkey:=true;
CosSin(round(-colatitude*10),cc,sc);
CosSin(round(azimuth*10),ca,sa);
viewpoint.x:=viewpoint.x-(FixedMul(speed,FixedMul(cc,ca)));
viewpoint.y:=viewpoint.y-(FixedMul(speed,FixedMul(cc,sa)));
viewpoint.z:=viewpoint.z-(FixedMul(speed,sc));
x_pos:=viewpoint.x/65536;
y_pos:=viewpoint.y/65536;
z_pos:=viewpoint.z/65536;
end
else
if switch=208 then
begin
correctkey:=true;
CosSin(round(-colatitude*10),cc,sc);
CosSin(round(azimuth*10),ca,sa);
viewpoint.x:=viewpoint.x+(FixedMul(speed,FixedMul(cc,ca)));
viewpoint.y:=viewpoint.y+(FixedMul(speed,FixedMul(cc,sa)));
viewpoint.z:=viewpoint.z+(FixedMul(speed,sc));
x_pos:=viewpoint.x/65536;
y_pos:=viewpoint.y/65536;
z_pos:=viewpoint.z/65536;
end;
if correctkey then
begin
Set_World_to_View(viewpoint.x,viewpoint.y,viewpoint.z,azimuth,colatitude,0);
main_matrix:=w2v;
end;
Joystick_Check:=correctkey;
end;
end.