Tuesday, 13 October 2009

TrackIR

Today I ported Ronald Erickson's DBPro wrapper for the TrackIR head tracking device to BliztMax. It's Win32 only as the TrackIR only works on that platform. I'll refine this code into a module later and have it pull out values between -1.0 and 1.0 instead of -16384 and 16384. This will bring it into line with other controller axis outputs.




Import pub.win32


?Win32


Global lib%  = LoadLibraryA("TrackIRWrap.dll")
Global TIR_Update()"Win32" =  GetProcAddress(lib,"?TrackIR_Update@@YAXXZ")
Global TIR_Init%(GameID:Int)"Win32" = GetProcAddress(lib, "?TrackIR_Init@@YAHG@Z")
Global TIR_Pitch%()"Win32" = GetProcAddress(lib, "?TrackIR_GetPitch@@YAKXZ")
Global TIR_Roll%()"Win32" = GetProcAddress(lib, "?TrackIR_GetRoll@@YAKXZ")
Global TIR_Yaw%()"Win32" = GetProcAddress(lib, "?TrackIR_GetYaw@@YAKXZ")
Global TIR_GetVecX%()"Win32" = GetProcAddress(lib, "?TrackIR_GetVecX@@YAKXZ")
Global TIR_GetVecY%()"Win32" = GetProcAddress(lib, "?TrackIR_GetVecY@@YAKXZ")
Global TIR_GetVecZ%()"Win32" = GetProcAddress(lib, "?TrackIR_GetVecZ@@YAKXZ")
Global TIR_GetFrame%()"Win32" = GetProcAddress(lib, "?TrackIR_GetFrameSig@@YAKXZ")


Global TIR_Connected:Int = -1




Graphics 640,480
Delay(500)
Local GameID% = 14901


TIR_Connected = -1


Global pitch,roll,yaw:Int
Global VecX, VecY, VecZ:Int
Global frame:Int


While Not KeyHit( KEY_ESCAPE )


Cls
If TIR_Connected <> 0
TIR_Connected = TIR_Init(GameID)
Else
TIR_Update()
pitch = TIR_Pitch()
roll = TIR_Roll()
yaw = TIR_Yaw()
VecX = TIR_GetVecX()
VecY = TIR_GetVecY()
VecZ = TIR_GetVecZ()
frame = TIR_GetFrame()
End If


DrawText TIR_Connected,20,20
DrawText "Pitch: " + String(pitch),20,40
DrawText "Roll: " + String(roll),20,60
DrawText "Yaw: " + String(yaw),20,80
DrawText "VecX: " + String(VecX),20,100
DrawText "VecY: " + String(VecY),20,120
DrawText "VecZ: " + String(VecZ),20,140
DrawText "Frame: " + String(frame),20,160


Flip
Wend


?

Now that's a result.

No comments:

Post a Comment