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


C++ Coordinates::GetScreenFloat方法代码示例

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


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

示例1: Update

void World::Update(const float time_delta) {
	mCurrentLevelTime += time_delta;
	// INPUT!
	const sf::Input& in = GameApp::get_mutable_instance().GetInput();
	sf::View& view = GameApp::get_mutable_instance().GetView();
	if(GameApp::get_mutable_instance().IsEditorMode()) {
		float px = 10;
		if(in.IsKeyDown(sf::Key::LShift) || in.IsKeyDown(sf::Key::RShift)) {
			px *= 5;
		}
		if(in.IsKeyDown(sf::Key::Up)) {
			view.SetCenter(view.GetCenter().x, view.GetCenter().y - px);
		}
		if(in.IsKeyDown(sf::Key::Down)) {
			view.SetCenter(view.GetCenter().x, view.GetCenter().y + px);
		}
		if(in.IsKeyDown(sf::Key::Left)) {
			view.SetCenter(view.GetCenter().x - px, view.GetCenter().y);
		}
		if(in.IsKeyDown(sf::Key::Right)) {
			view.SetCenter(view.GetCenter().x + px, view.GetCenter().y);
		}

		Coordinates mp;
		mp.SetScreenPixel(GameApp::get_mutable_instance().GetMousePosition());
		if(mEditorMouseAction == EMA_GRAB) {
			mEditorMouseActionEntity->SetPosition( mEditorMouseActionStartEntityPosition.GetWorldFloat() +
												   mp.GetWorldFloat() -
												   mEditorMouseActionStartMousePosition.GetWorldFloat() );
		} else if(mEditorMouseAction == EMA_ALPHA) {
			float mpf = mp.GetScreenFloat().y;
			float mspf = mEditorMouseActionStartMousePosition.GetScreenFloat().y;
			float d = (mspf - mpf) * 5.f;
			float a = mEditorMouseActionStartEntityAlpha + d;
			if (a > 1) a = 1;
			if (a < 0) a = 0;
			mEditorMouseActionEntity->SetAlpha( a );
		} else if(mEditorMouseAction == EMA_SCALE) {
			Vector2D md = mEditorMouseActionStartEntityPosition.GetScreenPixel() - mp.GetScreenPixel();
			Vector2D sd = mEditorMouseActionStartEntityPosition.GetScreenPixel() - mEditorMouseActionStartMousePosition.GetScreenPixel();
			float f =  md.Magnitude() / sd.Magnitude();
			mEditorMouseActionEntity->SetScale( mEditorMouseActionStartEntityScale * f );
		} else if(mEditorMouseAction == EMA_ROTATE) {
			Coordinates ep;
			ep.SetWorldFloat(mEditorMouseActionEntity->GetPosition());
			mEditorMouseActionEntity->SetRotation(
					(mEditorMouseActionStartMousePosition.GetWorldFloat()-ep.GetWorldFloat()).Rotation()
					-(mp.GetWorldFloat()-ep.GetWorldFloat()).Rotation()
					+ mEditorMouseActionStartEntityRotation );
		}
	} else if(GameApp::get_mutable_instance().GetAppMode() == AM_PUZZLE) {
		// draw point on closest rail
		Rail* r = GetClosestRail();
		if(r != NULL) {
			Coordinates tmp;
			tmp.SetScreenPixel(GameApp::get_mutable_instance().GetMousePosition());
			float d = r->ClosestPositionOnLine(tmp.GetWorldFloat());
			mClosestRailPoint = r->GetPointFromFloat(d);
		}
		mClosestRail = r;

	}
	if(GetBoxEntity() != NULL && GetBoxEntity()->UsesPhysics() && !GameApp::get_mutable_instance().GetInput().IsMouseButtonDown(sf::Mouse::Left)) {
		mCurrentRail = GetClosestRail(true, GetBoxEntity()->GetBody()->getWorldTransform().getOrigin());
	}

	//mDynamicsWorld->stepSimulation(time_delta, 10);
	if(GameApp::get_mutable_instance().GetAppMode() == AM_PLAY) {
		mDynamicsWorld->stepSimulation(1 / 60.f, 10);
		mDynamicsWorld->clearForces();
	}

	Entity* c = GetClosestEntityOnLayer(GameApp::get_mutable_instance().GetMousePosition(), mEditorLayer);
	BOOST_FOREACH(Entity& entity, mEntities) {
		int h = 0;
		if (mEditorSelectedEntity == &entity) h = 2;
		else if (c == &entity) h = 1;
		entity.SetHighlightMode(h);
		entity.Update(time_delta);
		/*if(entity.GetLifeTime() >= entity.GetTimeToLive()) {
			mDynamicsWorld->removeRigidBody(entity.GetBody().get());
			mEntities.erase_if(boost::bind(&Entity::GetUID, _1) == entity.GetEntityUniqueId());
		}*/
	}
开发者ID:frankier,项目名称:gamejam,代码行数:84,代码来源:World.cpp


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