TweetFollow Us on Twitter

Cubby VR Part II

Volume Number: 16 (2000)
Issue Number: 11
Column Tag: QuickDraw 3D Tricks

Cubby: Multiscreen Desktop VR Part II

by By Maarten Gribnau and Tom Djajadiningrat

How to create an Input Sprocket driver for a 3D input device

Summary

In this second part of our 'Cubby: Multiscreen Desktop VR' trilogy, we will introduce you to the art of creating a driver to read an Origin Instruments Dynasight input device. With the Dynasight, the position of the head of the user is established so that Cubby can display the correct images on its screens. The driver is created with InputSprocket, which is part of Apple's Game Sprockets API.

Introduction

In our previous articles about Desktop VR (Djajadiningrat & Gribnau, 1998; Gribnau & Djajadiningrat, 1998), we used the Pointing Device Manager (PDM) of QuickDraw 3D to serve our input needs. We promoted the PDM because it was intended to support 3D input devices. The PDM and InputSprocket have in common that they both separate the device dependent code from the application. They relieve application programmers from dealing with devices directly and provide an abstraction layer for input programming. The difference between the two is that InputSprocket is actually supported by device manufacturers. There are no QuickDraw 3D drivers available to our knowledge. For InputSprocket on the other hand, lots of drivers are available. In addition, InputSprocket has configuration management built in. A standard interface is provided for connecting devices to applications. For these reasons InputSprocket provides a better solution for Cubby's input needs than the PDM.

In this episode we cover programming with InputSprocket to create a device driver. In the next episode the application side will be covered. Together, the two articles cover the whole of InputSprocket. The driver we describe is for the Dynasight device. If you do not own one or plan to buy one, you might still be interested because the techniques explained here can be used for other input devices as well. Documentation on writing InputSprocket drivers is scarce, so you might pick up some facts here. To compile our code, you will probably need to download the latest version of InputSprocket from the Apple web site (see References section), which is currently version 1.7.3.

If you are familiar with programming drivers for InputSprocket, you can safely skip the next section and proceed with the following section about creating an InputSprocket driver for the Dynasight. If InputSprocket drivers are new to you, you can read the next section and be introduced to the basic concepts. If you have worked with InputSprocket before but not with drivers, you can also read the next section to learn how drivers and applications communicate.

Introduction to InputSprocket

The goal of InputSprocket is to make life easier for game programmers who deal with input devices. There are an immense number of devices on the market with different features. Trying to have a game support all these devices optimally can lead to severe headaches. Most games support input devices through emulation of the keyboard and mouse. But emulation does not suffice when supporting complex devices that have directional pads, levers, wheels, etc. For one, the game cannot take advantage of the extra input controls of complex devices and secondly, configuring the devices and connecting them to game controls is device specific. That means that game programmers should provide configuration capabilities for each device that they need to support.

This is where InputSprocket comes in. It solves these problems through an input device architecture that allows games developers to create games that can use a wide variety of input devices. Input device developers can use InputSprocket to build device drivers that provide a description of input device controls that the game can use to automatically configure its control options. The device driver can also provide a user interface that allows the user to change default control options. Therefore, game programming is made easier because a lot of device dependent code is moved from the application to the device driver.

The communication between InputSprocket drivers and games is based on elements. The element is a building block used to describe the capabilities of a device. Each control of a device is described with an element, so every device can be described with a set of elements. For example, a one-button mouse can be described with an element for the x-axis, an element for the y-axis and a button element. More complex devices may require more elements but are handled in the same way. An element is described by the following three pieces of data.

A human readable identifier is a string that the game can display to identify the element for the user during configuration. Examples of such identifiers are "trigger", "roll" or "move forward".

The element kind is a four-character sequence that indicates the type of data the element produces. For example, button elements will typically produce two-state values while axis elements produce continuous data. InputSprocket currently provides five basic element kinds:

  • Button elements produce two-state data.
  • Directional pad elements are nine state elements with an idle position and eight states corresponding to the eight directions on a typical directional game pad.
  • Axis elements produce continuous data, either with or without a meaningful center. A symmetrical axis has a meaningful center, like the axis of a joystick. Axis elements such as a gas pedal or a brake do not have a meaningful center.
  • Delta elements are like axis elements but instead of an absolute position or orientation, they produce Delta data, which indicates the distance moved relative to the previous position (e.g. mouse axes).
  • Movement elements produce movement data that is given both as x-y axis data and directional pad data, allowing the game to use whichever is suitable. Note that in general you should use axis data instead.

There is a sixth element kind, the virtual element, which we will encounter later.

The label of an element gives the suggested use for an element. For example, a button element may be intended as the start button or the firing button. During configuration, a game uses labels to find the elements it requires for play.

As was mentioned, elements are the way applications communicate with drivers. There are two interfaces to pass data from drivers to applications using elements: the low-level and the high-level interface. In principle, driver programmers can decide which interface to implement. It is tempting to implement the low-level interface only, since it is the easiest to implement. However, drivers should provide both the low and the high-level interface, so that game application programmers can decide which interface they want to use.

