// Keyboard events handler
//*****************************************************************************
void KeyboardGL(unsigned char key, int x, int y)
{
    switch(key) 
    {
        case 'P':   // P toggles Processing between CPU and GPU
        case 'p':   // p toggles Processing between CPU and GPU
            if (iProcFlag == 0)
            {
                iProcFlag = 1;
            }
            else 
            {
                iProcFlag = 0;
            }
            shrLog("\n%s Processing...\n", cProcessor[iProcFlag]);
            break;
        case ' ':   // space bar toggles processing on and off
            bPostprocess = !bPostprocess;
            shrLog("\nPostprocessing (Blur Filter) Toggled %s...\n", bPostprocess ? "ON" : "OFF");
            break;
        case 'A':   // 'A' toggles animation (spinning of teacup) on/off  
        case 'a':   // 'a' toggles animation (spinning of teacup) on/off 
            bAnimate = !bAnimate;
            shrLog("\nGL Animation (Rotation) Toggled %s...\n", bAnimate ? "ON" : "OFF");
            break;
        case '=':
        case '+':
            if (blur_radius < 16) blur_radius++;
            shrLog("\nBlur radius = %d\n", blur_radius);
            break;
        case '-':
        case '_':
            if (blur_radius > 1) blur_radius--;
            shrLog("\nBlur radius = %d\n", blur_radius);
            break;
        case '\033': // escape quits
        case '\015': // Enter quits    
        case 'Q':    // Q quits
        case 'q':    // q (or escape) quits
            // Cleanup then quit (without prompting)
            bNoPrompt = shrTRUE;
            Cleanup(EXIT_SUCCESS);
            break;
    }

    // Trigger fps update and call for refresh
    TriggerFPSUpdate();
    glutPostRedisplay();
}
Ejemplo n.º 2
0
// GLUT key event handler
// params commented out to remove unused parameter warnings in Linux
//*****************************************************************************
void KeyboardGL(unsigned char key, int /*x*/, int /*y*/)
{
    switch (key) 
    {
    case ' ':   // toggle pause in simulation computations
        bPause = !bPause;
        shrLog("\nSimulation %s...\n", bPause ? "Paused" : "Running");
        break;
    case 13:
        psystem->update(timestep); 
        renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles());
        break;
    case '\033':// Escape quits    
    case 'Q':   // Q quits
    case 'q':   // q quits
		bNoPrompt = shrTRUE;
        shrQAFinish2(false, *pArgc, (const char **)pArgv, QA_PASSED);
        Cleanup(EXIT_SUCCESS);
        break;
    case 'T':   // Toggles from (T)our mode to standard mode and back
    case 't':   // Toggles from (t)our mode to standard mode and back
        bTour = bTour ? shrFALSE : shrTRUE;
        shrLog("\nTour Mode %s...\n", bTour ? "ON" : "OFF");
        break;
    case 'F':   // F toggles main graphics display full screen
    case 'f':   // f toggles main graphics display full screen
        bFullScreen = !bFullScreen;
        if (bFullScreen)
        {
            iGraphicsWinPosX = glutGet(GLUT_WINDOW_X) - 8;
            iGraphicsWinPosY = glutGet(GLUT_WINDOW_Y) - 30;
            iGraphicsWinWidth  = min(glutGet(GLUT_WINDOW_WIDTH) , glutGet(GLUT_SCREEN_WIDTH) - 2*iGraphicsWinPosX ); 
            iGraphicsWinHeight = min(glutGet(GLUT_WINDOW_HEIGHT), glutGet(GLUT_SCREEN_HEIGHT)- 2*iGraphicsWinPosY ); 
            printf("(x,y)=(%d,%d), (w,h)=(%d,%d)\n", iGraphicsWinPosX, iGraphicsWinPosY, iGraphicsWinWidth, iGraphicsWinHeight);
            glutFullScreen();
        }
        else
        {
            glutPositionWindow(iGraphicsWinPosX, iGraphicsWinPosY);
            glutReshapeWindow(iGraphicsWinWidth, iGraphicsWinHeight);
        }
        shrLog("\nMain Graphics %s...\n", bFullScreen ? "FullScreen" : "Windowed");
        break;
    case 'V':
    case 'v':
        if (M_VIEW != mode)
        {
            shrLog("\nMouse View Mode...\n");
            mode = M_VIEW;
        }
        break;
    case 'M':
    case 'm':
        if (M_MOVE != mode)
        {
            shrLog("\nMouse Move Mode...\n");
            mode = M_MOVE;
        }
        break;
    case 'P':
    case 'p':
        displayMode = (ParticleRenderer::DisplayMode)
                      ((displayMode + 1) % ParticleRenderer::PARTICLE_NUM_MODES);
        break;
    case 'D':
    case 'd':
        psystem->dumpGrid();
        break;
    case 'U':
    case 'u':
        break;
    case 'R':
    case 'r':
        displayEnabled = !displayEnabled;
        break;
    case '1':
        ResetSim(1);
        break;
    case '2':
        ResetSim(2);
        break;
    case '3':
        ResetSim(3);
        break;
    case '4':
        ResetSim(4);
        break;
    case 'H':
    case 'h':
        displaySliders = !displaySliders;
        break;
    }

    // Trigger fps update and call for refresh
    TriggerFPSUpdate();
}
Ejemplo n.º 3
0
// GLUT key event handler
//*****************************************************************************
void KeyboardGL(unsigned char key, int /*x*/, int /*y*/)
{
    switch (key) 
    {
        case ' ': // space toggle computation flag on/off
            bPause = !bPause;
            shrLog("\nSim %s...\n\n", bPause ? "Paused" : "Running");
            break;
	    case 's':
        case 'S':   // Tilda toggles slider display
            bShowSliders = !bShowSliders;
            shrLog("\nSlider Display %s...\n\n", bShowSliders ? "ON" : "OFF");
            break;
        case 'p':   // 'p' falls through to 'P' 
        case 'P':   // p switched between points and blobs 
            displayMode = (ParticleRenderer::DisplayMode)((displayMode + 1) % ParticleRenderer::PARTICLE_NUM_MODES);
            break;
        case 'c':   // 'c' falls through to 'C'
        case 'C':   // c switches between cycle demo mode and fixed demo mode
            bTour = bTour ? shrFALSE : shrTRUE;
            shrLog("\nTour Mode %s...\n\n", bTour ? "ON" : "OFF");
            break;
        case '[':
            activeDemo = (activeDemo == 0) ? numDemos - 1 : (activeDemo - 1) % numDemos;
            SelectDemo(activeDemo);
            break;
        case ']':
            activeDemo = (activeDemo + 1) % numDemos;
            SelectDemo(activeDemo);
            break;
        case 'd':   // 'd' falls through to 'D'
        case 'D':   // d toggled main graphics display on/off
            displayEnabled = !displayEnabled;
            shrLog("\nMain Graphics Display %s...\n\n", displayEnabled ? "ON" : "OFF");
            break;
        case 'f':   // 'f' falls through to 'F'
        case 'F':   // f toggles main graphics display full screen
            bFullScreen = !bFullScreen;
            if (bFullScreen)
            {
                iGraphicsWinPosX = glutGet(GLUT_WINDOW_X) - 8;
                iGraphicsWinPosY = glutGet(GLUT_WINDOW_Y) - 30;
                iGraphicsWinWidth  = min(glutGet(GLUT_WINDOW_WIDTH) , glutGet(GLUT_SCREEN_WIDTH) - 2*iGraphicsWinPosX ); 
                iGraphicsWinHeight = min(glutGet(GLUT_WINDOW_HEIGHT), glutGet(GLUT_SCREEN_HEIGHT)- 2*iGraphicsWinPosY ); 
                printf("(x,y)=(%d,%d), (w,h)=(%d,%d)\n", iGraphicsWinPosX, iGraphicsWinPosY, iGraphicsWinWidth, iGraphicsWinHeight);
                glutFullScreen();
            }
            else
            {
                glutPositionWindow(iGraphicsWinPosX, iGraphicsWinPosY);
	            glutReshapeWindow(iGraphicsWinWidth, iGraphicsWinHeight);
            }
            shrLog("\nMain Graphics %s...\n\n", bFullScreen ? "FullScreen" : "Windowed");
            break;
        case 'o':   // 'o' falls through to 'O'
        case 'O':   // 'O' prints Nbody sim physical parameters
            activeParams.print();
            break;
        case 'T':   // Toggles from (T)our mode to standard mode and back
        case 't':   // Toggles from (t)our mode to standard mode and back
            bTour = bTour ? shrFALSE : shrTRUE;
            shrLog("\nTour Mode %s...\n", bTour ? "ON" : "OFF");
            break;
        case '1':
            ResetSim(nbody, numBodies, NBODY_CONFIG_SHELL, true);
            break;
        case '2':
            ResetSim(nbody, numBodies, NBODY_CONFIG_RANDOM, true);
            break;
        case '3':
            ResetSim(nbody, numBodies, NBODY_CONFIG_EXPAND, true);
            break;
        case '\033': // escape quits
        case '\015': // Enter quits    
        case 'Q':    // Q quits
        case 'q':    // q (or escape) quits
            // Cleanup and quit
            bNoPrompt = shrTRUE;
            shrQAFinish2(false, *pArgc, (const char **)pArgv, QA_PASSED);
            Cleanup(EXIT_SUCCESS);
            break;
    }

    // Trigger fps update and call for refresh
    TriggerFPSUpdate();
    glutPostRedisplay();
}
// Keyboard event handler callback
//*****************************************************************************
void KeyboardGL(unsigned char key, int /*x*/, int /*y*/)
{
    switch(key) 
    {
        case 'P':   // P toggles Processing between CPU and GPU
        case 'p':   // p toggles Processing between CPU and GPU
            if (iProcFlag == 0)
            {
                iProcFlag = 1;
            }
            else 
            {
                iProcFlag = 0;
            }
            shrLog("\n%s Processing...\n", cProcessor[iProcFlag]);
            break;
        case 'F':   // F toggles main graphics display full screen
        case 'f':   // f toggles main graphics display full screen
            bFullScreen = !bFullScreen;
            if (bFullScreen)
            {
                iGraphicsWinPosX = glutGet(GLUT_WINDOW_X) - 8;
                iGraphicsWinPosY = glutGet(GLUT_WINDOW_Y) - 30;
                iGraphicsWinWidth  = min(glutGet(GLUT_WINDOW_WIDTH) , glutGet(GLUT_SCREEN_WIDTH) - 2*iGraphicsWinPosX ); 
                iGraphicsWinHeight = min(glutGet(GLUT_WINDOW_HEIGHT), glutGet(GLUT_SCREEN_HEIGHT)- 2*iGraphicsWinPosY ); 
                printf("(x,y)=(%d,%d), (w,h)=(%d,%d)\n", iGraphicsWinPosX, iGraphicsWinPosY, iGraphicsWinWidth, iGraphicsWinHeight);
                glutFullScreen();
            }
            else
            {
                glutPositionWindow(iGraphicsWinPosX, iGraphicsWinPosY);
                glutReshapeWindow(iGraphicsWinWidth, iGraphicsWinHeight);
            }
            shrLog("\nMain Graphics %s...\n", bFullScreen ? "FullScreen" : "Windowed");
            break;
        case ' ':   // space bar toggles filter on and off
            bFilter = !bFilter;
            shrLog("\nSobel Filter Toggled %s...\n", bFilter ? "ON" : "OFF");
            break;
        case '+':   // + sign increases threshold
        case '=':   // = sign increases threshold
        case '-':   // - sign decreases threshold
        case '_':   // _ decreases threshold
            if(key == '+' || key == '=')
            {
                fThresh += 10.0f;
            }
            else
            {
                fThresh -= 10.0f;
            }

            // Clamp and reset the associated kernel arg, and log value
            fThresh = CLAMP(fThresh, 0.0f, 255.0f);
            for (cl_uint i = 0; i < GpuDevMngr->uiUsefulDevCt; i++)
            {
                ciErrNum = clSetKernelArg(ckSobel[i], 6, sizeof(cl_float), (void*)&fThresh);
            }
            oclCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup);
            shrLog("\nThreshold changed to %.1f...\n", fThresh);
            break;
        case '\033':// Escape quits    
        case '\015':// Enter quits    
        case 'Q':   // Q quits
        case 'q':   // q quits
            // Cleanup up and quit
            bNoPrompt = shrTRUE;
            Cleanup(EXIT_SUCCESS);
            break;
    }

    // Trigger fps update and call for refresh
    TriggerFPSUpdate();
}