直接看代码!
理解方法就ok,其他的无视!(这是路径规划代码中的一部分内容)
for(unsigned int i = 0; i < 2; i++) // aid for avoiding diplicated code
{
Vector2<> positionOfObstacle = i == 0 ? positionOfObstacleStart : positionOfObstacleEnd;
Node position = i == 0 ? startPosition : endPosition;
Node otherPosition = i == 0 ? endPosition : startPosition;
vector<Node>& usedTree = i == 0 ? firstTree : secondTree;
bool& nearObstacle = i == 0 ? startNearObstacle : targetNearObstacle;
if(nearObstacle)
{
addAvoidingPoints(allObstacles, usedTree, position.position, positionOfObstacle, nearestObstacleMMX, otherPosition, i == 0); // calculate avoiding points if position is inside obstacle
}
else
{
usedTree.push_back(position); // use position itself if it is not near an obstacle
}
}