spatial/spatial.c File Reference

#include "spatial.h"
#include <z800.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <termios.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>

Functions

int sptInit (int what, char *prog_name)
 Initialize the spatial library.
int sptEnableStereo ()
 enable stereo mode on the Z800
int sptDisableStereo ()
 turn Z800 stereo mode off
int sptClose ()
 close spatial devices
int sptCycleBrightness ()
 change the Z800 brightness
int sptContinuousTracking ()
 enable continuous position tracking mode
int sptPointTracking ()
 request a single tracking data frame
int sptUpdatePosition ()
 update active stations' position and rotation data
float * sptGetPositionPointer (unsigned int station)
 get pointer to a station's tracking data
int sptSetHemisphere (unsigned int station, float x, float y, float z)
 set tracking system hemisphere of operation
int sptSetAlignmentFrame (unsigned int station, float ox, float oy, float oz, float xx, float xy, float xz, float yx, float yy, float yz)
 modifies tracking system alignment frame
int sptResetAlignmentFrame (unsigned int station)
 resets the Patriot's alignment frame
int sptEnableStations (unsigned int station)
 enable tracking for station(s)
int sptResetPatriot (void)
 reset the Patriot tracking system
void sptHeadsetViewport ()
 change to Z800 headset viewport
void sptSecondViewport ()
 change to LCD/projector viewport
void sptRenderFrame ()
 finish drawing a frame
void sptGetFrustum (float vfov, float zNear, float *ret)
 obtain a 3D viewing frustum
SDL_Surface * sptGetSDLSurface (void)
 obtain SDL surface

Variables

int sptIsLeft = 0
 true if we are drawing a frame to the left eye of the headset

Detailed Description

Author: Josh Holtrop

spatial.c is the main file implementing the spatial library, a library providing an easier interface to the 3D headset, position tracking, and graphics hardware.

History:


Function Documentation

int sptClose (  ) 

close spatial devices

This function releases resources that had been claimed upon initialization of the spatial library

Returns:
zero for sucess, nonzero for error

int sptContinuousTracking (  ) 

enable continuous position tracking mode

This function tells the Patriot to start sending data frames at a rate of 60Hz to the PC via the serial line rather than waiting to be asked for a data frame.

Returns:
zero for sucess, nonzero for error

int sptCycleBrightness (  ) 

change the Z800 brightness

This is a simple function to change the brightness level of the Z800 headset from software. Each time it is called it will "cycle" the brightness level on the headset.

Returns:
zero for sucess, nonzero for error

int sptDisableStereo (  ) 

turn Z800 stereo mode off

Disable stereo mode for Z800 headset

Returns:
zero for sucess, nonzero for error

int sptEnableStations ( unsigned int  station  ) 

enable tracking for station(s)

This function enables one or both of the Patriot sensors to send data frames back to the PC

Parameters:
station SPT_STATION1, SPT_STATION2, or SPT_STATIONBOTH
Returns:
zero for sucess, nonzero for error

int sptEnableStereo (  ) 

enable stereo mode on the Z800

Tell the Z800 headset that every other frame should go to every other eye from now on

void sptGetFrustum ( float  vfov,
float  zNear,
float *  ret 
)

obtain a 3D viewing frustum

This graphics helper function returns values that can be used to send to OpenGL's glFrustum() function. The values returned specify a viewing frustum that has not been offset for the eye separation. See glFrustum() man page for more information.

Parameters:
vfov the vertical field-of-view angle in degrees
zNear the distance to the near clipping plane
ret a pointer to where to store the 4 floating point values for the viewing frustum.

float* sptGetPositionPointer ( unsigned int  station  ) 

get pointer to a station's tracking data

This function returns to the user application a pointer which can be used by the user application to access the position data for each sensor when it is needed

Parameters:
station must be SPT_STATION1 or SPT_STATION2
Returns:
a pointer to an array of floats specifying the position and rotation for the given station

SDL_Surface* sptGetSDLSurface ( void   ) 

obtain SDL surface

This graphics helper function returns the main SDL surface used in drawing the screen in case the application desires to do something with it directly

Returns:
a pointer to the SDL_Surface object

void sptHeadsetViewport (  ) 

change to Z800 headset viewport

