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


C++ MapObject::getNextPosition方法代码示例

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


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

示例1: int

wns::Position
Street::getNextPosition(MapUser* user, simTimeType dt) const
{
	// in case we just entered this street, we have to determine the
	// user's heading. If we come from the crossing at endPoint[0], we
	// call it "Forward", otherwise we'll call it "Reverse"
	if (user->currentObject!=this->id)
	{
		MapObject::ID from = user->currentObject;
		user->heading = (  ( from==connections.at(0))
						   ? int(Headings::Forward())
						   : int(Headings::Reverse()) );
		user->currentObject=this->id;
	}

	// how much of this road remains?
	double remaining = (1-user->percent)*streetVector.abs();

	// is user velocity on this street bounded by vMax?
	double currentVelocity = ( user->velocity < vMax ? user->velocity : vMax );

	if (currentVelocity*dt < remaining)
	{
		// we stay on this road and only advance by a certain
		// percentage (given through velocity and timestep)
		user->percent += (currentVelocity*dt)/streetVector.abs();

		MESSAGE_BEGIN(NORMAL, log, m, "MapUser advancing on street ");
		m << id << ", completed " << int(100.0*user->percent) 
		  << "%, velocity " << currentVelocity << "(desired: " << user->velocity << ") m/s";
		MESSAGE_END();

		return this->getPosition(user);
	}
	else
	{
		// we reach the end of this street, how long does that take?
		double untilCrossing = remaining/currentVelocity;
		// determine the object we'll reach next
		MapObject* nextObject = map->getObject(( user->heading==Headings::Forward()
												 ? connections.at(1)
												 : connections.at(0) ));
		// and delegate the decision about the new final position
		return nextObject->getNextPosition(user,dt-untilCrossing);
	}
}
开发者ID:openwns,项目名称:rise,代码行数:46,代码来源:Street.cpp


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