Low-level Interface

The low-level interface is the simplest to implement when building drivers. Figure 1 shows a diagram of both the low and the high-level interfaces. The lower parts of the Dynasight Driver and the InputSprocket Extension represent the low-level interface. Cubby uses only the high-level interface and therefore connects the cameras to the high-level axis elements (Head X, Head Y and Head Z) exclusively. When the driver is loaded, it creates elements for every control it has. The driver is responsible for reading the data from the device and, as soon as it is loaded, should update its elements every time the device reports new data. Applications can connect via InputSprocket directly to the elements of the device and update the game state accordingly.


Figure 1. Diagram of the low- and high-level interfaces.

High-level Interface

In Figure 1, the upper parts of the Dynasight Driver and the InputSprocket Extension represent the high-level interface. The high-level interface is somewhat more complicated than the low-level interface but it has all the advantages that InputSprocket was meant to offer. Instead of connecting to the device's elements directly, games read data from the devices through virtual elements. These virtual elements are created by InputSprocket from the needs that the game has. Drivers are responsible for the mapping of needs to virtual elements. The high-level interface is only valid between the driver's Init and Stop callbacks that InputSprocket calls. Only the driver knows exactly how it has been configured, and when it is active, it is responsible for pushing data to those virtual elements for each need for which it is configured.

Configuration

The majority of driver callbacks are related to the Configure dialog. These function calls will only happen while the high-level is valid (i.e. ISpInit has been called without a subsequent ISpStop). When the application calls ISpConfigure, a dialog is presented with a scrolling list of devices with one device selected. Figure 3 shows this dialog with our Dynasight device selected. The popup menus show the current connection of the Dynasight x- y- and z-axis to a game's roll, pitch and yaw controls. The selected device is responsible for the primary pane of the dialog, handling all events and drawing related to that area. The GetSize function is called to determine the preferred and minimum sizes of the pane area used by the device. If the pane area will not fit on any available display device, then that device is removed from the high-level list. The BeginConfiguration function is then called for each device. The configure dialog is resized and shown. The GetIcon function is called for each device to determine the icon to be shown in the scrolling list. Then the Show function is called for the selected device. This is the time to call AppendDITL for the resources to be displayed in the primary pane. All events returned in the dialog filter are passed to the HandleEvent function to give the device a chance to handle them. If update events are not handled (the recommended option to avoid extra flicker), InputSprocket will make the device Draw function call from within a BeginUpdate/EndUpdate pair. Unhandled mouse clicks will be passed to the Click function. If the device called AppendDITL to add items to the dialog and those items are returned by InputSprocket's ModalDialog call, then it will call the DialogItemHit function.

The device should maintain a 'dirty' variable that is set whenever any configuration information is changed, and returned and cleared when the Dirty call is made. When a different device is selected in the list, the old device receives a Hide function call and the new device a Show function call. When the dialog is closed, every device receives an EndConfiguration call.


Figure 2. InputSprockets's configuration dialog box with the Dynasight device selected.

Procedure

Figure 3 illustrates the sequence of events when a game is using InputSprocket. The initiating calls are shown on the left and the driver's responses are found on the right. There are four major activities. Low-level initialization is entered when an application calls ISpStartUp. InputSprocket will then load the driver and call its major entry point. In response, the driver should look for devices present on the system and create InputSprocket devices for each active device. If a device was created, InputSprocket will call the driver's Meta handler to find out where the driver's entry points are. If no InputSprocket device was created, the driver is unloaded. High-level initialization is entered when the application calls ISpInit. InputSprocket passes the needs and virtual elements to the driver. In response, the driver stores them and does an auto-configuration. This means that the driver will try to find an optimal match between the needs of the application and the elements the device has. When the high-level interface is valid, the application can call ISpConfigure. This starts the configuration activities explained in the previous section.

There are several guidelines that should be followed during auto-configuration. If a previous device fulfilled a need and the kISpNeedFlag_NoMultiConfig bit is set in the need structure for that need, the device should not attempt to auto-configure to the need. The driver should indicate that it is fulfilling a need so that devices queried later know that the need is taken. More guidelines can be found in Apple's documentation of InputSprocket (see References section). After auto-configuring, the device should immediately push initial values to the corresponding virtual elements and from that point push data to those virtual elements whenever data is pushed to the elements to which they are configured.

When the application calls ISpStop, the validity of the high-level interface ends. The drivers should stop pushing data to the virtual elements and dispose the needs and the virtual elements. Calling ISpShutdown within the application causes InputSprocket to call the driver's termination routine. In response, the driver should stop pushing low-level data and dispose the InputSprocket device.


Figure 3. The sequence of events in communication between driver and game.

Creating an InputSprocket Driver for the Dynasight

