home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Virtual Reality Homebrewer's Handbook
/
vr.iso
/
vroom
/
headtrac.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-03-19
|
6KB
|
187 lines
unit headtracker;
interface
uses vroom,crt,fix_math;
procedure Initialise_Head_Tracker;
procedure Scale_Head_Tracker(scale_val : real);
procedure Read_Head_Tracker;
var
htz, hts : array[0..5] of real;
last_ht_angle : array[0..5] of integer;
l0, l1, l2, l3, l4, thx, thy, thz : longint;
l0a, l1a, l2a, l3a, l4a, thxa, thya, thza : longint;
implementation
procedure Initialise_Head_Tracker;
const adport=624;
delay_no=20;
var channel, junk : integer;
begin
htz[0]:=1800;
htz[1]:=2065 {2025};
htz[2]:=2010 {2080};
htz[3]:=1831 {1859};
htz[4]:=1950 {2160};
htz[5]:=1835 {1816};
hts[0]:=0.96;
hts[1]:=-0.96;
hts[2]:=-0.96;
hts[3]:=0.96;
hts[4]:=-0.96;
hts[5]:=-0.96;
l0a:=0;
l1a:=0;
l2a:=0;
l3a:=0;
l4a:=0;
thxa:=0;
thya:=0;
thza:=0;
for channel:=0 to 5 do
begin
port[adport+3]:=0;
port[adport]:=channel;
junk:=port[adport+4];
for junk:=1 to delay_no do;
junk:=port[adport+4];
for junk:=1 to delay_no do;
junk:=port[adport+4];
for junk:=1 to delay_no do;
junk:=port[adport+4];
for junk:=1 to delay_no do;
junk:=port[adport+4];
for junk:=1 to delay_no do;
junk:=port[adport+4];
for junk:=1 to delay_no do;
junk:=port[adport+4];
for junk:=1 to delay_no do;
junk:=port[adport+5];
for junk:=1 to delay_no do;
junk:=port[adport+5];
for junk:=1 to delay_no do;
junk:=port[adport+5];
for junk:=1 to delay_no do;
junk:=port[adport+5];
for junk:=1 to delay_no do;
junk:=port[adport+5];
for junk:=1 to delay_no do;
junk:=port[adport+5];
for junk:=1 to delay_no do;
junk:=port[adport+5];
for junk:=1 to delay_no do;
last_ht_angle[channel]:=(port[adport+2] and 15)*256+(port[adport+1]);
end;
end;
procedure Scale_Head_Tracker(scale_val : real);
var fixed_scale_val : longint;
begin
fixed_scale_val:=real_to_fixed(scale_val);
l0:=fixedmul(l0a,fixed_scale_val);
l1:=fixedmul(l1a,fixed_scale_val);
l2:=fixedmul(l2a,fixed_scale_val);
l3:=fixedmul(l3a,fixed_scale_val);
l4:=fixedmul(l4a,fixed_scale_val);
thx:=fixedmul(thxa,fixed_scale_val);
thy:=fixedmul(thya,fixed_scale_val);
thz:=fixedmul(thza,fixed_scale_val);
end;
procedure Read_Head_Tracker;
const adport=624;
delay_no=20;
var channel,junk : integer;
angle, anglead : array [0..5] of integer;
mat0, mat1, mat2, mat3, mat4, mat5, tempmat1, tempmat2, boom_tfm : fixed_matrix_4x4;
cth0, cth1, cth2, cth3, cth4, cth5 : longint;
sth0, sth1, sth2, sth3, sth4, sth5 : longint;
begin
for channel:=0 to 5 do
begin
port[adport+3]:=0;
port[adport]:=channel;
junk:=port[adport+4];
for junk:=1 to delay_no do;
junk:=port[adport+4];
for junk:=1 to delay_no do;
junk:=port[adport+4];
for junk:=1 to delay_no do;
junk:=port[adport+4];
for junk:=1 to delay_no do;
junk:=port[adport+4];
for junk:=1 to delay_no do;
junk:=port[adport+4];
for junk:=1 to delay_no do;
junk:=port[adport+4];
for junk:=1 to delay_no do;
junk:=port[adport+5];
for junk:=1 to delay_no do;
junk:=port[adport+5];
for junk:=1 to delay_no do;
junk:=port[adport+5];
for junk:=1 to delay_no do;
junk:=port[adport+5];
for junk:=1 to delay_no do;
junk:=port[adport+5];
for junk:=1 to delay_no do;
junk:=port[adport+5];
for junk:=1 to delay_no do;
junk:=port[adport+5];
for junk:=1 to delay_no do;
anglead[channel]:=(port[adport+2] and 15)*256+(port[adport+1]);
if abs(last_ht_angle[channel]-anglead[channel])>4 then last_ht_angle[channel]:=anglead[channel]
else anglead[channel]:=last_ht_angle[channel];
angle[channel]:=round((anglead[channel]-htz[channel])*hts[channel]);
end;
CosSin(angle[0],cth0,sth0);
CosSin(angle[1],cth1,sth1);
CosSin(angle[2],cth2,sth2);
CosSin(angle[3],cth3,sth3);
CosSin(angle[4],cth4,sth4);
CosSin(angle[5],cth5,sth5);
mat0.data( cth0, sth0, 0, 0,
-sth0, cth0, 0, 0,
0, 0, 65536, 0,
l0, 0, 0, 65536);
mat1.data(cth1, 0, -sth1, 0,
0, 65536, 0, 0,
sth1, 0, cth1, 0,
l1, 0, 0, 65536);
mat2.data(cth2, 0, -sth2, 0,
0, 65536, 0, 0,
sth2, 0, cth2, 0,
l2, 0, 0, 65536);
mat3.data(cth3, 0, -sth3, 0,
0, 65536, 0, 0,
sth3, 0, cth3, 0,
0, 0, l3, 65536);
mat4.data(65536, 0, 0, 0,
0, cth4, sth4, 0,
0, -sth4, cth4, 0,
0, 0, l4, 65536);
mat5.data( cth5, sth5, 0, 0,
-sth5, cth5, 0, 0,
0, 0, 65536, 0,
thx, thy, thz, 65536);
multiply_4x4(mat0, mat1, tempmat1);
multiply_4x4(tempmat1, mat2, tempmat2);
multiply_4x4(tempmat2, mat3, tempmat1);
multiply_4x4(tempmat1, mat4, tempmat2);
multiply_4x4(tempmat2, mat5, boom_tfm);
multiply_4x4(w2v,boom_tfm,main_matrix);
redraw_all:=true;
end;
end.