#include #include #include #define _USE_MATH_DEFINES #include #include #include #include "typedefs.h" #include "glutcallbacks.h" #include "textfile.h" //Global variables GameState_t g_GameState; void InitGL(void) { GLfloat l_f4LightPos[] = {0.0, 1.0, 1.0, 0.0}, l_f4GlobalAmbient[] = {0.3, 0.3, 0.3, 1.0}; //init OpenGL glLightfv(GL_LIGHT0, GL_POSITION, l_f4LightPos); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, l_f4GlobalAmbient); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glClearColor(1.0, 1.0, 1.0, 1.0); glClearDepth(1000.0); glDisable(GL_DITHER); glShadeModel(GL_SMOOTH); glEnable(GL_CULL_FACE); } bool InitWiiMotes() { g_GameState.m_pTrackingWiimote = new wiimote(); g_GameState.m_pTrackingWiimote->ChangedCallback = NULL; //no callbacks, we just poll... g_GameState.m_pTrackingWiimote->CallbackTriggerFlags = NO_CHANGE; /*printf("connecting:\n"); while(!g_Wiimote.Connect(wiimote::FIRST_AVAILABLE)) { Sleep(1000); printf("."); } printf("connected\n");*/ if (g_GameState.m_pTrackingWiimote->Connect(wiimote::FIRST_AVAILABLE)) { g_GameState.m_pTrackingWiimote->SetLEDs(0x0f); g_GameState.m_pTrackingWiimote->SetReportType(wiimote::IN_BUTTONS_ACCEL_IR_EXT); // IR dots /*g_GameState.m_pTrackingWiimote->SetRumble(true); Sleep(500); g_GameState.m_pTrackingWiimote->SetRumble(false); */ return true; } else { return false; } } bool LoadGreyScaleShader() { char *vs_text = NULL,*fs_text = NULL; GLuint vs = glCreateShader(GL_VERTEX_SHADER), fs = glCreateShader(GL_FRAGMENT_SHADER); vs_text = textFileRead("shaders\\greyscale.vert"); if (vs_text == NULL) { return false; } fs_text = textFileRead("shaders\\greyscale.frag"); if (fs_text == NULL) { free(vs_text); return false; } glShaderSource(vs, 1, (const char**)&vs_text,NULL); glShaderSource(fs, 1, (const char**)&fs_text,NULL); free(vs_text); free(fs_text); glCompileShader(vs); glCompileShader(fs); g_GameState.m_GreyScaleShaderProgram = glCreateProgram(); glAttachShader(g_GameState.m_GreyScaleShaderProgram,fs); glAttachShader(g_GameState.m_GreyScaleShaderProgram,vs); glLinkProgram(g_GameState.m_GreyScaleShaderProgram); g_GameState.m_GSConvScaleLoc = glGetUniformLocation(g_GameState.m_GreyScaleShaderProgram, "g_ConversionWeights"); return true; } int main(int argc, char **argv) { //init the GL Utility Toolkit glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow("HeadTrackDemo"); //register GLUT callback routines glutDisplayFunc(Display); glutIdleFunc(Idle); glutReshapeFunc(Reshape); glutKeyboardFunc(Keyboard); //init openGL state variables InitGL(); //init the GL Extension Wrangler library glewInit(); //check for OpenGL 2.0 support if (!glewIsSupported("GL_VERSION_2_0")) { printf("Your graphics hardware/software does not support OpenGL 2.0\n"); exit(1); } //try to load the grayscale shader if (!LoadGreyScaleShader()) { printf("Failed to load vertex/fragment shader.\n"); exit(1); } // initialise the stereo vision parameters g_GameState.m_FrustumParms.m_dEyeDistMM = 70.0; //7 cm g_GameState.m_FrustumParms.m_dDefHeadDistMM = 1000.0; //100 cm g_GameState.m_FrustumParms.m_dHeadTrackLedDist = 205.0; g_GameState.m_FrustumParms.m_dRadPerCameraPixel = (41.0*(M_PI/180.0))/1024.0; g_GameState.m_FrustumParms.m_dCameraXCenter = 1024.0/2.0; g_GameState.m_FrustumParms.m_dCameraYCenter = 768.0/2.0; g_GameState.m_FrustumParms.m_dYAngleCorrection = 0.0; //to be initialised correctly g_GameState.m_FrustumParms.m_dScreenHeightWorld = 20.0; /*g_GameState.m_FrustumParms.m_dCameraYOffset = 130.0; g_GameState.m_FrustumParms.m_dScreenHeightMM = 210.0; g_GameState.m_FrustumParms.m_dScreenAspect = 4.0/3.0;*/ g_GameState.m_GSConvScale[0] = 0.299; g_GameState.m_GSConvScale[1] = 0.587; g_GameState.m_GSConvScale[2] = 0.114; g_GameState.m_FrustumParms.m_dCameraYOffset = 205.0; g_GameState.m_FrustumParms.m_dScreenHeightMM = 320.0; g_GameState.m_FrustumParms.m_dScreenAspect = 16.0/10.0; g_GameState.m_bHeadTrackingEnabled = false; g_GameState.m_bStereoEnabled = false; InitWiiMotes(); glutFullScreen(); //action!! glutMainLoop(); return 0; } ////initialise the parameters needed for perspective correction when head tracking //g_HeadTrackParms.m_dHeadTrackLedDist = 205.0; //g_HeadTrackParms.m_dRadPerCameraPixel = (41.0*(M_PI/180.0))/1024.0; //g_HeadTrackParms.m_dCameraXCenter = 1024.0/2.0; //g_HeadTrackParms.m_dCameraYCenter = 768.0/2.0; //g_HeadTrackParms.m_dYAngleCorrection = 0.0; //to be initialised correctly //g_HeadTrackParms.m_dCameraYOffset = 205.0; //g_HeadTrackParms.m_dScreenHeightMM = 320.0; //g_HeadTrackParms.m_dScreenAspect = 16.0/10.0; //g_HeadTrackParms.m_dScreenHeightWorld = 20.0;