Research
Almaden Research Center 
  SDL Modifications for Accelerometer Game Control

My Main Page

ThinkPad Active Protection System for Linux

be careful with sendmsg() family

Publications

Personal

 
SDL Accel: SDL Modifications for Accelerometer Game Control

One of the benefits of working in IBM Almaden Research Center CS is the freedom we are given to pursue our technical interests even when they don't immediately align with our current research. This page is the result of one such digression.

Since the release of the ThinkPad Accelerometer Interface in mid-2005, I have received a good deal of correspondence regarding the changes I described to the Simple Directmedia Layer (SDL) library. Small modifications to SDL can enable any game which uses the multimedia libary to use the acceleromter as input for games.

Although the accelerometer can be used to trigger any of the input types to a game, directional input is the most obviously applicable. Of course, games which rely on directional input as their primary interface are optimal candidates for this feature. Consider Tux Racer and Neverball.

Screenshots from Tux Racer and Neverball

Download

This feature as implemented will only work with ThinkPads with accelerometers running either Windows or Linux. To install:

Windows
The Windows version interfaces directly with sensor.dll, by calling an undocumented function: ShockproofGetAccelerometerData(). sensor.dll is included as part of the Active Protection System, and should come preinstalled with supported ThinkPads. However, if you need to install the APS, you can find it here.
  1. Download and install any game which uses SDL. A list of such games is maintained on the libsdl website. Tux Racer and Neverball are good candidates. Note: The precompiled Windows version of Neverball requires - but does note come with - msvcrt71.dll. A quick web search for "msvcrt71.dll" should set you on the right path.
  2. Download this Modified SDL Library zip. This library and accompanying patch is distributed under terms of the LGPL. Please note that the patch is not intended to be a final version - however, it is complete enough for purposes of this demonstration.
  3. Find where the game placed its SDL.dll, and replace it with the one in the Modified SDL Library zip.
  4. Start the game.

Linux
You'll need to build your own SDL library using this provided patch and Makefile. Please note that when these changes were made, the linux accelerometer driver was not yet available, so this code interfaces directly with the accelerometer. The patch should be updated to rely on the proper driver, which is included in the Linux kernel starting with 2.6.14. As written, this may interact or interfere with the aforementioned driver, but is useful as a demonstration.
  1. Download this patch and follow the instructions in the Makefile to compile and install this modified version of SDL.

Mac OS X
Similar changes can be made to SDL for the accelerometers in Macintoshes. However, the interface to the accelerometer in such machines is not public. Amit Singh, of kernelthread.com will be releasing his source for The Apple Motion Sensor As a Human Interface Device with his book, Mac OS X Internals. That code should be easily adaptable for SDL. It is also interesting to note that the Macintoshes' accelerometers measure and expose X, Y, and Z (or vertical) acceleration components, making "jump when I jump" style game-play possible.

Configuration

One may notice that on Windows, some games may "freeze" momentarily during play. In many cases, games will need to load parts of level maps as one moves through a level. If the Active Protection System is detecting motion, however, it will "stop" the hard drive, causing the load of that map piece to be delayed, causing the hiccup. The APS must be enabled because, as previously mentioned, the modifications to SDL rely on the APS's sensor.dll for its accelerometer readings. Fortunately, the APS is very configurable; the "Shock detection sensitivity" can be set to low, and even suspended for some minutes. To reach the configuration menu, look in the Notification Area of the Windows Taskbar for the APS icon: . Follow the prompts in the configuration menu to suit your needs.

Note: Some ThinkPads have "reversed" accelerometer X and Y readings. This may cause left-right motion to control the forward-back inputs on games, and vice versa.

Technical

Small changes to SDL_PollEvent() in src/events/SDL_events.c make all games which use SDL "accelerometer ready." This is achieved primarily by adding calls to SDL_PrivateKeyboard() based on accelerometer readings. We find initial "rest" values, establish a "range" for the X and Y values, and then call SDL_PrivateKeyboard() with SDL_PRESSED if the current reading is more than the "rest" value plus the range, or we call SDL_PrivateKeyboard() with SDL_RELEASED if not.

Acknowledgements

This work was first pursued by Ted Bonkenburg while he was working at the IBM Almaden Research Center. Amit Singh has done similar work with his investigation of The Apple Motion Sensor As a Human Interface Device, the source for which is provided with his tome, Mac OS X Internals, available as ISBN 0321278542.


  Privacy | Terms of Use | IBM Home | Almaden Home | Almaden CS Home | Research Sites | Page Contact