Now that we have a basic understanding of how InputSprocket works, we will dive into the coding of a driver and illustrate how we can put this knowledge to use. We take the Dynasight device as example and start with the real driver functionality: the initialization and transfer of data. The configuration of the driver will be covered in the next section. The Dynasight device is an infrared tracking device that is used in Cubby to track the head position of users. The 3D position data is made available on the serial port. In the following discussion, we will not go into the details of reading the position data from the serial port. If you are interested in that part of the driver, you can read our previous article about Desktop VR (Gribnau & Djajadiningrat, 1998) and/or you can have a look at the code accompanying this article.

Before we begin, we should make some general remarks about developing InputSprocket drivers. An InputSprocket driver is a shared library with a specific file type and creator ('shlb' and 'insp'). All drivers must be located in the same folder as the InputSprocket extension, which must be the Extensions folder. Being a shared library, it takes some extra effort to debug a driver. First of all, you should set the output directory of your development environment to the Extensions folder of the System folder on your startup disk, so that the compiled driver ends up there. Secondly, you should set a host application that is used to run the driver.

The Dynasight driver handles the six major tasks that all drivers should handle: shared library initialization, shared library termination, pushing data, 'high-level' Init, 'high-level' Stop, and the configure dialog user interface. The code for shared library initialization is shown in Listing 1. This routine is called when InputSprocket loads the driver. The important parts are that the driver checks whether a certain version of InputSprocket is available. If version 1.2 or greater is not available, the driver returns without creating any InputSprocket devices. In that case, InputSprocket unloads the driver. The other important point in this listing is that the driver retrieves the file specification of the shared library. The file specification is used in the driver initialization routine to locate the resource file.

Listing 1: ISpDriverDynasightMain.cp

__myintialize
OSErr __myinitialize(CFragInitBlockPtr ibp)
{
   OSErr   err = noErr;
   FSSpec fileSpec = {0,0,0};
   NumVersion version;
   UInt32 inputSprocketVersion;
   
#if __MWERKS__
   err = __initialize(ibp);
   if (err != noErr) {
      return err;
   }
#endif
   
   // Require InputSprocket 1.2.0
   version = ISpGetVersion();
   inputSprocketVersion = * (UInt32 *) &(version);   
   if (inputSprocketVersion < 0x01200000) {
      return err;
   }
   
   // Grab the file spec
   if (ibp->fragLocator.where == kDataForkCFragLocator) {
      // The shared library should always be located in the data fork
      fileSpec = *ibp->fragLocator.u.onDisk.fileSpec;
   }
   
   // Create IS device for each Dynasight device found on the system
   // If we don't create an IS device, IS will unload us
   DynasightInit(fileSpec);
   return err;   
}


In Listing 2, it is shown what happens inside the initialization routine. The routine looks at all available serial ports for a Dynasight. If one is found, the driver's resource file is opened and a structure in a global array (fDynas) is filled with all the information for the device on the current port. After setting some default values in the structure, the InputSprocket device is actually created (by calling CreateDevice) and the Dynasight is put into action. Finally, after all ports have been checked, the resource file of the driver is closed.

Listing 2: ISpDriverDynasight.cp

DynasightInit
OSErr DynasightInit(FSSpec fileSpec)
{
   OSErr err;
   short resourceRef = -1;                  // ref to our resource file
   Boolean resourceFileOpen = false;   // true if our resource file is open
   SerialPort port;
   UInt16 portID, numPortIDs;
   Boolean   portWithDynasight;
   
   fNumDynas = 0;
   numPortIDs = port.GetNumSerialPorts();
   for (portID = 0; portID < numPortIDs; portID++) {
      {
         Dynasight dynasight;
         portWithDynasight = 
            dynasight.GetDynasightFoundOnPort(portID);
      }
      if (portWithDynasight) {
         // Open the resource file and check for errors
         if (!resourceFileOpen) { 
            resourceRef   = FSpOpenResFile(&fileSpec, fsRdPerm);
            err = ResError();
            if (err != noErr) {
               return err;
            }
            resourceFileOpen = true;
         }
         fDynas[fNumDynas].dynasight = new Dynasight (portID);
         fDynas[fNumDynas].fileSpec = fileSpec;
         fDynas[fNumDynas].oldLLState.xAxis = kISpAxisMiddle;
         fDynas[fNumDynas].oldLLState.yAxis = kISpAxisMiddle;
         fDynas[fNumDynas].oldLLState.zAxis = kISpAxisMiddle;
         LowToHighLevelState(&fDynas[fNumDynas].oldLLState,
            &fDynas[fNumDynas].oldHLState);
         fDynas[fNumDynas].axisIndexToNeeds[kAxisIndex_XAxis]=
            kUnsetIndex;
         fDynas[fNumDynas].axisIndexToNeeds[kAxisIndex_YAxis]=
            kUnsetIndex;
         fDynas[fNumDynas].axisIndexToNeeds[kAxisIndex_ZAxis]=
            kUnsetIndex;
         fDynas[fNumDynas].virtualElementsValid = false;
         fDynas[fNumDynas].active = false;
         // Create the device and store its reference
         CreateDevice(&fDynas[fNumDynas]);
         fDynas[fNumDynas].active = true;
         fDynas[fNumDynas].dynasight->StartRunning(
            MyDynasightCompletionProc, &fDynas[fNumDynas]);
         fNumDynas++;
      }
   }
   // Close the resource file
   if (resourceFileOpen) {
      CloseResFile(resourceRef);
   }
   return err;
}


