next up previous contents
Next: Performance Up: Adapting your applications to Previous: Adapting your applications to   Contents

Porting 3D apps to multiview systems

Most 3D applications can be easily ported to run in multiview environments.

There are only two requirements:

  1. You must be able to render the view in any direction;
  2. You must have variable with the viewer's position and orientation.
Not that hard, huh? Some applications that use hacks (such as direct 2D drawing, magics in the z-buffer, etc) may be harder to port. In short, if you can render the view in any direction you want, then it's very easy to port.

Below is a step by step procedure that is likely to work in virtually any 3D application.

  1. Define the special functions. They are responsible for setting the view in each client. For example, for setting orthogonal views:

    int front (void *data) { 
    return 0; 

    int left (void *data) { 

    glRotated(90, 0, -1, 0);

    return 0; 

    int right (void *data) { 

    glRotated(90, 0, 1, 0); 

    return 0; 

    int back (void *data) { 

    glRotated(180, 0, -1, 0); 

    return 0; 

    }DICE_Function DICE_MyFunctions[] = {

    { "front", front }, { "left", left }, { "right", right }, { "back", back }, { NULL, NULL } }; 

  2. Add DICE_init()/DICE_close() calls. The DICE_init() call should be one of the first calls in your program. The sooner, the better. DICE_close() should be called everywhere your application may exit, ensuring that all clients and the server are automatically closed.
  3. Declare your global variables as shared variables. In general, you'll want to share: position, viewing direction, viewing options (such as wireframe/solid, textures on/off). I suggest that physic simulation is handled only in one client (original). It's quite easy to do it: just add this code to the beginning of every function you want to run in only one client:

    if (!DICE_is_original()) 
    return;
  4. I suggest that you write a mysync() function, to take care of the updates/synchronization of the shared variables whenever you synchronize. Call it instead of DICE_sync(). Something like:

    int my_sync ( void ) { 
    int i; 

    DICE_sync_update("axisRot", &axisRot); 

    DICE_sync_update("rotate", &rotate);

    i = DICE_sync(); 

    if ( i < 0 ) 

    return i;
    axisRot = *((int *)DICE_sync_get("axisRot")); 

    rotate = *((float *)DICE_sync_get("rotate"));

    }
That's it. It usually takes about five minutes to have a simple application converted.


next up previous contents
Next: Performance Up: Adapting your applications to Previous: Adapting your applications to   Contents
2001-12-09