コード例 #1
0
ファイル: controller.cpp プロジェクト: dianagudu/SWE
/**
    Process single keyboard event
	@param *keysym			pointer to the sdl keyevent structure

*/	
bool Controller::handleKeyPress( SDL_keysym *keysym) {

	switch ( keysym->sym ) {
		case SDLK_ESCAPE:
			// ESC key was pressed -> exit
			return true;
			break;
		case SDLK_r:
			// Restart simulation
			allowStep = paused;
			simulation->restart();
			break;
		case SDLK_w:
			// Switch rendering mode
			visualization->toggleRenderingMode();
			break;
		case SDLK_s:
			// Save simulation data to file
			simulation->saveToFile();
			break;
		case SDLK_RIGHT:
			// Advance single timestep when paused
			allowStep = paused;
			break;
		case SDLK_SPACE:
			// Pause/Resume
			paused = !paused;
			break;
		case SDLK_1:
			// Load scenario 1
			{
			  allowStep = paused;
                          SWE_RadialDamBreakScenarioVisInfo* 
                            newScene = new SWE_RadialDamBreakScenarioVisInfo();
			  SWE_VisInfo* visInfo = newScene;

			  // define grid size and initial time step
			  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
			  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
			  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

			  simulation->loadNewScenario(newScene, visInfo);
			  visualization->updateBathymetryVBO(simulation);
			}
			break;
		case SDLK_2:
			// Load scenario 2
			{
			  allowStep = paused;
			  SWE_Scenario* newScene = new SWE_BathymetryDamBreakScenario;
			  // define grid size and initial time step
			  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
			  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
			  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

			  simulation->loadNewScenario(newScene, NULL);
			  visualization->updateBathymetryVBO(simulation);
			}
			break;
		case SDLK_3:
			// Load scenario 3
			{
			  allowStep = paused;
			  SWE_SplashingPoolScenarioVisInfo* 
                            newScene = new SWE_SplashingPoolScenarioVisInfo;

			  // define grid size and initial time step
			  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
			  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
			  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

			  simulation->loadNewScenario(newScene, newScene);
			  visualization->updateBathymetryVBO(simulation);
			}
			break;
		default:
			break;
	}
	return false;
}
コード例 #2
0
/**
    Process single keyboard event
	@param *keysym			pointer to the sdl keyevent structure

	@todo Refector!!

*/	
bool Controller::handleKeyPress( SDL_keysym *keysym) {

	switch ( keysym->sym ) {
		case SDLK_ESCAPE:
			// ESC key was pressed -> exit
			return true;
			break;
		case SDLK_r:
			// Restart simulation
			allowStep = paused;
			simulation->restart();
			break;
		case SDLK_w:
			// Switch rendering mode
			visualization->toggleRenderingMode();
			break;
		case SDLK_s:
			// Save simulation data to file
			simulation->saveToFile();
			break;
		case SDLK_RIGHT:
			// Advance single timestep when paused
			allowStep = paused;
			break;
		case SDLK_SPACE:
			// Pause/Resume
			paused = !paused;
			break;
		case SDLK_PLUS:
			// Increase water scaling
			visualization->modifyWaterScaling(1.5);
			break;
		case SDLK_MINUS:
			// Decrease water scaling
			visualization->modifyWaterScaling(1/1.5);
			break;
		case SDLK_1:
			// Load scenario 1
			{
			  allowStep = paused;

			  if (scenarios[0] == 0)
				  scenarios[0] = new SWE_RadialDamBreakScenario;

			  SWE_Scenario* newScene = scenarios[0];

			  // define grid size and initial time step
			  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
			  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
			  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

			  simulation->loadNewScenario(newScene);
			  visualization->init(*simulation);
			}
			break;
		case SDLK_2:
			// Load scenario 2
			{
			  allowStep = paused;

			  if (scenarios[1] == 0) {
				  scenarios[1] = new SWE_BathymetryDamBreakScenario();
				  visInfos[1] = new SWE_BathymetryDamBreakVisInfo();
			  }

			  SWE_Scenario* newScene = scenarios[1];

			  // define grid size and initial time step
			  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
			  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
			  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

			  simulation->loadNewScenario(newScene);
			  visualization->init(*simulation, visInfos[1]);
			}
			break;
		case SDLK_3:
			// Load scenario 3
			{
			  allowStep = paused;

			  if (scenarios[2] == 0)
				  scenarios[2] = new SWE_SplashingPoolScenario();

			  SWE_Scenario* newScene = scenarios[2];

			  // define grid size and initial time step
			  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
			  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
			  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

			  simulation->loadNewScenario(newScene);
			  visualization->init(*simulation);
			}
			break;
#ifdef ASAGI
		case SDLK_4:
			// Load scenario 4
			{
				allowStep = paused;

				if (scenarios[3] == 0) {
					//simulation area
					float simulationArea[4];
					simulationArea[0] = -450000;
					simulationArea[1] = 6450000;
					simulationArea[2] = -2450000;
					simulationArea[3] = 1450000;
					scenarios[3] = new SWE_AsagiScenario(
							ASAGI_INPUT_DIR "tohoku_gebco_ucsb3_500m_hawaii_bath.nc",
				            ASAGI_INPUT_DIR "tohoku_gebco_ucsb3_500m_hawaii_displ.nc",
				            (float) 28800., simulationArea);
				}

				SWE_Scenario* newScene = scenarios[3];

				  // define grid size and initial time step
				  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
				  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
				  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

				  simulation->loadNewScenario(newScene);
				  visualization->init(*simulation);
			}
			break;
		case SDLK_5:
			// Load scenario 5
			{
				allowStep = paused;

				if (scenarios[4] == 0) {
					//simulation area
					float simulationArea[4];
					simulationArea[0] = -450000;
					simulationArea[1] = 700000;
					simulationArea[2] = -1000000;
					simulationArea[3] = 1450000;
					scenarios[4] = new SWE_AsagiScenario(
							ASAGI_INPUT_DIR "tohoku_gebco_ucsb3_500m_hawaii_bath.nc",
				            ASAGI_INPUT_DIR "tohoku_gebco_ucsb3_500m_hawaii_displ.nc",
				            (float) 28800., simulationArea);

					visInfos[4] = new SWE_AsagiJapanSmallVisInfo();
				}

				SWE_Scenario* newScene = scenarios[4];

				  // define grid size and initial time step
				  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
				  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
				  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

				  simulation->loadNewScenario(newScene);
				  visualization->init(*simulation, visInfos[4]);
			}
			break;
		case SDLK_6:
			// Load scenario 6
			{
				allowStep = paused;

				if (scenarios[5] == 0) {
					//simulation area
					float simulationArea[4];
					simulationArea[0] = -13775000;
					simulationArea[1] = 1655000;
					simulationArea[2] = -2765000;
					simulationArea[3] = 8870000;
					scenarios[5] = new SWE_AsagiScenario(
							ASAGI_INPUT_DIR "chile_gebco_usgs_500m_bath.nc",
				            ASAGI_INPUT_DIR "chile_gebco_usgs_500m_displ.nc",
				            (float) 28800., simulationArea);
				}

				SWE_Scenario* newScene = scenarios[5];

				  // define grid size and initial time step
				  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
				  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
				  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

				  simulation->loadNewScenario(newScene);
				  visualization->init(*simulation);
			}
			break;
		case SDLK_7:
			// Load scenario 7
			{
				allowStep = paused;

				if (scenarios[6] == 0) {
					//simulation area
					float simulationArea[4];
					simulationArea[0] = -2275000;
					simulationArea[1] = 1655000;
					simulationArea[2] = -2265000;
					simulationArea[3] = 1870000;
					scenarios[6] = new SWE_AsagiScenario(
							ASAGI_INPUT_DIR "chile_gebco_usgs_500m_bath.nc",
				            ASAGI_INPUT_DIR "chile_gebco_usgs_500m_displ.nc",
				            (float) 28800., simulationArea);
				}

				SWE_Scenario* newScene = scenarios[6];

				  // define grid size and initial time step
				  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
				  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
				  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

				  simulation->loadNewScenario(newScene);
				  visualization->init(*simulation);
			}
			break;
#endif // ASAGI
		default:
			break;
	}
	return false;
}