// Helper function to loop through different modes //***************************************************************************** void ResetSim(int iOption) { if((iOption < 1) || (iOption > 4))return; switch (iOption) { case 1: psystem->reset(ParticleSystem::CONFIG_GRID); break; case 2: psystem->reset(ParticleSystem::CONFIG_RANDOM); break; case 3: addSphere(); break; case 4: { // shoot ball from camera float pr = psystem->getParticleRadius(); float vel[4], velw[4], pos[4], posw[4]; vel[0] = 0.0f; vel[1] = 0.0f; vel[2] = fShootVelocity; vel[3] = 0.0f; ixform(vel, velw, modelView); pos[0] = 0.0f; pos[1] = 0.0f; pos[2] = -2.5f; pos[3] = 1.0; ixformPoint(pos, posw, modelView); posw[3] = 0.0f; psystem->addSphere(0, posw, velw, ballr, pr * 2.0f); } break; } }
// commented out to remove unused parameter warnings in Linux void key(unsigned char key, int /*x*/, int /*y*/) { #ifndef BT_NO_PROFILE if (key >= 0x31 && key < 0x37) { int child = key-0x31; renderer->m_profileIterator->Enter_Child(child); } if (key==0x30) { renderer->m_profileIterator->Enter_Parent(); } #endif //BT_NO_PROFILE switch (key) { case ' ': bPause = !bPause; break; case 13: psystem->update(timestep); renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles()); break; case '\033': case 'q': exit(0); break; case 'v': mode = M_VIEW; break; case 'm': mode = M_MOVE; break; case 'p': displayMode = (ParticleRenderer::DisplayMode) ((displayMode + 1) % ParticleRenderer::PARTICLE_NUM_MODES); break; case 'd': psystem->dumpGrid(); break; case 'u': psystem->dumpParticles(0, 1); break; case 'r': displayEnabled = !displayEnabled; break; case 'g': psystem->reset(ParticleSystem::CONFIG_GRID); break; case 'a': psystem->reset(ParticleSystem::CONFIG_RANDOM); break; case 'e': { // inject a sphere of particles float pr = psystem->getParticleRadius(); float tr = pr+(pr*2.0f)*ballr; float pos[4], vel[4]; pos[0] = -1.0 + tr + frand()*(2.0f - tr*2.0f); pos[1] = 1.0f - tr; pos[2] = -1.0 + tr + frand()*(2.0f - tr*2.0f); pos[3] = 0.0f; vel[0] = vel[1] = vel[2] = vel[3] = 0.0f; psystem->addSphere(0, pos, vel, ballr, pr*2.0f); } break; case 'b': { // shoot ball from camera float pr = psystem->getParticleRadius(); float vel[4], velw[4], pos[4], posw[4]; vel[0] = 0.0f; vel[1] = 0.0f; vel[2] = -0.05f; vel[3] = 0.0f; ixform(vel, velw, modelView); pos[0] = 0.0f; pos[1] = 0.0f; pos[2] = -2.5f; pos[3] = 1.0; ixformPoint(pos, posw, modelView); posw[3] = 0.0f; psystem->addSphere(0, posw, velw, ballr, pr*2.0f); } break; case 'w': wireframe = !wireframe; break; case 'h': displaySliders = !displaySliders; break; case 's': psystem->setSimulationMode((ParticleSystem::SimulationMode) ((psystem->getSimulationMode() + 1) % ParticleSystem::SIMULATION_NUM_MODES)); CProfileManager::CleanupMemory(); break; } glutPostRedisplay(); }
// commented out to remove unused parameter warnings in Linux void key(unsigned char key, int /*x*/, int /*y*/) { switch (key) { case ' ': bPause = !bPause; break; case 13: psystem->update(timestep); if (renderer) { renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles()); } break; case '\033': case 'q': #if defined(__APPLE__) || defined(MACOSX) exit(EXIT_SUCCESS); #else glutDestroyWindow(glutGetWindow()); return; #endif case 'v': mode = M_VIEW; break; case 'm': mode = M_MOVE; break; case 'p': displayMode = (ParticleRenderer::DisplayMode) ((displayMode + 1) % ParticleRenderer::PARTICLE_NUM_MODES); break; case 'd': psystem->dumpGrid(); break; case 'u': psystem->dumpParticles(0, numParticles-1); break; case 'r': displayEnabled = !displayEnabled; break; case '1': psystem->reset(ParticleSystem::CONFIG_GRID); break; case '2': psystem->reset(ParticleSystem::CONFIG_RANDOM); break; case '3': addSphere(); break; case '4': { // shoot ball from camera float pr = psystem->getParticleRadius(); float vel[4], velw[4], pos[4], posw[4]; vel[0] = 0.0f; vel[1] = 0.0f; vel[2] = -0.05f; vel[3] = 0.0f; ixform(vel, velw, modelView); pos[0] = 0.0f; pos[1] = 0.0f; pos[2] = -2.5f; pos[3] = 1.0; ixformPoint(pos, posw, modelView); posw[3] = 0.0f; psystem->addSphere(0, posw, velw, ballr, pr*2.0f); } break; case 'w': wireframe = !wireframe; break; case 'h': displaySliders = !displaySliders; break; } demoMode = false; idleCounter = 0; glutPostRedisplay(); }
// commented out to remove unused parameter warnings in Linux void key(unsigned char key, int /*x*/, int /*y*/) { switch (key) { case ' ': bPause = !bPause; break; case 13: psystem->update(timestep); renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles()); break; case '\033': case 'q': exit(0); break; case 'v': mode = M_VIEW; break; case 'm': mode = M_MOVE; break; case 'p': displayMode = (ParticleRenderer::DisplayMode) ((displayMode + 1) % ParticleRenderer::PARTICLE_NUM_MODES); break; case 'd': psystem->dumpGrid(); break; case 'u': psystem->dumpParticles(0, 1); break; case 'r': displayEnabled = !displayEnabled; break; case '1': psystem->reset(ParticleSystem::CONFIG_GRID); break; case '2': psystem->reset(ParticleSystem::CONFIG_RANDOM); break; case '3': { // inject a sphere of particles float pr = psystem->getParticleRadius(); float tr = pr+(pr*2.0f)*ballr; float pos[4], vel[4]; pos[0] = -1.0 + tr + frand()*(2.0f - tr*2.0f); pos[1] = 1.0f - tr; pos[2] = -1.0 + tr + frand()*(2.0f - tr*2.0f); pos[3] = 0.0f; vel[0] = vel[1] = vel[2] = vel[3] = 0.0f; psystem->addSphere(0, pos, vel, ballr, pr*2.0f); } break; case '4': { // shoot ball from camera float pr = psystem->getParticleRadius(); float vel[4], velw[4], pos[4], posw[4]; vel[0] = 0.0f; vel[1] = 0.0f; vel[2] = -0.05f; vel[3] = 0.0f; ixform(vel, velw, modelView); pos[0] = 0.0f; pos[1] = 0.0f; pos[2] = -2.5f; pos[3] = 1.0; ixformPoint(pos, posw, modelView); posw[3] = 0.0f; psystem->addSphere(0, posw, velw, ballr, pr*2.0f); } break; case 'w': wireframe = !wireframe; break; case 'h': displaySliders = !displaySliders; break; } glutPostRedisplay(); }
// commented out to remove unused parameter warnings in Linux void key(unsigned char key, int /*x*/, int /*y*/) { switch (key) { case ' ': bPause = !bPause; break; case 13: psystem->update(timestep); if (renderer) { renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles()); } break; case '\033': case 'q': // cudaDeviceReset causes the driver to clean up all state. While // not mandatory in normal operation, it is good practice. It is also // needed to ensure correct operation when the application is being // profiled. Calling cudaDeviceReset causes all profile data to be // flushed before the application exits cudaDeviceReset(); exit(EXIT_SUCCESS); break; case 'v': mode = M_VIEW; break; case 'm': mode = M_MOVE; break; case 'p': displayMode = (ParticleRenderer::DisplayMode) ((displayMode + 1) % ParticleRenderer::PARTICLE_NUM_MODES); break; case 'd': psystem->dumpGrid(); break; case 'u': psystem->dumpParticles(0, numParticles-1); break; case 'r': displayEnabled = !displayEnabled; break; case '1': psystem->reset(ParticleSystem::CONFIG_GRID); break; case '2': psystem->reset(ParticleSystem::CONFIG_RANDOM); break; case '3': addSphere(); break; case '4': { // shoot ball from camera float pr = psystem->getParticleRadius(); float vel[4], velw[4], pos[4], posw[4]; vel[0] = 0.0f; vel[1] = 0.0f; vel[2] = -0.05f; vel[3] = 0.0f; ixform(vel, velw, modelView); pos[0] = 0.0f; pos[1] = 0.0f; pos[2] = -2.5f; pos[3] = 1.0; ixformPoint(pos, posw, modelView); posw[3] = 0.0f; psystem->addSphere(0, posw, velw, ballr, pr*2.0f); } break; case 'w': wireframe = !wireframe; break; case 'h': displaySliders = !displaySliders; break; } demoMode = false; idleCounter = 0; glutPostRedisplay(); }