/* bareVR.c - A bare-bones VR program to be used as a starting point
	for Eng 591, Virtual Reality Programming.

	Written August 1999 by John T. Bell

	Last modified _________ by __________
*/

#include <stdlib.h>
#include <stdio.h>
#include "wt.h"

/* Function Prototypes */

void UserActions( void );

/* Global Variables - Use only when NECESSARY */

WTnode *Root = NULL;
WTviewpoint *Viewpoint = NULL;
WTsensor *Mouse = NULL;

int main ( int argc, char **argv )

{

	/* Intialize the Universe */
	
        WTuniverse_new( WTDISPLAY_DEFAULT, WTWINDOW_DEFAULT );
	
	/* Set some global variables */
	
        Root = WTuniverse_getrootnodes();
	Viewpoint = WTuniverse_getviewpoints();

        /* Set up devices */

        WTkeyboard_open();

        Mouse = WTmouse_new();
        if( !Mouse )
            WTerror( "Sorry;  A mouse is required to run"
                " this program.\n" );
        else {
            WTmotionlink_new( Mouse, Viewpoint, WTSOURCE_SENSOR, 
	    	WTTARGET_VIEWPOINT );
        }

        /* Build the scene graph */

        WTlightnode_newdirected( Root );
        WTnode_load( Root, "oplan.nff", 1.0 );
        WTnode_load( Root, "clown.dxf", 1.0 );
        WTnode_load( Root, "lunchbox.3ds", 1.0 );
        WTnode_load( Root, "snail.wrl", 1.0 );

	/* Initialize the viewpoint */

	WTwindow_zoomviewpoint( WTuniverse_getcurrwindow() );
	
	/* Setup the action function */
        
        WTuniverse_setactions( UserActions );

	/* The "go" function runs the simulation.  
	   It doesn't return until we quit. */
	   
        WTuniverse_ready();
        WTuniverse_go();
	
	/* And now to clean up our toys and go home. */

        WTuniverse_delete();

        return 0;

} /* End of Main Routine */

/********************************************************************************/

void UserActions( void ) {

        short key;

        /* Process Keyboard Input */

        key = WTkeyboard_getlastkey();

        if( key ) {

            switch( key ) {

                case 'q':
                case 'Q': 
			WTuniverse_stop();
                        break;

                case 'p':
                case 'P':
			WTnode_print( Root );
			break;

                case 'h':  /* Help - Fall through to default */
                case 'H':
                case '?':   

                default:
			WTmessage( "\nThe following keys are active:\n\n" );
                    	WTmessage( "Q or q: Quit.\n" );
			WTmessage( "P or p: Print scene graph.\n" );
	                break;

            }
        }

        return;

} /* End of UserActions */
