Unity-TrackIR-Plugin
Unity-TrackIR-Plugin copied to clipboard
Plugin for Unity 3D for Natural Points TrackIR
This repository is obsolete!
As of February 2024, TrackIR now offers an official and first party SDK Unity plugin that works quite well. It's missing some small conviences and a simple way to do angle/position limits, but it's easy to add that in if you start from their base. Most importantly though, the official SDK doesn't require the kinda hacky DLL that this repository is built around.
This repository will be kept up for archival's sake, but I don't recommend using this repository's plugin. The original plugin is about a decade old as of this writing (February 2024), and was always technically in a weird legal gray area because this plugin being "okay" was based mostly on an official forum post like 10 years ago.
To get the official TrackIR Unity SDK, click this link! NaturalPoint also provides a nice Quick Start guide. The guide plus the new SDK makes adding the basic TrackIR support pretty trivial!
Unity TrackIR Plugin v1.3
As I started to integrate the old Track IR plugin code into a small test project, I ended up re-writing a lot how it interfaces with Unity. This new version includes a bunch of quality of fixes and re-organizes the code into something that more closely matches how Unity code is written today.
The original code is quite old and was built for Unity 2.6!
The TrackIR plugin was originally written by Tobias Boogh, and updated by Chris Reed with 64 bit binaries required for recent versions of Unity. All I've done is modernize it and make it easier to use.
This project was built in Unity 2017.4.37f1
Download
You can either clone the repository or download the asset package located in the root.
How it works
The TrackIRTransform
component takes raw input from TrackIR, and then modifies the assigned Tracked Object
to mirror those inputs in local space. All inputs are also offset from wherever the object already was in local space, so you can have an object at some position, E.g. (0, 1, 3) with a rotation of (30, 0, 0) and all movement/rotation will be done relative to those offsets.
The default values for the Position Multiplier
and Rotation Multiplier
are magic numbers that I've found to make the Unity results match 1:1 what the TrackIR application reports the results should be. I've left them configurable either way in case it they need to be adjusted.
Behind the scenes, these values are multipliers to the raw hardware values that TrackIR puts out.
Usage
Tracking will start automatically, but can be enabled or disabled at runtime using either the StartTracking()
and StopTracking()
functions, or by enabling/disabling the component itself. The latter should be negligibly more performant since it won't be running an Update()
loop that isn't doing anything while disabled, but the methods are otherwise identical.
I've also included a simple ResetTracking()
utility function because sometimes I forget to start up TrackIR and it's always annoyed me that most games need to be completely restarted for TIR to work in that situation.
This is typical hierarchy I would use for a tracked camera, with the TrackIRTransform
component on the "TrackIR" object, and the "Main Camera" set as the Tracked Object
. Depending on how you plan to use your cameras, you might be able get away with not having that root component, but the important thing to remember is that all rotation and movement is handled in local space. Without that root object, the camera rotation will work correctly only if local rotation is straight forward.
Optional clamps on position and rotation can be applied by checking the Use Limits
box.
Changelog
1.3 (Jan 23 2021)
- Protection against trying to create multiple TrackIR clients
- Protection against trying to run on machines without TrackIR installed
- More correct handling of rotations for cameras with nonzero start rotations
1.2 (Apr 6 2020)
- Moved the TrackIRTransform component into the same namespace as the TrackIR plugin code (TrackIRUnity)
1.1 (Apr 3 2020)
- Fixed crash when TrackIR is not detected at all
1.0 (Apr 2 2020)
- Released