本文整理汇总了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();
}