The standard way to do this — used by Oculus and Sony — is to put LEDs or some other set of markers on the headset, then track them with an external camera. This kind of positional tracking is ...
[WayneKeenan] wrote a proof-of-concept virtual reality system that used a Raspberry Pi and an Oculus Rift. It was about a thousand lines of Python and with a battery pack it was even portable.