The CreateDevice routine actually creates the device and elements for the low-level interface. The driver provides three axis elements, corresponding to the x-, y- and z-axis of the Dynasight device. In our driver we chose to set up the device using a resource (of type 'isdv'), as shown in Listing 3. This resource contains all the information of an ISpDeviceDefinition structure that is passed to the InputSprocket. Listing 4 shows the creation of an axis element. Again, we chose to set up the axis elements from a resource (of type 'isel') that contains the information in an ISpElementDefinitionStruct structure which is needed to set up an element. After retrieving the element resource, yet another resource is retrieved. This is the element configuration resource (of type 'isei') that is used to configure the element. This part is optional. If the resource is not available or invalid, the element is still created in the subsequent ISpElement_New call.

Listing 3: ISpDriverDynasight.cp

CreateDeviceFromResource
OSErr CreateDeviceFromResource(
   short resId, 
   UInt32 refCon,
   ISpDeviceReference *device)
{
   Handle h;
   OSErr err;
   ISpDeviceDefinition def;
   
   // Read the device resource from the res file
   h = Get1Resource('isdv', resId);
   err = ResError();
   if (err != noErr) { return err; }
   if (h == nil) { err = -1; }
   if (err != noErr) { return err; }
   // Copy the handle to a structure and release the handle   
   BlockMoveData(*h, &def, sizeof(def));
   ReleaseResource(h);
   // Create the InputSprocket device
   err = ISpDevice_New(&def, (ISpDriverFunctionPtr_MetaHandler) DeviceMetaHandler, refCon, device);
   
   return err;
}


Listing 4: ISpDriverDynasight.cp

CreateElementFromResource
OSErr CreateElementFromResource(
   short elementResId,
   short configResID,
   ISpDeviceReference device,
   ISpElementReference *element)
{
   Handle h1;                  // handle to resource based element definition structure
   Handle h2;                  // handle to resource based element configuration info
   OSErr err;      
   ISpElementDefinitionStruct def;   // actual element definition structure
   
   // Read the element definition struct from a resource
   h1 = Get1Resource('isel', elementResId);
   err = ResError();
   if (err != noErr) { return err; }
   if (h1 == nil) { err = -1; }
   if (err != noErr) { return err; }
   
   // Copy the handle to a structure
   BlockMoveData(*h1, &def, sizeof(def));
   
   // Read the configuration information from a resource (this may fail)
   h2 = Get1Resource('isei', configResID);
   err = ResError();
   if (h2 && (err == noErr)) {
      HLock(h2);
      def.configInfo = *h2;
      def.configInfoLength = GetHandleSize(h2);
   }
   // Create the InputSprocket element
   def.device = device;
   err = ISpElement_New(&def, element);
   // Release resources
   HUnlock(h2);
   ReleaseResource(h1);
   ReleaseResource(h2);
   
   return err;
}



When creating the device in Listing 2, a pointer to DeviceMetaHandler was passed to the ISpDevice_New routine. This routine is called by InputSprocket to retrieve pointers to all the callbacks in our driver. It is called after the initialization of the driver. Listing 5 shows a part of the DeviceMetaHandler. InputSprocket calls the routine with a selector. The routine selects the appropriate callback and returns it. This example returns only the pointers to our Init and Stop callbacks. In our driver, the Meta handler returns pointers dealing with the configuration as well. These will be listed in the next section.

Listing 5: Example of a device Meta handler

DeviceMetaHandler
ISpDriverFunctionPtr_Generic DeviceMetaHandler(
   UInt32 refCon,
   ISpMetaHandlerSelector selector)
{
   ISpDriverFunctionPtr_Generic function = NULL;
   ISpDriverFunctionPtr_Init funcInit;
   ISpDriverFunctionPtr_Stop funcStop;
   
   switch(selector) {
      case kISpSelector_Init:
         funcInit = (ISpDriverFunctionPtr_Init) Init;
         function = (ISpDriverFunctionPtr_Generic) funcInit;
         break;
      
      case kISpSelector_Stop:
         funcStop = (ISpDriverFunctionPtr_Stop) Stop;
         function = (ISpDriverFunctionPtr_Generic) funcStop;
         break;
   }
   return function;
}

