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


C++ Obstacle::TagColl方法代码示例

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


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

示例1: ObstacleAvoidance

ofVec3f SteeringBehaviors::ObstacleAvoidance(const std::vector<Obstacle*>& _obstacles)
{
	//compute length of detection cylinder
	m_detCylL = abs(m_viewDistance  *  (m_Vehicle->Speed() / m_Vehicle->MaxSpeed()))*2;
	m_detCylR = m_Vehicle->BRadius(); //base radius of the cylinder
	//tag all neighboring obstacles
	TagNeighbors(m_Vehicle, _obstacles,  m_detCylL);
	//keep tracks of the closest intersectin object (CIB)
	Obstacle* CIB = NULL;
	float distToCIB = FLT_MAX;
	ofVec3f localObstaclePos, localPosCIB;
	//quaternions used to translate between global and local spaces
	ofQuaternion rot;
	ofVec4f rota;

	std::vector<Obstacle*>::const_iterator it;
	it = _obstacles.begin();
	while (it != _obstacles.end())
	{
		//*******************
		//collision debugging
		(*it)->UnTagColl();
		//*******************
		//discard if not tagged
		if ((*it)->IsTagged())
		{
			//Translate _obstacle in m_Vehicle local space
			//(assuming 0,0,-1 as m_Vehicle base heading)
			rot.makeRotate(ofVec3f(0.0, 0.0, -1.0), m_Vehicle->Heading());
			rot.getRotate(rota.w, rota.x, rota.y, rota.z);
			localObstaclePos = (*it)->Pos() - m_Vehicle->Pos();
			localObstaclePos.rotate(-rota.w, ofVec3f(rota.x, rota.y, rota.z));
			//discard if behind or farther away than cylinder 
			float rad = (*it)->BRadius();
			if ((localObstaclePos.z < 0)
				&& (localObstaclePos.z > -m_detCylL))
			{
				//discard if not within cylinder				
				if((localObstaclePos.y <= m_detCylR+rad)
					&&(localObstaclePos.y >= -m_detCylR-rad)
					&&(localObstaclePos.x <= m_detCylR+rad)
					&&(localObstaclePos.x >= -m_detCylR-rad))
				{
					//get the closest intersecting obstacle
					//(simplifying here -- need to get the closest intersecting point instead)
					if(localObstaclePos.z < distToCIB)
					{
						CIB = (*it);
						localPosCIB = localObstaclePos;
						distToCIB = localObstaclePos.z;
					}

				}
			}
		}
		++it;
	}

	//if obstacle detected...
	if (CIB)
	{
		CIB->TagColl();	//debug for collision draw
		// create escape point in local space (ignoring actual intersection point for now)
		if (localPosCIB.x>0)
		{
			escapePoint.x = localPosCIB.x - CIB->BRadius() - escapeDistance - m_Vehicle->BRadius();
		}
		else
		{
			escapePoint.x = localPosCIB.x + CIB->BRadius() + escapeDistance + m_Vehicle->BRadius();
		}
		escapePoint.y = localPosCIB.y;
		escapePoint.z = localPosCIB.z;
		// translate escape point back to global space
		escapePoint += m_Vehicle->Pos();
		escapePoint.rotate(rota.w, ofVec3f(rota.x, rota.y, rota.z));
		// return force to steer to escape point
		ofVec3f DesiredVelocity; 
		float multiplier = 10; //* ((m_detCylL - distToCIB) / m_detCylL);
		//brakes
		float breakingWeight = abs(.05 / (1 - distToCIB));
		m_Vehicle->SetVelocity(m_Vehicle->Velocity()*breakingWeight);
		DesiredVelocity += (escapePoint - m_Vehicle->Pos()).getNormalized() * (m_Vehicle->MaxSpeed()*multiplier);
		return (DesiredVelocity - m_Vehicle->Velocity());
	}
	return ofVec3f::zero();
}
开发者ID:Fraps77,项目名称:CityStart,代码行数:87,代码来源:SteeringBehaviors.cpp


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