Пример #1
0
 void EventManager::cancelAllEvents()
 {
     eventList::iterator it(m_events.begin());
     for(; it != m_events.end(); ++it) {
         if(it->getState() == kFZEventState_Began || it->getState() == kFZEventState_Updated)
         {
             Event event = Event(it->getOwner(), it->getIdentifier(),
                                 it->getType(), kFZEventState_Cancelled,
                                 it->m_x, it->m_y, it->m_z);
             
             catchEvent(event);
         }
     }
 }
Пример #2
0
int Example::run()
{
  // Init window with opengl context
  sf::ContextSettings context;
  context.depthBits = 24;
  context.stencilBits = 24;
  context.antialiasingLevel = 2;
  context.majorVersion = 3;
  context.minorVersion = 3;

  _window = new sf::Window(sf::VideoMode(_winWidth, _winHeight, 32), _name,
			   sf::Style::Default, context);

  // Print OpenGL supported version
  context = _window->getSettings();
  std::cout << context.majorVersion << '.'
            << context.minorVersion << std::endl;

  _window->setActive();

  initScene();

  if (_cameraType == Flycam)
    _window->setMouseCursorVisible(false);

  while (_window->isOpen())
    {
      _elapsedTime = _time.getElapsedTime().asMilliseconds();

      sf::Event event;
      while (_window->pollEvent(event))
        {
          // Close window : exit
          if (event.type == sf::Event::Closed)
            _window->close();
          else if (event.type == sf::Event::KeyPressed
                   && event.key.code == sf::Keyboard::Escape)
            _window->close();
          // Adjust the viewport when the window is resized
          if (event.type == sf::Event::Resized)
	    {
	      _winWidth = event.size.width;
	      _winHeight = event.size.height;
	      glViewport(0, 0, _winWidth, _winHeight);
	    }
	  if (_cameraType == Flycam)
	    flycam::event(event, *_window);
	  if (_cameraType == Trackball)
	    trackball::event(event, *_window);
	  catchEvent(event);
        }

      if (!_window->isOpen())
	continue ;

      if (_cameraType == Flycam)
	{
	  sf::Mouse::setPosition(sf::Vector2i(_winWidth/2, _winHeight/2), *_window);
	  flycam::flycam(_camera);
	}
      else if (_cameraType == Trackball)
	trackball::trackball(_camera);

      animate();
      render();

      _window->display();
      if (_recordVideo)
	video::saveImage(*_window, _framerate);

      if (_showFramerate)
	fps::print();
      if (_limitFramerate)
	fps::limit(_framerate);
    }  

  if (_recordVideo)
    {
      std::string filename = _name;
      std::replace(filename.begin(), filename.end(), ' ', '_');
      std::replace(filename.begin(), filename.end(), ':', '_');
      std::replace(filename.begin(), filename.end(), '-', '_');
      video::save(filename, _framerate);
    }

  return (0);
}