#include "view.h"

/*these are the key codes for camera changes*/

#define SWIVEL_LEFT		0x61	/*a*/
#define SWIVEL_RIGHT	0x64	/*d*/
#define SWIVEL_UP		0x78	/*x*/
#define SWIVEL_DOWN		0x77	/*w*/
#define MOVE_FOWARDS	0x73	/*s*/
#define MOVE_BACKWARDS	0x53	/*S*/
/*shift s is backwards*/


#define QUIT			0x2e


void mainEventLoop(view,facelist,tree)
View *view;
FaceList *facelist;
Tree *tree;
{
	EventRecord event;
	REAL swivel,translation;
	int charCode;
	TMatrix posR,negR;
	
	swivel = PI/18.0;
	translation = 10.0;
	
	/*construct the left and right rotataion matrices - rotation about z*/
	setZRotationMatrix(posR.TM,swivel);
	setZRotationMatrix(negR.TM,-swivel);
	
	while(1){
		while(!GetNextEvent(keyDownMask,&event));
				
		
		switch(event.message & charCodeMask){
			case SWIVEL_LEFT	: 	/*rotate VPN about z axis*/
									transformVPNOfView(view,&posR);
									break;
									
			case SWIVEL_RIGHT	: 	/*rotate VPN about z axis*/
									transformVPNOfView(view,&negR);
									break;
									
			case SWIVEL_UP		: 	/*rotate VUV*/
									break;		
										
			case SWIVEL_DOWN	: 	/*rotate VUV*/
									break;	
										
			case MOVE_FOWARDS	: 	/*move VRP*/
									translateVRPOfView(view,translation);
									break;		
			
			case MOVE_BACKWARDS	: 	/*move VRP*/
									translateVRPOfView(view,-translation);
									break;		
									
			case QUIT			:	EXIT;
			
			default				:   /*donothing*/;
		}		
		setView(view);
		clearDrawable();
		displayTreeOnView(view,facelist,tree);
	}
}