当前位置: 首页>>代码示例>>C++>>正文


C++ RectangleShape::getOrigin方法代码示例

本文整理汇总了C++中sf::RectangleShape::getOrigin方法的典型用法代码示例。如果您正苦于以下问题:C++ RectangleShape::getOrigin方法的具体用法?C++ RectangleShape::getOrigin怎么用?C++ RectangleShape::getOrigin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sf::RectangleShape的用法示例。


在下文中一共展示了RectangleShape::getOrigin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: draw

	void draw() {
		// update the mouse position and add it to the broadphase
		auto mousePosition = static_cast<sf::Vector2f>(sf::Mouse::getPosition(window));
		const auto mouseSize = mouseObject.getSize();
		mouseObject.setPosition(mousePosition);
		mousePosition -= mouseObject.getOrigin();
		broadphase.addRectangle(
			mousePosition.x,
			mousePosition.y,
			mouseSize.x,
			mouseSize.y,
			&mouseObject);

		// move the rectangles around and add them to the broadphase
		for (const auto& object : objects) {
			object->setPosition(randb(0, window.getSize().x), randb(0,  window.getSize().y));
			const auto objectPosition = object->getPosition() - object->getOrigin();
			const auto objectSize = object->getSize();
			broadphase.addRectangle(
				objectPosition.x,
				objectPosition.y,
				objectSize.x,
				objectSize.y,
				object);

			object->setFillColor(sf::Color(0x00, 0x8B, 0x8B));
			object->setOutlineColor(sf::Color::White);
		}

		// now query the collision pairs and change the color of objects that hit the mouse object to red
		const auto &collisionPairs = broadphase.getCollisionPairs();
		for (const auto &pair : collisionPairs) {
			sf::RectangleShape *other = nullptr;
			if (pair.first == &mouseObject)
				other = (sf::RectangleShape*)pair.second;
			else if (pair.second == &mouseObject)
				other = (sf::RectangleShape*)pair.first;
			else {
				((sf::RectangleShape*)pair.first)->setOutlineColor(sf::Color::Cyan);
				((sf::RectangleShape*)pair.second)->setOutlineColor(sf::Color::Cyan);
			}
			if (other != nullptr)
				other->setFillColor(sf::Color(200, 0, 0));
		}

		// clear out the broadphase for the next run
		broadphase.clear();

		// clear the window with black color
		window.clear(sf::Color::Black);

		for (const auto& object : objects)
			window.draw(*object);

		window.draw(mouseObject);

		// draw a grid to outline the buckets
		const float lineThickness = 5;
		const sf::Color lineColor(150, 150, 150);
		sf::RectangleShape verticalLine(sf::Vector2f(lineThickness, window.getSize().y));
		verticalLine.setFillColor(lineColor);
		for (size_t i = 1; i < (window.getSize().x / broadphase.getCellWidth()); ++i) {
			verticalLine.setPosition(i * broadphase.getCellWidth(), 0);
			window.draw(verticalLine);
		}
		sf::RectangleShape horizontalLine(sf::Vector2f(window.getSize().x, lineThickness));
		horizontalLine.setFillColor(lineColor);
		for (size_t i = 1; i < (window.getSize().y / broadphase.getCellHeight()); ++i) {
			horizontalLine.setPosition(0, i * broadphase.getCellHeight());
			window.draw(horizontalLine);
		}
	}
开发者ID:fundies,项目名称:SAT,代码行数:72,代码来源:BroadphaseDemo.hpp


注:本文中的sf::RectangleShape::getOrigin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。