This is a graphics helper function to set the OpenGL viewport to the left side of the double-wide screen. The Left side of the screen will be the image that is sent to one of the eye screens on the headset.

int sptInit ( int  what,
char *  prog_name 
)

Initialize the spatial library.

This routine is used to initialize spatial library and devices. It must be called before any other spt* routines.

Parameters:
what what part of spatial to initialize -- can be SPT_HEADSET, SPT_TRACKING, SPT_GRAPHICS, SPT_AUDIO, or any combination of these ORed together
prog_name the program name -- this is used to set the window title if SPT_GRAPHICS is specified
Returns:
zero for success, nonzero for error

int sptPointTracking (  ) 

request a single tracking data frame

This function requests a single data frame with position and rotation information from the Patriot tracking system and also disables continuous tracking if it had been enabled

Returns:
zero for sucess, nonzero for error

void sptRenderFrame (  ) 

finish drawing a frame

This function can be called when a complete OpenGL scene is rendered. It will cause a buffer swap (which should be synced to happen during the vertical retrace period of the Z800 headset) and it will toggle the sptIsLeft variable to be used by the application.

int sptResetAlignmentFrame ( unsigned int  station  ) 

resets the Patriot's alignment frame

This function resets the "alignment frame" of the Patriot magnetic tracking system back to its default value

Parameters:
station SPT_STATION1, SPT_STATION2, or SPT_STATIONBOTH
Returns:
zero for sucess, nonzero for error

int sptResetPatriot ( void   ) 

reset the Patriot tracking system

This function sends a reset to the Patriot -- apparently the Patriot either (a) does not reset immediately or (b) waits until it has another command to reset. Since resets take up to a couple dozen seconds, calling sptResetPatriot() and then sptPointTracking() and then closing the file descriptor and waiting a minute is probably the best way to reset the system from software. Of course, cycling the power would probably be easier.

Returns:
zero for sucess, nonzero for error

void sptSecondViewport (  ) 

change to LCD/projector viewport

This is a graphics helper function to select the right half of the screen for OpenGL to draw to. This side will go to the LCD or projector.

int sptSetAlignmentFrame ( unsigned int  station,
float  ox,
float  oy,
float  oz,
float  xx,
float  xy,
float  xz,
float  yx,
float  yy,
float  yz 
)

modifies tracking system alignment frame

This function can alter the "alignment frame" for the Patriot magnetic tracking system. See the Patriot documentation for more details. You probably will not even need to call this function.

Parameters:
station SPT_STATION1, SPT_STATION2, or SPT_STATIONBOTH
ox the x coordinate of the new origin point
oy the y coordinate of the new origin point
oz the z coordinate of the new origin point
xx the x coordinate of the new X axis vector
xy the y coordinate of the new X axis vector
xz the z coordinate of the new X axis vector
yx the x coordinate of the new Y axis vector
yy the y coordinate of the new Y axis vector
yz the z coordinate of the new Y axis vector
Returns:
zero for sucess, nonzero for error

int sptSetHemisphere ( unsigned int  station,
float  x,
float  y,
float  z 
)

set tracking system hemisphere of operation

This function tells the Patriot which hemisphere the sensors are located in so that it will obtain the correct measurements (the magnetic field is symmetric). The hemisphere is specified by an (x,y,z) vector from the magnetic field source. The vector will be in the center of the hemisphere of operation.

Parameters:
station SPT_STATION1, SPT_STATION2, or SPT_STATIONBOTH
x the x coordinate of the hemisphere vector
y the y coordinate of the hemisphere vector
z the z coordinate of the hemisphere vector
Returns:
zero for sucess, nonzero for error

int sptUpdatePosition (  ) 

update active stations' position and rotation data

This function updates the position data stored in the buffers for each sensor in the Patriot tracking system based on what data frames are available to be read in.

Returns:
zero for sucess, nonzero for error


Variable Documentation

int sptIsLeft = 0

true if we are drawing a frame to the left eye of the headset

This variable will be true if a frame is being drawn to the left eye of the headset viewport, and false otherwise. It is automatically modified by the sptRenderFrame() function.


Generated on Mon Aug 27 20:51:51 2007 for spatial by  doxygen 1.4.7