The beating hart of the driver is listed in Listing 6. This is the routine that is called whenever there is new data available from the Dynasight. We passed a pointer to this routine when we started the Dynasight in Listing 2. In the routine, it is first checked whether the low-level interface is active and whether the Dynasight is producing reliable data. Then, the position read from the Dynasight is scaled between 0 and 1 and subsequently scaled between InputSprocket axis values kISpAxisMinimum and kISpAxisMaximum. This is a requirement of InputSprocket. The convention is to scale coordinates of devices between those boundaries. For instance, with a joystick, kISpAxisMinimum should be sent when the joystick is fully rotated to one end and kISpAxisMaximum when it is fully rotated the other way.

The scaled coordinates are pushed to the low-level elements with the three ISpElement_PushSimpleData calls but only when a coordinate has changed. Then, the low-level data is converted to high-level data (in our case copied) and send to the virtual elements when the high-level interface is valid.

Listing 6: ISpDriverDynasight.cp

MyDynasightCompletionProc
void MyDynasightCompletionProc(
   DynasightCompletionProcData* data)
{
   OSStatus err;
   AbsoluteTime time;
   TDynasightRecPtr dyna = (TDynasightRecPtr)data->data;
   TISpLowLevelState llState;
   TISpHighLevelState hlState;
   float xf, yf, zf;
   
   if ((dyna->active) && (data->dynasightStatus ==
         dynasightStatus_Track)) {
      time = ISpUptime();

      // Scale Dynasight coordinates between 0 and 1
      NormalizeDynasightPosition(&data->position, &xf, &yf, &zf);
      // Put point between kISpAxisMinimum and kISpAxisMaximum
      scale = kISpAxisMaximum - kISpAxisMinimum;
      xf = kISpAxisMinimum + xf * scale;
      yf = kISpAxisMinimum + yf * scale;
      zf = kISpAxisMinimum + zf * scale;
      llState.xAxis = (UInt32)xf;
      llState.yAxis = (UInt32)yf;
      llState.zAxis = (UInt32)zf;
      
      // Push low-level data for low-level interface
      if (llState.xAxis != dyna->oldLLState.xAxis) {
         err = ISpElement_PushSimpleData(
                     dyna->deviceXAxis, llState.xAxis, &time);
      }
      if (llState.yAxis != dyna->oldLLState.yAxis) {
         err = ISpElement_PushSimpleData(
                     dyna->deviceYAxis, llState.yAxis, &time);
      }
      if (llState.zAxis != dyna->oldLLState.zAxis) {
         err = ISpElement_PushSimpleData(
                     dyna->deviceZAxis, llState.zAxis, &time);
      }
      
      // Push high-level data for high-level interface
      LowToHighLevelState(&llState, &hlState);
      if (dyna->virtualElementsValid) {
         SetVirtualsData(dyna, &hlState);
      }
      
      dyna->oldLLState = llState;
      dyna->oldHLState = hlState;
   }
}



InputSprocket Driver Configuration

We will now show the important parts of the driver relating to the configuration dialog. For our Dynasight driver this part is relatively easy since we have only three popup menus in the dialog box (see Figure 2). Each menu can be used to change the function of a Dynasight axis. For example, a user might select the menu and change the function of the x-axis from need 'pitch' to need 'move forward'. The driver maintains the list of total needs of the application and a mapping of needs to axes. A selection in the dialog might change this mapping.

As was mentioned above, the first routine InputSprocket calls when starting configuration is the GetSize routine. The driver returns the minimal and optimal size we need, as shown in Listing 7. The next routine called is the GetIcon routine shown in Listing 8. The driver returns the resource identifier of the icon suite of the Dynasight driver.

Listing 7: ISpDriverDynasight.cp

GetSize
OSStatus GetSize(
   UInt32 refCon,
   Point *minimum,
   Point *best)
{
   refCon;
   best->h = minimum->h = 200;
   best->v = minimum->v = 120;   
   return noErr;
}

Listing 8: ISpDriverDynasight.cp
GetIcon
OSStatus GetIcon(
   UInt32 refCon,
   short *iconSuiteResourceId)
{
   refCon;
   *iconSuiteResourceId = kIconSuiteDynasight;
   return noErr;
}

When the Dynasight device is selected is the dialog box, InputSprocket calls the driver's Show routine listed in Listing 9. This is the time to have our dialog items added to the main dialog pane. First, some information about the dialog is stored for later use (in the Hide routine for instance). Then, the 'DITL' resource is retrieved from the resource file and appended at the end. Listing 10 shows how the reverse takes place. The Hide routine is called when another device is selected in the dialog or when the dialog is closed. Then, the driver removes its dialog items from the 'DITL'.

Listing 9: ISpDriverDynasight.cp

Show
OSStatus Show(
   UInt32 refCon,
   DialogPtr theDialog, 
   short dialogItemNumber,
   Rect *r)
{
   OSStatus err;
   TDynasightRecPtr dyna = (TDynasightRecPtr) refCon;
   Handle ditl;
   
   dyna->dialogRect = *r;   
   dyna->dialogPtr = theDialog;
   dyna->dialogBaseDITLCount = CountDITL(theDialog);

   // Open the resource file, get our DITL and append it
   dyna->resFileRef = FSpOpenResFile(&dyna->fileSpec, 
      fsRdPerm);
   err = ResError();
   if (err != noErr) { return err; }
   ditl = Get1Resource('DITL', kDITLID_Config);
   err = ResError();
   if (err != noErr) {
      CloseResFile(dyna->resFileRef);
      return err;
   }
   AppendDITL(theDialog, ditl, -dialogItemNumber);
   
   // Free our DITL
   ReleaseResource(ditl);

   return noErr;
}

