// Create the scene, and (re)initialize lights if changeLights is true void Scene::Init(bool changeLights) { // Get the max number of lights allowed by the graphic card glGetIntegerv(GL_MAX_LIGHTS, &maxLights); if( maxLights>16 ) maxLights = 16; // Create the lights array if( lights==NULL && maxLights>0 ) { lights = new Light[maxLights]; NumLights = 3; // default number of lights if( NumLights>maxLights ) NumLights = maxLights; changeLights = true; // force lights initialization // Create a tweak bar for lights CreateBar(); } // (Re)initialize lights if needed (uses random values) if( changeLights ) for(int i=0; i<maxLights; ++i) { lights[i].Dist0 = 0.5f*(float)rand()/RAND_MAX + 0.55f; lights[i].Angle0 = FLOAT_2PI*((float)rand()/RAND_MAX); lights[i].Height0 = FLOAT_2PI*(float)rand()/RAND_MAX; lights[i].Speed0 = 4.0f*(float)rand()/RAND_MAX - 2.0f; lights[i].Animation = (Light::AnimMode)(Light::ANIM_BOUNCE + (rand()%3)); lights[i].Radius = (float)rand()/RAND_MAX+0.05f; lights[i].Color[0] = (float)rand()/RAND_MAX; lights[i].Color[1] = (float)rand()/RAND_MAX; lights[i].Color[2] = (lights[i].Color[0]>lights[i].Color[1]) ? 1.0f-lights[i].Color[1] : 1.0f-lights[i].Color[0]; lights[i].Color[3] = 1; lights[i].Active = true; } // Initialize some OpenGL states glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LIGHTING); glEnable(GL_CULL_FACE); glEnable(GL_NORMALIZE); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); // Create objects display list using the current Subdiv parameter to control the tesselation if( objList>0 ) glDeleteLists(objList, 1); // delete previously created display list objList = glGenLists(1); glNewList(objList, GL_COMPILE); DrawSubdivCylinderY(-0.9f, 0, -0.9f, 1.4f, 0.15f, 0.12f, Subdiv/2+8, Subdiv); DrawSubdivCylinderY(+0.9f, 0, -0.9f, 1.4f, 0.15f, 0.12f, Subdiv/2+8, Subdiv); DrawSubdivCylinderY(+0.9f, 0, +0.9f, 1.4f, 0.15f, 0.12f, Subdiv/2+8, Subdiv); DrawSubdivCylinderY(-0.9f, 0, +0.9f, 1.4f, 0.15f, 0.12f, Subdiv/2+8, Subdiv); DrawSubdivCylinderY(0, 0, 0, 0.4f, 0.5f, 0.3f, Subdiv+16, Subdiv/8+1); DrawSubdivCylinderY(0, 0.4f, 0, 0.05f, 0.3f, 0.0f, Subdiv+16, Subdiv/16+1); glEndList(); // Create ground display list if( groundList>0 ) glDeleteLists(groundList, 1); // delete previously created display list groundList = glGenLists(1); glNewList(groundList, GL_COMPILE); DrawSubdivPlaneY(-1.2f, 1.2f, 0, -1.2f, 1.2f, (3*Subdiv)/2, (3*Subdiv)/2); glEndList(); // Create display list to draw light halos if( haloList>0 ) glDeleteLists(haloList, 1); // delete previously created display list haloList = glGenLists(1); glNewList(haloList, GL_COMPILE); DrawSubdivHaloZ(0, 0, 0, 1, 32); glEndList(); }
int main(int argc, char *argv[]) { TwBar *bar; float axis[] = { 0.7f, 0.7f, 0.0f }; float angle = 0.8f; winW = 640; winH = 480; glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(640, 480); glutCreateWindow("Assignment3- Skinning"); glutCreateMenu(NULL); glutDisplayFunc(Display); glutReshapeFunc(Reshape); atexit(Terminate); TwInit(TW_OPENGL, NULL); glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT); glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT); glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT); TwGLUTModifiersFunc(glutGetModifiers); //Todo Matrices identity; skeletonWasp = new Skeleton("wasp_walk.skel"); skinningWasp = new skin("wasp_walk.skin", skeletonWasp->worldMatrixes); animation = new Animation("wasp_walk.anim", skeletonWasp->joints); skeletonWasp->calculate(identity.IDENTITY); skinningWasp->update(); bar = TwNewBar("TweakBar"); TwDefine(" GLOBAL help='This is rotate and zoom the skeleton also to change the lighting effects' "); TwDefine(" TweakBar size='200 400' color='96 216 224' "); TwAddButton(bar, "Reset", ResetValues, NULL, " label='Resets the View' "); TwAddButton(bar, "Animate", StartAnimation, NULL, " label='Starts the animation' "); TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom, " min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' "); TwAddVarRW(bar, "ObjRotation", TW_TYPE_QUAT4F, &g_Rotation, " label='Object rotation' opened=true help='Change the object orientation.' "); TwAddVarCB(bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL, " label='Auto-rotate' key=space help='Toggle auto-rotate mode.' "); TwAddVarRW(bar, "Multiplier", TW_TYPE_FLOAT, &g_LightMultiplier, " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' "); TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3F, &g_LightDirection, " label='Light direction' opened=true help='Change the light direction.' "); TwAddVarRW(bar, "LightDir2", TW_TYPE_DIR3F, &g_LightDirection2, " label='Light direction' opened=true help='Change the light direction.' "); TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &g_MatAmbient1, " group='Material' "); TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &g_MatDiffuse1, " group='Material' "); { TwEnumVal shapeEV[NUM_SHAPES] = { { WASP, "Wasp" } }; TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES); TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, " keyIncr='<' keyDecr='>' help='Change object shape.' "); } g_RotateTime = GetTimeMs(); SetQuaternionFromAxisAngle(axis, angle, g_Rotation); SetQuaternionFromAxisAngle(axis, angle, g_RotateStart); CreateBar(); glutMainLoop(); return 0; }
CPaletteWindow::CPaletteWindow(CDocumentWindow* owner, const char* name, RECT rect, bool visible) { m_Owner = owner; #ifdef USE_SIZECBAR m_Name = name; m_pBarParent = NULL; m_PaletteNumber = (owner) ? owner->GetNumPalettes() : -1; #endif DWORD styles; #ifndef USE_SIZECBAR styles = WS_THICKFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_CLIPCHILDREN; if (visible) styles |= WS_VISIBLE; #else styles = WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN; #endif if (owner) { owner->AttachPalette(this); } // make sure the palette is visible! if (rect.right <= rect.left || rect.bottom <= rect.top || rect.left < 0 || rect.top < 0 || rect.left >= GetSystemMetrics(SM_CXSCREEN) - 1 || rect.top >= GetSystemMetrics(SM_CYSCREEN) - 1) { rect.left = 64; rect.top = 64; rect.right = 256; rect.bottom = 256; } // !!!! // for now, all palettes are shown by default // change this in the future #ifdef USE_SIZECBAR CreateBar(true); Create( AfxRegisterWndClass( 0, ::LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)) ), name, styles, rect, m_pBarParent, 0 ); #else Create( AfxRegisterWndClass( 0, ::LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)) ), name, styles, rect, AfxGetApp()->m_pMainWnd, 0 ); if (visible) { ShowWindow(SW_SHOW); } #endif }
void Init(){ for (int i = 0; i < 50; i++){ Gesture_ g; g_gestureManager.gestures.push_back(g); } DBConnect(); DBLoadAllGestures(); loadFTable(); // Initialise GLFW if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); exit(1); } glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Open a window and create its OpenGL context if (!glfwOpenWindow(1050, 690, 0, 0, 0, 0, 32, 0, GLFW_WINDOW)) { fprintf(stderr, "Failed to open GLFW window.\n"); glfwTerminate(); exit(1); } // Initialize GLEW glewExperimental = true; // Needed for core profile if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); exit(1); } glfwSetWindowTitle("Gesture Recognition"); glfwDisable(GLFW_STICKY_KEYS); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); // Init AntTweakBar if (!TwInit(TW_OPENGL_CORE, NULL)){ fprintf(stderr, "Failed to initialize AntTweakBar\n"); exit(1); } TwWindowSize(1050, 690); CreateBar(); //leap init if (g_leapController.isConnected()) { if (!g_leapController.addListener(g_leapListener)) std::cout << "Leap controller isnt accepting the listener" << std::endl; } else std::cout << "Leap controller isnt connected" << std::endl; }