Daily stuff not frequently posted a software developer finds out or rants about.

Thursday, May 31, 2007

3D Navigation in Pascal

There's a 3D navigation device out there that helps navigating Google Sketchup (or Google Earth if you just want to us it for fun) by getting rid of the need to constantly switch between navigation tools to get to the view you want. This device is called SpaceNavigator, from 3DConnexion. The downside of this device is that it can only be used with applications that do support it. There is a special driver from a committed SpaceNavigator fan available on their support forums, but this driver works only on 32-bit Windows, emulating a mouse, keyboard or joystick.

Using a 64-bit Windows, I could not use that driver, but wanted mouse emulation at least myself. Looking at the installed files, I noticed a type library that seemed to be part of the interface, so I hacked together a small unit making use of this library: pk3DConnexion.pas, which also needs the typelib unit TDxInput_TLB.pas. Using these two units, you can easily add SpacePilot support (or that for any other 3DConnexion device probably) to your Delphi application, just create a T3dConnexionDevice object, check if Loaded is true, set the event handlers for OnRotation, OnTranslation and OnKeyChange/OnKeyUp/OnKeyDown, and poll your required information with PollRotation, PollTranslation, PollKeys or Poll (polls them all). The property MouseEmulation conversts, as the name says, the device to a system-wide mouse, including left and right button and the scrollwheel (support for horizontal scrollwheel under Vista pending).

Left to implement might be to detect newly connected devices while the application is running, for example, but hey, this is just some quick demonstration code.

4 Comments:

Blogger ol said...

Thanks you for your unit. It's pritty nice and helpful. Although the period variable indicates a interval of 16 ms while polling., it takes unfortunately on average 50-100 ms before getting a sample with new (i.e. different) data. Does somebody have idea, why the actual sampling rate so bad? I definitively need a much high rate, because I intend to use the device for time cortical measurements.


Oliver

17:31

 
Blogger CCRDude said...

Well, my unit did only implement polling; if you take a look at TDxInput_TLB.pas, you'll find the OnSensorInput, OnKeyUp, OnKeyDown events.
Might be worth trying out whether reaction to those events instead of polling is faster. Maybe take a look into the official API documentation if this topic is mentioned there (I did write it based only on the typelib, so I can't say).

Also, if you do not need all information (e.g. no keys, no translation. etc.), don't use Poll, but PullTranslation, PullRotation or PullKeys only.

17:41

 
Blogger HPW said...

Hello ccrdude,

seems to be an interesting idea to be able to use it in our delphi app's.

>Using these two units, you can easily add SpacePilot support ...

Can you provide a small delphi projekt to show the ease of use?

Hans-Peter
D5/D7

08:35

 
Blogger Jimmy said...

Downloaded and installed the program on Vista X64. Works great for what I was looking for. I can scroll up and down webpages using the device. Thanks for your time-

06:11

 

Post a Comment

<< Home