Listing 10: ISpDriverDynasight.cp

Hide
OSStatus Hide(
   UInt32 refCon)
{
   TDynasightRecPtr dyna = (TDynasightRecPtr) refCon;
   // Restore to original count of items
   ShortenDITL(dyna->dialogPtr, CountDITL(dyna->dialogPtr) - 
      dyna->dialogBaseDITLCount);
   dyna->dialogPtr = nil;
   CloseResFile(dyna->resFileRef);
   return noErr;
}


When the dialog is on the screen, the driver needs to respond to events to track whether there are changes in the configuration. In our case, the driver has only popup menus that it can handle by responding to mouse click events. Therefore, our driver ignores all other events that InputSprocket passes. In Listing 11, it is shown how the driver handles mouse clicks. First the position of the click is established. Then we iterate through our popup menus and call HandleAxisClick for each axis. This routine checks whether the current need of an axis changes as a result of the click.

Listing 11: ISpDriverDynasight.cp

Click
OSStatus Click(
   UInt32 refCon, 
   const EventRecord *event)
{
   refCon;
   TDynasightRecPtr dyna = (TDynasightRecPtr) refCon;
   Point where;
   UInt32 itr;
   short itemNo;
   UInt32 oldNeed;

   where = event->where;
   GlobalToLocal(&where);

   for (itr = kDialogItem_FirstPopup;
         itr <= kDialogItem_NumPopups;
         itr++) {
      itemNo = itr + dyna->dialogBaseDITLCount;
      oldNeed = dyna->axisIndexToNeeds[itr-1];
      switch (itr) {
         case kDialogItem_XAxis:
            HandleAxisClick(dyna, where, itemNo,
               kISpElementLabel_Axis_XAxis, kAxisIndex_XAxis,
               oldNeed);
            break;
         case kDialogItem_YAxis:
            HandleAxisClick(dyna, where, itemNo,
               kISpElementLabel_Axis_YAxis, kAxisIndex_YAxis,
               oldNeed);
            break;
         case kDialogItem_ZAxis:
            HandleAxisClick(dyna, where, itemNo,
               kISpElementLabel_Axis_ZAxis, kAxisIndex_ZAxis,
               oldNeed);
            break;
         default:
            break;
      }      
   }
   
   return noErr;
}



Listing 12 shows the HandleAxisClick routine. First, it is checked whether the popup is actually hit and if the need for the current axis changed as a result of the click. If the need changed, the need for that axis is first cleared. Then, the new need is activated. The current configuration is marked 'dirty' as InputSprocket requires. Finally, the popup menu is drawn with the new need setting to reflect the change in need for this axis.

Listing 12: ISpDriverDynasight.cp

HandleAxisClick
void HandleAxisClick(
   TDynasightRecPtr dyna,
   Point where,
   short itemNo,
   ISpElementLabel elementLabel,
   TAxisIndex axisIndex,
   UInt32 oldNeed)
{
   UInt32 itemIndex = itemNo - dyna->dialogBaseDITLCount;
   UInt32 newNeed;
   
   if (CheckPopUpHit(dyna, where, itemNo,
         kISpElementKind_Axis, elementLabel, validAxisKinds,
         validAxisKindsCount, oldNeed, newNeed) &&
         (oldNeed != newNeed)) {
      dynasightPtr->axisIndexToNeeds[axisIndex] = newNeed;
      dynasightPtr->configurationDirty = true;
      PlotPopupIcon(dynasightPtr,axisIndex + 1 + 
         dynasightPtr->dialogBaseDITLCount, ttNone);
   }
}


This concludes our coverage of the driver's code for the configuration dialog. There are some parts of the driver that we could not cover such as auto-configuration. The interested reader can look at the full source code of the driver to see how this is accomplished.

Conclusion

In this month's episode, you have discovered how InputSprocket can be used to create a driver for the Dynasight device. We hope that this episode has illustrated the power of InputSprocket. To connect Cubby with the Dynasight, we could have used parts of the driver code and pasted them directly into the Cubby application code. That would have saved the time to write and debug the driver. However, now that we have a driver, we can use the same device with other InputSprocket-savvy applications (imagine looking around in a game with the Dynasight as head-tracking device...). Moreover, making Cubby support InputSprocket, we can use any 3D device with an InputSprocket driver for Cubby.

In next month's episode, we will cover the integration of Cubby with InputSprocket. We will show you how Cubby uses InputSprocket to move the cameras from part I. In addition, we will cover calibrating Cubby so that Cubby positions the cameras such that the correct images are generated.

