Support request: Simple Direct Media Layer

If you have questions or comments concerning any non-support related 3Dconnexion topic, please use this forum.

Moderator: Moderators

Post Reply
lmop
Posts: 12
Joined: Tue Mar 06, 2007 7:33 am
Location: UK

Support request: Simple Direct Media Layer

Post by lmop »

To quote the SDL homepage:
Simple DirectMedia Layer wrote:Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. It is used by MPEG playback software, emulators, and many popular games, including the award winning Linux port of "Civilization: Call To Power."
As such, integrating the 3Dconnexion SDK into this framework would provide a one-stop shop for people who want to be able to use devices like the SpaceNavigator in their 3D applications - particularly those seeking to create a cross-platform product.

From a personal point of view, I'm interested in such support in order to be able to use SpaceNavigator with Homeworld.
agoenczi
User
User
Posts: 668
Joined: Mon Dec 04, 2006 6:17 am
Location: EU

Support request: Simple Direct Media Layer

Post by agoenczi »

Hi Imop

Please see the following thread. It may offer a solution for you.
agoenczi
lmop
Posts: 12
Joined: Tue Mar 06, 2007 7:33 am
Location: UK

Post by lmop »

Thanks for the link but that's for Windows and doesn't address the cross-platform issue at all. The SDL library has the advantage that you only need to link to it once and your application runs everywhere (individual compiles withstanding).

Now obviously developers could handle the cross-platform code themselves on a per-application basis but that means they would have to do it three times (for Windows/Linux/Macintosh) - and it would also pretty much be the same code that everyone else has had to write in order to do the exact same thing for their applications. Integration with SDL would save a lot of duplication of effort as well as have the advantage that you can fix an implementation/interface bug once and it is fixed for all applications that use that library (well, after a relink anyway).

Anyway, I've received confirmation that my SpaceNavigator is in the post. I can't wait to play with it on my Mac. I'll try integrating with it via the Mac beta driver/framework that's available. Thanks.
jwick
Moderator
Moderator
Posts: 3331
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Post by jwick »

Hi Imop,

That does sound like a good library to be supported by. If you are a developer or know the developers of it, we'd be happy to help out with any questions or issues that come up during the integration.

Jim
3Dx Software Development
lmop
Posts: 12
Joined: Tue Mar 06, 2007 7:33 am
Location: UK

Post by lmop »

I had a play with my SpaceNavigator, SDL and the Mac OS X beta Framework but unfortunately I could not interface with the device. I've pretty much exhausted what I can do without some input from the friendly 3Dconnexion engineers :) I've detailed what I did (and how you can easily replicate it) at the bottom of this post.

In short, I think the possible issue is is that the SpaceNavigator is not registering itself with the HID library such that SDL can find it (specifically: kHIDUsage_GD_Joystick). Judging by some of the strings in the 3Dconnexion driver (ahem) I think may have been registered as a mouse. This has a certain logic to it but a joystick feels a more instinctive to me given the number of degrees of freedom the SpaceNavigator et al support. Would it be possible to register them as joysticks instead? If there are reasons why a mouse was chosen (and must remain so), is it possible to register a device using two different kHIDUsage_*?

Many thanks for any help/assistance you can provide.

----------

What I did was:

1) Download the runtime SDL library.

2) After mounting the .dmg, copy SDL.framework to ~/Library/Frameworks

3) Download the development SDL library (this will make it a lot easier to get up-and-running).

4) After mounting the .dmg, copy TemplatesForXcode/* to ~/Library/Application Support/Apple/Developer Tools/Project Templates/Application (you will have to manually create the subdirectory hierarchy I've highlighted).

5) Start Xcode

6) Choose the File -> New Project... menu item

7) Select SDL Application that is in the Application collapsable list of project types.

8 ) Save the project wherever you want.

9) Edit main.c:

- change "Uint32 initflags = SDL_INIT_VIDEO;" to "Uint32 initflags = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK;"

- add the following after the SDL_Init if() block and before the setting of the video mode block:

Code: Select all

else
{
    fprintf(stderr, "SDL successfully initialized\n");
}
int num_joysticks = SDL_NumJoysticks();
fprintf(stderr, "num_joysticks = %d\n", num_joysticks);
10) Select the Build -> Build and run menu item. The application will now run (assuming it compiles successfully, which it should). stderr is logged to the Run Log window. It should display automatically but you can reach it via the Window -> Tools -> Run Log menu item. (NB: don't command-Q quit the application as any key press (including the command key) will cause the application to quit and you may inadvertantly send a command-Q to Xcode instead...)

When I run it I get:

Code: Select all

[Session started at 2007-03-12 20:54:22 +0000.]
SDL successfully initialized
num_joysticks = 0
so it looks like that the 3Dconnexion driver software isn't registering itself correctly with IOHIDDeviceInterface - or at least not how SDL is expecting it to be.

Documentation of interest:

The SDL source code dealing with joysticks on Mac OS X: SDL-1.2/src/joystick/darwin/SDL_sysjoystick.c. I'd recommend looking at the SDL_SYS_JoystickInit function to see how SDL is detecting relevant devices.

SDL documentation index

SDL: Input Handling: Handling Joysticks

Again, many thanks for any assistance you can provide.
flomotan
Moderator
Moderator
Posts: 287
Joined: Mon Jan 08, 2007 3:37 pm

Post by flomotan »

You can try changing the SDL_SYS_JoystickInit(void) function to also consider a multi-axis controller.

Code: Select all

/* Filter device list to non-keyboard/mouse stuff */ 
if ( (device->usagePage != kHIDPage_GenericDesktop) ||
     ((device->usage != kHIDUsage_GD_Joystick &&
      device->usage != kHIDUsage_GD_GamePad &&
      device->usage != kHIDUsage_GD_MultiAxisController)) ) {
I've not tested this but it could be the solution you need to detect our device
lmop
Posts: 12
Joined: Tue Mar 06, 2007 7:33 am
Location: UK

Post by lmop »

After some faffing around getting SDL to compile from source (the Mac OS X project is a bit out of date with regard to the head revision) I finally got a test version to meddle with. A great many thanks for your tip - I now get:

Code: Select all

lmop's version of sdl being used...
SDL successfully initialized
num_joysticks = 1

SDL_JoystickName(0) = SpaceNavigator
Sweet. :D

For reference:

Code: Select all

case SDL_JOYAXISMOTION:
    switch (event.jaxis.axis)
    {
        // process event.jaxis.value in these cases

        case 0: // translation (+/-) left-right
        case 1: // translation (+/-) forwards-backwards
        case 2: // translation (+/-) up-down

        case 3: // pitch (+/-) back-forward
        case 4: // roll  (+/-) left-right
        case 5: // yaw   (+/-) right-left

        default:
            break;
    }
    break;

case SDL_JOYBUTTONDOWN: 
    switch (event.jbutton.button)
    {
        case 0: // left button
        case 1: // right button

        default:
            break;
    }
    break;
I'll play around with it some more and then commit any necessary changes to the SDL codebase. Thanks again.
Post Reply