Developing Games with GAIM

From EQUIS Lab Wiki

Jump to: navigation, search

The General Active Input Model (GAIM) framework provides utilities for developers of active/exercise games. This page is provided as a resource for game developers intent on using GAIM in their project(s). There are 4 simple steps to using GAIM input in your game:

Contents

Creating and managing the configuration text file

In the [Debug/Release]/bin folder of your game's executable, create a text file called 'config.txt'. The device manager requires that the config file listing connected devices be formatted as follows (* indicates optional item):

[type] [name] [port]*

Examples of this include:

BikePower PCGamerBike
BikePower TunturiBike COM1
TargetHRPower HRMI COM3
WiiStance WiiStance

The type of device refers to the abstract device level of the GAIM framework. In some cases, the name of the device and the device type are synonymous (for example WiiStance is the only WiiStance device).

Currently supported device types and names:

IPower:

BikePower [PCGamerBike | TunturiBike]
TargetHRPower [TunturiBike | HRMI]

IPoint:

WiimotePoint WiimotePoint

IStance:

WiiStance WiiStance

IGesture:

WiiGesture WiiGesture

Eventually more device types and names will be added, such as:

IPoint:

CameraPoint ['CameraType1' | 'CameraType2' | ... ]

IStance:

CameraStance ['CameraType1' | 'CameraType2' | ... ]
PadStance ['PadType1' | 'PadType2' | ... ]
AccelerometerStance ['AccelerometerType1' | 'AccelerometerType2' | ... ]
MatStance ['MatType1' | 'MatType2' | ... ]

IGesture:

CameraGesture ['CameraType1' | 'CameraType2' | ... ]

ITap:

PadTap ['PadType1' | 'PadType2' | ... ]
CameraTap ['CameraType1' | 'CameraType2' | ... ]
MatTap ['MatType1' | 'MatType2' | ... ]

IContControl:

CameraContControl ['CameraType1' | 'CameraType2' | ... ]

Adding the required library to your project

  • In your Visual C# XNA Studio project, add GAIM's ActiveGameEquipment project as a reference;
  • In files that either initialize any GAIM input or use GAIM input, include the following using directives depending upon your needs:
using ActiveGameEquipment;
using ActiveGameEquipment.Point;
using ActiveGameEquipment.Power;
using ActiveGameEquipment.Stance;
using ActiveGameEquipment.Gesture;
using ActiveGameEquipment.Tap;
using ActiveGameEquipment.ContControl;

Using GAIM's device manager to initialize input devices

EXAMPLE 1: The following is a simple example of how a racing game initializes IPower input using GAIM's DeviceManager - from within the game's main game manager:

// find and instantiate a compatible IPower
DeviceManager.generateList();
IPower iPow = DeviceManager.getIPower();

Occasionally, several abstract input devices within GAIM have static methods which you may access here as well;

// initialize static properties in TargetHRPower
TargetHRPower.Age = 23;
TargetHRPower.MaxSpeed = CarPhysics.MaxPossibleSpeed;
TargetHRPower.RestingHR = 60;