Bibliography and References

  • Apple Game Sprockets web site. The place to download Apple Game Sprockets software, documentation and example software. Available as:
    http://developer.apple.com/games/sprockets/index.html
  • Configuring Game Input Devices with InputSprocket. Available as: http://developer.apple.com/techpubs/macos8/pdf/InputSprocket1.7.pdf.
  • Djajadiningrat, J. P. & Gribnau, M. W. (1998). Desktop VR using QuickDraw 3D, Part I. MacTech Magazine 14(7), 32-43.
  • Gribnau, M. W. & Djajadiningrat, J. P. (1998). Desktop VR using QuickDraw 3D, Part II. MacTech Magazine 14(8), 26-34.
  • Djajadiningrat, J.P. & Gribnau, M.W. (2000). Cubby: Multiscreen Desktop VR Part I. MacTech Magazine 16(10).

Maarten is always jealous of his co-author. The ease with which Tom creates a funny 'about the author' piece starts to become almost traumatic. He is now on the verge of refusing to finish his contribution to the final episode. You might try to inspire him with an email at: M.W.Gribnau@io.tudelft.nl.

There are some striking similarities between Tom and his Wallstreet PoBo. You need to push them really hard to wake them from sleep, if you persist it still takes ages before they finally get into action, and sometimes it appears as if they've woken up but really all they do is zombie around in some undefined state in which it is impossible to get anything sensible out of them. If they're up and running you can reach them at J.P.Djajadiningrat@io.tudelft.nl.

 
AAPL
$102.05
Apple Inc.
+2.29
MSFT
$44.80
Microsoft Corpora
+0.72
GOOG
$521.93
Google Inc.
+1.09

MacTech Search:
Community Search:

Software Updates via MacUpdate

RapidWeaver 6.0 - Create template-based...
RapidWeaver is a next-generation Web design application to help you easily create professional-looking Web sites in minutes. No knowledge of complex code is required, RapidWeaver will take care of... Read more
NTFS 12.0.39 - Provides full read and wr...
Paragon NTFS breaks down the barriers between Windows and OS X. Paragon NTFS effectively solves the communication problems between the Mac system and NTFS, providing full read and write access to... Read more
RestoreMeNot 2.0.3 - Disable window rest...
RestoreMeNot provides a simple way to disable the window restoration for individual applications so that you can fine-tune this behavior to suit your needs. Please note that RestoreMeNot is designed... Read more
Macgo Blu-ray Player 2.10.9.1750 - Blu-r...
Macgo Mac Blu-ray Player can bring you the most unforgettable Blu-ray experience on your Mac. Overview Macgo Mac Blu-ray Player can satisfy just about every need you could possibly have in a Blu-ray... Read more
Apple iOS 8.1 - The latest version of Ap...
The latest version of iOS can be downloaded through iTunes. Apple iOS 8 comes with big updates to apps you use every day, like Messages and Photos. A whole new way to share content with your family.... Read more
TechTool Pro 7.0.5 - Hard drive and syst...
TechTool Pro is now 7, and this is the most advanced version of the acclaimed Macintosh troubleshooting utility created in its 20-year history. Micromat has redeveloped TechTool Pro 7 to be fully 64... Read more
PDFKey Pro 4.0.2 - Edit and print passwo...
PDFKey Pro can unlock PDF documents protected for printing and copying when you've forgotten your password. It can now also protect your PDF files with a password to prevent unauthorized access and/... Read more
Yasu 2.9.1 - System maintenance app; per...
Yasu was originally created with System Administrators who service large groups of workstations in mind, Yasu (Yet Another System Utility) was made to do a specific group of maintenance tasks... Read more
Hazel 3.3 - Create rules for organizing...
Hazel is your personal housekeeper, organizing and cleaning folders based on rules you define. Hazel can also manage your trash and uninstall your applications. Organize your files using a... Read more
Autopano Giga 3.7 - Stitch multiple imag...
Autopano Giga allows you to stitch 2, 20, or 2,000 images. Version 3.0 integrates impressive new features that will definitely make you adopt Autopano Pro or Autopano Giga: Choose between 9... Read more

Latest Forum Discussions

See All

