Calc::Calc(const Config& config) : _scale(config["calc.scale"].as<double>()), _nx(config["output.width"].as<size_t>()), _ny(config["output.height"].as<size_t>()), _width(config["crop.width"].as<size_t>()), _height(config["crop.height"].as<size_t>()) { const size_t window_size = config["calc.window_size"].as<size_t>() | 1; _window_size = cv::Size(window_size, window_size); // Init background image cv::Rect ROI(config["crop.xmin"].as<size_t>(), config["crop.ymin"].as<size_t>(), config["crop.width"].as<size_t>(), config["crop.height"].as<size_t>()); if (config.count("input.background")) { _background = cv::imread(config["input.background"].as<std::string>(), CV_LOAD_IMAGE_GRAYSCALE); if (_background.size() != ROI.size()) { _background = _background(ROI); } } else { _background = cv::Mat::ones(ROI.size(), CV_8UC1) * 255; } // Init matrices const int dims[] = { _ny, _nx, 2 }; _out.density.create(_height, _width, CV_8U); _out.velocity.create(3, dims, CV_32F); _out.mask.create(2, dims, CV_8U); }
virtual void _updateBackground(gfx::Engine&, bool&) { _background().destroy(); Pictures pics; Decorator::draw( pics, Rect( Point(), size() ), style ); Picture emlbPic( gui::rc.panel, config::id.empire.stamp ); pics.append( emlbPic, Point( 4, 2 ) ); pics.append( emlbPic, Point( width() - emlbPic.width()-4, 2 ) ); bool batchOk = _background().load( pics, absoluteRect().lefttop() ); if( !batchOk ) { _background().destroy(); Decorator::reverseYoffset( pics ); _backgroundNb() = pics; } }
int main() { std::map<std::string, std::string> _texts = std::map<std::string, std::string>(); std::vector<GameObject*> _gameObjects = std::vector<GameObject*>(); sf::RenderWindow window(sf::VideoMode(800, 600), "Collision test"); /* sf::Texture _bkg; _bkg.loadFromFile("gorge.jpg"); _bkg.setRepeated(true); sf::Sprite _background(_bkg, sf::IntRect(0, 0, 2000, 1000)); */ if(load("Brown_Rocks.png", sf::Vector2u(32, 32), nullptr, 800, 600)) std::cout << "YEAH\n"; sf::Texture _bkg; _bkg.loadFromFile("Brown_Rocks.png"); _bkg.setRepeated(true); sf::Sprite _background(_bkg, sf::IntRect(0, 0, 2000, 1000)); std::cout << sf::Texture::getMaximumSize() << "\n"; sf::Texture _cliffsTexture; _cliffsTexture.loadFromFile("Cliffs.png"); _cliffsTexture.setRepeated(true); sf::Sprite _cliffsBottom(_cliffsTexture); sf::Sprite _cliffsTop(_cliffsTexture, sf::IntRect(0, 400, 800, -800)); _cliffsTop.setPosition(-300, 0); std::cout << _cliffsTexture.getSize().x << "," << _cliffsTexture.getSize().y; sf::Texture _platformTexture; _platformTexture.loadFromFile("Rocks_Platform1.png"); _platformTexture.setRepeated(true); sf::Sprite _platform(_platformTexture, sf::IntRect(0, 0, 2000, 32)); _platform.setPosition(0, window.getSize().y - 32); sf::Sprite _platformBottom(_platformTexture, sf::IntRect(0, 32, 2000, -32)); _platformBottom.setPosition(0, 0); sf::Texture texture; texture.loadFromFile("plane.png"); //texture.loadFromFile("player.png"); GameObject _player(texture); _player.setPosition(window.getSize().x / 2.f - 300, window.getSize().y / 2.f - 75); _gameObjects.push_back(&_player); sf::Texture etexture; etexture.loadFromFile("plane.png"); //sf::IntRect textRect(64, 0, -64, 32); //GameObject _enemy(etexture, textRect); GameObject _enemy(etexture); _enemy.setPosition(window.getSize().x / 2.f + 75, window.getSize().y / 2.f - 16); _gameObjects.push_back(&_enemy); sf::RectangleShape _bounding1(sf::Vector2f(_player.getBoundingBox().width - 1, _player.getBoundingBox().height - 1)); _bounding1.setPosition(_player.getPosition()); _bounding1.setFillColor(sf::Color::Transparent); _bounding1.setOutlineColor(sf::Color::Red); _bounding1.setOutlineThickness(1); sf::RectangleShape _bounding2(sf::Vector2f(_enemy.getBoundingBox().width - 1, _enemy.getBoundingBox().height - 1)); _bounding2.setPosition(_enemy.getPosition()); _bounding2.setFillColor(sf::Color::Transparent); _bounding2.setOutlineColor(sf::Color::Red); _bounding2.setOutlineThickness(1); sf::Font font; font.loadFromFile("VeraMono.ttf"); sf::Text _text("Debug", font, 12); _text.setPosition(0, 0); sf::Clock clock; sf::Time timeSinceLastUpdate = sf::Time::Zero; // Start the game loop while (window.isOpen()) { sf::Time elapsedTime = clock.restart(); timeSinceLastUpdate += elapsedTime; while (timeSinceLastUpdate > TimePerFrame) { timeSinceLastUpdate -= TimePerFrame; // Process events sf::Event event; while (window.pollEvent(event)) { // Close window : exit if (event.type == sf::Event::Closed) window.close(); if(event.type == sf::Event::KeyPressed) { short id = 1; for( auto& i : _gameObjects ) { i->update(event, id); id++; } } } if(checkCollisions(_gameObjects, _texts)) _texts["Collision"] = "Detected"; else _texts["Collision"] = "NOT Detected"; std::map<std::string, std::string>::iterator i = _texts.begin(); std::stringstream ss; for( ; i != _texts.end(); ++i ) { ss << i->first << ": " << i->second << std::endl << std::endl; } _text.setString(ss.str()); } _bounding1.setPosition(_player.getPosition()); _bounding2.setPosition(_enemy.getPosition()); _statisticsUpdateTime += elapsedTime; _statisticsNumFrames += 1; if (_statisticsUpdateTime >= sf::seconds(1.0f)) { std::stringstream fps, timeupdate; fps << _statisticsNumFrames; timeupdate << _statisticsUpdateTime.asMicroseconds() / _statisticsNumFrames; _statisticsUpdateTime -= sf::seconds(1.0f); _statisticsNumFrames = 0; _texts["FPS"] = fps.str() + "\n" + "Time / Update = " + timeupdate.str() + "us"; } window.clear(); window.draw(_background); // window.draw(m_vertices, &m_tileset); window.draw(_cliffsBottom); window.draw(_cliffsTop); window.draw(_platform); window.draw(_platformBottom); for( auto& i : _gameObjects ) { window.draw(*i); } window.draw(_text); window.draw(_bounding1); window.draw(_bounding2); window.display(); } }