Implementing TrackingTools in the Unreal Engine

Post Reply
BigBen528
Posts: 5
Joined: Mon Dec 06, 2010 9:26 am

Implementing TrackingTools in the Unreal Engine

Post by BigBen528 »

Lately my lab and I have been very interested in implementing TrackingTools motion tracking in multiple UDK projects.

I've started integrating it and up until now it has been relatively simple. Within UDK's unrealscript you utilize a DLLBind to bind the necessary functions from NPTrackingTools.dll to your class, and from there you can Initialize, Shutdown, etc.

I run into a problem however when it comes time to passing pointers. Unrealscript doesn't support char's for one, and a pointer to a char array, no. Specifically, when trying to load my ttp project the only datatype I can really pass is a string. When doing that however, the TrackingTools side only receives the first char of that string and tries to load project "p" instead of "project.ttp".

Code: Select all

TT_LoadProject(const char *filename)
I run into a similar problem with the float pointers required for TT_TrackableLocation.

I've tried a million different workarounds. I did manage to successfully do a LoadProject by actually renaming my "project.ttp" to "p" which seems to retrieve some information, although my TT_TrackableName retrieval seems weird. I'm still stumped on the float pointers though. Any suggestions?

I have a similar post going on the UDK forums: http://forums.epicgames.com/showthread.php?t=753267
beckdo
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: Implementing TrackingTools in the Unreal Engine

Post by beckdo »

I recently created a Unity3D plug-in that worked with the Tracking Tools. I'd be happy to share that code with you (email our support and ask for it). Instead of trying to load the Tracking Tools API into the process space and interface to it, it may be easier for you to simply create a DLL that works nicely with the Unreal Engine and then just stream data to that DLL from the Tracking Tools via VRPN. This way you optionally have access to the Tracking Tools user interface and you don't have to startup/shutdown the Tracking Tools with each run of your Unreal project.
BigBen528
Posts: 5
Joined: Mon Dec 06, 2010 9:26 am

Re: Implementing TrackingTools in the Unreal Engine

Post by BigBen528 »

That would be excellent! I'll do just that. Thanks!

There's a chance I may have got it to work as it is now, but I won't know for sure until further testing tomorrow. At any rate, I'd rather it not be as hacky as I currently have it.
BigBen528
Posts: 5
Joined: Mon Dec 06, 2010 9:26 am

Re: Implementing TrackingTools in the Unreal Engine

Post by BigBen528 »

Thanks Doug. Got it and it works just great!
I didn't see any Tracker Structs that gave yaw, pitch, and roll. Are those available via VRPN or should I do conversion from quaternions on my end?
beckdo
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: Implementing TrackingTools in the Unreal Engine

Post by beckdo »

Great, keep us posted on how things go and maybe send us a screenshot or video. It's nice to see what you guys come up with.

For Eulers, I would suggest using a conversion like this:

Code: Select all

void GetEulers(float qx, float qy, float qz, float qw, float *angle1,float *angle2, float *angle3)
{
    float &heading = *angle1;
    float &attitude = *angle2;
    float &bank = *angle3;

	double test = qx*qy + qz*qw;
	if (test > 0.499) { // singularity at north pole
		heading = (float) 2.0f * atan2(qx,qw);
		attitude = 3.14159265f/2.0f;
		bank = 0;

        RadiansToDegrees(heading);
        RadiansToDegrees(attitude);
        RadiansToDegrees(bank);
		return;
	}
	if (test < -0.499) { // singularity at south pole
		heading = (float) -2.0f * atan2(qx,qw);
		attitude = - 3.14159265f/2.0f;
		bank = 0;

        RadiansToDegrees(heading);
        RadiansToDegrees(attitude);
        RadiansToDegrees(bank);
		return;
	}
    double sqx = qx*qx;
    double sqy = qy*qy;
    double sqz = qz*qz;
    heading = (float) atan2((double)2.0*qy*qw-2.0*qx*qz , (double)1 - 2.0*sqy - 2.0*sqz);
	attitude = (float)asin(2.0*test);
	bank = (float) atan2((double)2.0*qx*qw-2.0*qy*qz , (double)1.0 - 2.0*sqx - 2.0*sqz);

    RadiansToDegrees(heading);
    RadiansToDegrees(attitude);
    RadiansToDegrees(bank);
}
BigBen528
Posts: 5
Joined: Mon Dec 06, 2010 9:26 am

Re: Implementing TrackingTools in the Unreal Engine

Post by BigBen528 »

Thanks I appreciate all the help. It's been great. Right now I'm setting the IP and a port number in an Unreal config file and passing it through to my dll, which returns position and euler rotation.

It works great for one tracking body at this point, but I am curious if you have implemented your VRPN code to use more than one tracking body.

I've tried a bunch of different things, but the returned data feed seems to only come from the last tracker remote I register.

Code: Select all

tracker1 = new vrpn_Tracker_Remote("body_1", connection);
tracker2 = new vrpn_Tracker_Remote("body_2", connection);
tracker1->register_change_handler(NULL, handle_pos, 0);
tracker2->register_change_handler(NULL, handle_pos, 1);
For 2 bodies I register 2 'trackers' and call mainloop() on them both every tick. the sensor ID I set doesn't seem to make its way to the handler either where I could use it.

Am I even going about this the right way? Thanks again.
beckdo
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: Implementing TrackingTools in the Unreal Engine

Post by beckdo »

in the register_change_handler method, the first parameter is user data, which can be anything. Since you just want to pass an 'ID', set the user data of the first one to 1 and the second to 2. I would drop that last parameter so you end up with something like:

Code: Select all

tracker1->register_change_handler(1, handle_pos);
tracker2->register_change_handler(2, handle_pos);
for example. Another thing you could do in the user data is pass back a pointer to your tracker object, like this:

Code: Select all

tracker1->register_change_handler(tracker1, handle_pos);
tracker2->register_change_handler(tracker2, handle_pos);
See how that works?
BigBen528
Posts: 5
Joined: Mon Dec 06, 2010 9:26 am

Re: Implementing TrackingTools in the Unreal Engine

Post by BigBen528 »

Thanks Doug! I have everything working now.
Post Reply