Inferno 2 Review
Inferno 2 Review By Andrew Fisher on October 21st, 2014 Our Rating: :: TWIN STICK GOODNESSUniversal App - Designed for iPhone and iPad With tight controls and awesome, stark visuals, Inferno 2 is loads of fun.   | Read more »
Clips Review
Clips Review By Jennifer Allen on October 21st, 2014 Our Rating: :: CONVENIENT PASTINGUniversal App - Designed for iPhone and iPad Making copying and pasting more powerful than usual, Clips is a great way to move stuff around.   | Read more »
MonSense Review
MonSense Review By Jennifer Allen on October 21st, 2014 Our Rating: :: ORGANIZED FINANCESiPhone App - Designed for the iPhone, compatible with the iPad Organize your finances with the quick and easy to use, MonSense.   | Read more »
This Week at 148Apps: October 13-17, 201...
Expert App Reviewers   So little time and so very many apps. What’s a poor iPhone/iPad lover to do? Fortunately, 148Apps is here to give you the rundown on the latest and greatest releases. And we even have a tremendous back catalog of reviews; just... | Read more »
Angry Birds Transformers Review
Angry Birds Transformers Review By Jennifer Allen on October 20th, 2014 Our Rating: :: TRANSFORMED BIRDSUniversal App - Designed for iPhone and iPad Transformed in a way you wouldn’t expect, Angry Birds Transformers is a quite... | Read more »
GAMEVIL Announces the Upcoming Launch of...
GAMEVIL Announces the Upcoming Launch of Mark of the Dragon Posted by Jessica Fisher on October 20th, 2014 [ permalink ] Mark of the Dragon, by GAMEVIL, put | Read more »
Interview With the Angry Birds Transform...
Angry Birds Transformers recently transformed and rolled out worldwide. This run-and-gun title is a hit with young Transformers fans, but the ample references to classic Transformers fandom has also earned it a place in the hearts of long-time... | Read more »
Hail to the King: Deathbat Review
Hail to the King: Deathbat Review By Rob Thomas on October 20th, 2014 Our Rating: :: SO FAR AWAYUniversal App - Designed for iPhone and iPad Hail to the King: Deathbat may feel like “Coming Home” for Avenged Sevenfold’s faithful,... | Read more »
Find Free Food on Campus with Ypay
Find Free Food on Campus with Ypay Posted by Jessica Fisher on October 20th, 2014 [ permalink ] iPhone App - Designed for the iPhone, compatible with the iPad | Read more »
Strung Along Review
Strung Along Review By Jordan Minor on October 20th, 2014 Our Rating: :: GOT NO STRINGSUniversal App - Designed for iPhone and iPad A cool gimmick and a great art style keep Strung Along from completely falling apart.   | Read more »

Price Scanner via MacPrices.net

Select MacBook Airs $100 off MSRP, free shipp...
B&H Photo has 2014 a couple of MacBook Airs on sale for $100 off MSRP. Shipping is free, and B&H charges NY sales tax only. They also include free copies of Parallels Desktop and LoJack for... Read more
13-inch 2.5GHz MacBook Pro on sale for $100 o...
B&H Photo has the 13″ 2.5GHz MacBook Pro on sale for $999.99 including free shipping plus NY sales tax only. Their price is $100 off MSRP. Read more
Strong iPhone, Mac And App Store Sales Drive...
Apple on Monday announced financial results for its fiscal 2014 fourth quarter ended September 27, 2014. The Company posted quarterly revenue of $42.1 billion and quarterly net profit of $8.5 billion... Read more
Apple Posts How-To For OS X Recovery
OS X 10.7 Lion and later include OS X Recovery. This feature includes all of the tools you need to reinstall OS X, repair your disk, and even restore from a Time Machine backup. OS X Recovery... Read more
Mac OS X Versions (Builds) Supported By Vario...
Apple Support has posted a handy resource explaining which Mac OS X versions (builds) originally shipped with or are available for your computer via retail discs, downloads, or Software Update. Apple... Read more
Deals on 2011 13-inch MacBook Airs, from $649
Daily Steals has the Mid-2011 13″ 1.7GHz i5 MacBook Air (4GB/128GB) available for $699 with a 90 day warranty. The Mid-2011 13″ 1.7GHz i5 MacBook Air (4GB/128GB SSD) is available for $649 at Other... Read more
2013 15-inch 2.0GHz Retina MacBook Pro availa...
B&H Photo has leftover previous-generation 15″ 2.0GHz Retina MacBook Pros now available for $1599 including free shipping plus NY sales tax only. Their price is $400 off original MSRP. B&H... Read more
Updated iPad Prices
We’ve updated our iPad Air Price Tracker and our iPad mini Price Tracker with the latest information on prices and availability from Apple and other resellers, including the new iPad Air 2 and the... Read more
Apple Pay Available to Millions of Visa Cardh...
Visa Inc. brings secure, convenient payments to iPad Air 2 and iPad mini 3as well as iPhone 6 and 6 Plus. Starting October 20th, eligible Visa cardholders in the U.S. will be able to use Apple Pay,... Read more
Textkraft Pocket – the missing TextEdit for i...
infovole GmbH has announced the release and immediate availability of Textkraft Pocket 1.0, a professional text editor and note taking app for Apple’s iPhone. In March 2014 rumors were all about... Read more

Jobs Board

*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
*Apple* Retail - Multiple Positions (US) - A...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
Position Opening at *Apple* - Apple (United...
…customers purchase our products, you're the one who helps them get more out of their new Apple technology. Your day in the Apple Store is filled with a range of Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** At the Apple Store, you connect business professionals and entrepreneurs with the tools they need in order to put Apple solutions to work in their Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.