EXAMPLE 2: a game requiring an IGesture device (in the game's initialization:

DeviceManager.generateList();
// initialize static properties of WiiGesture
WiiGesture.ButtonTrigger = true;
IGesture wGesture = DeviceManager.getIGesture();
wGesture.GestureJobName = "tennisGestures"; // load particular gesture job
Thread gestureThread = new Thread(new ThreadStart(GatherGestureData));
gestureThread.Start();

Comment: If you have an handle exception on .cs file include in Gaim package, (Your device seems to be undetected, but it works with FitXF_Server.exe) you just have to copy FitXF.dll (in Gaim package) in bin/x86/debug directory. For a cleaner job, you can add FitXF.dll as a content of your project.

Using GAIM input in your game

From within your game code, accessing properties of GAIM input is as simple as knowing the properties of the input you are using.

EXAMPLE 1 (cont.): An example from our racing game to calculate speed:

speed = (float)RacingGameManager.IPow.Power;

EXAMPLE 2 (cont.): in the GatherGestureData method:

string currentGesture = wGesture.GestureName;
double currentConfidence = wGesture.Confidence;
DateTime currentGestureTime = wGesture.GestureTime;
string currentGestureJob = wGesture.GestureJobName;

Configuring an IGesture device

To make use of a Wiimote as an IGesture device with a previously trained set of gestures, GAIM uses WiiGLE; to use WiiGLE, the following steps must be taken:

  1. Contents of the WiiGLE runtime folder must be placed in the ../bin/Debug folder of your project's main executable;
    1. You may copy the contents of this folder from GAIM (and make use of GAIM's previously trained gesture job); Otherwise, download the WiiGLE runtime here;
    2. You may also create your own GestureJobs using the WiiGLEGUI; the simple process is outlined here; Upon creating your own GestureJobs, rename the GestureJob's filename in ../bin/Debug/GestureJobs to match the GestureJob they represent, and (optionally) move the file to ../bin/GestureJobStorage;
  2. Ensure ../bin/Debug/GestureJobs has at least one job (IGesture will load the first gesture in GestureJobs unless instructed otherwise;
  3. Alternatively, your desired GestureJob can be found in ../bin/GestureJobStorage;
  4. In your application's initialization code, specify the desired GestureJob (if applicable) (see example 2 above);

GAIM's WiiGLE GestureJobs

GAIM currently contains the following GestureJobs:

  • golfGestures
    • swing
    • chip
    • putt
  • greetingGestures
    • wave
    • handshake
  • householdGestures
    • stir
    • chop
    • saw
    • flip
    • hammer
  • swordGestures
    • stab
    • zorro
    • waxOn
    • waxOff
  • tennisGestures
    • forehand
    • backhand
    • spike

Available properties of GAIM input types

The following properties of GAIM input types are currently available through use of the framework:

IPower

// properties of IPower
double Power; // current power generated in watts
IBike
//properties of IBike
int DeviceStatus; // status of bike (1 if connected, 0 otherwise)
string DeviceType; // name of device
doublge Speed; // pedal speed in mph
double pedalCadence; // pedal cadence in rpm
double Power; // power generated in watts
double PedalDistance; // distance traveled
int pedalTension; // current tension
double HR; // user's current heart rate
double Power; // power/speed as a function of current HR, age, resting HR

The following static properties of TargetHRPower are especially useful for customizing input for racing games:

// static properties of TargetHRPower
static double MaxSpeed; // top speed allowed in the game
static int Age; // user's age in years
static double RestingHR; // user's resting HR in bpm
IHRMonitor
// properties of IHRMonitor 
double HR; // current HR (bpm)
// properties of the HRMI
double HR; // current HR (bpm)
static string PortName; // port to which the HRMI is connected

IPoint

// properties of IPoint
float XCoordinate; // x coordinate of on-screen position currently pointed to
float YCoordinate; // y coordinate of on-screen position currently pointed to

IStance

// properties of IStance
// the stance area may be a pressure sensitive mat, a wii balance board, or other device capable of determining stance in the user's area
float CenterGravityX; // user's center of gravity x position over stance area
float CenterGravityY; // user's center of gravity y position over stance area
float Weight; // total weight in lb in stance area
float BottomLeft; // weight in lb (bottom left quadrant or stance area)
float BottomRight; // weight in lb (bottom right quadrant or stance area)
float TopLeft;  // weight in lb (top left quadrant or stance area)
float TopRight; // weight in lb (top right quadrant or stance area)

IGesture

// properties of IStance
string GestureName; // the name of the most recently detected gesture
double Condifence; // the confidence of  the most recently detected gesture (probability of gesture occurring)
bool GestureIsNew; // flag used to indicate if a new gesture has been recorded since the last polling
DateTime GestureTime; // the time of detection for the last gesture detected
string GestureJobName; // the set of gestures currently being used in online classification
WiiGesture
// static properties of WiiGesture
bool ButtonTrigger; // toggle between time-trigger gesture and button-triggered gesture (true = button trigger on)