本文整理汇总了C++中Space::getArea方法的典型用法代码示例。如果您正苦于以下问题:C++ Space::getArea方法的具体用法?C++ Space::getArea怎么用?C++ Space::getArea使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Space
的用法示例。
在下文中一共展示了Space::getArea方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: unfoldRoute
void Pathfinding::unfoldRoute(Route& out, Space* unfoldee, Space* end, Entity* entity) {
// NB: We're using a single-linked-list, so must retrace steps.
Space* step = unfoldee;
int timeout = 0;
Vector3 halfSize = entity->getBoundingBox().size * 0.5;
if(_showDebug) {
cout << "Unfold: " << unfoldee->getArea().toString();
cout << "End: " << end->getArea().toString();
}
while(true) {
if(step == step->astarParent) {
if(_showDebug) cout << " breaking loop, recursion found. " << endl;
break;
}
out.push_front(step->getCenter() - halfSize);
if(++timeout > 10000) {
if(_showDebug)
cout << "Canceled unfolding. Iterations so far: " << timeout
<< ". You probably have recursion? Or a too big map." << endl;
break;
}
if(step->astarParent == 0) {
if(_showDebug)
cout << "Breaking, this space leads to NULL." << step->getArea().toString();
break;
}
step = step->astarParent;
}
if(_showDebug)
cout << "End of unfolding method." << endl;
}
示例2: getPath
Pathfinding::Route Pathfinding::getPath(Entity* entity, const Vector3& goal) {
stringstream prettyInfo;
Vector3 start = entity->getPosition();
double a = phantom::Util::getTime();
_layer.cleanPathfinding();
Route route;
if(_showDebug) {
cout << endl<< endl<< endl<< endl;
}
if(_visualize) {
getGraphics().clear();
}
// Goal space uses a "strict" heuristic. EG: we don't want to walk into a tree.
Space* goalSpace = _layer.getSpaceAtUsingHeuristic(goal, entity);
// There is no "space" available at the destination. The entity probably wants
// to walk into a tree. Returns an empty route.
if(goalSpace == nullptr) {
if(_showDebug) {
cout << "Goal vector is not a space." << endl;
}
return route;
}
// Start space, first try using a strict heuristic. EG: If we start near a tree
// we don't want to walk into that tree.
Space* startSpace = _layer.getSpaceAtUsingHeuristic(start, entity);
// Ok, did we find a start space with the strict heuristic? If not, it probably
// means that our entity is stuck in a tree. Proceed with a less strict
// heuristic. In most cases this will let the entity "leave" the solid object
// that it's currently stuck on.
if(startSpace == nullptr) {
startSpace = _layer.getSpaceAtUsingHeuristic(start);
}
// Ok, we really can't walk anywhere. This is a rather odd case. Most likely
// the user tried to walk outside of the BSP tree, or you've just found a bug
// in the BSP tree.
if(startSpace == nullptr) {
if(_showDebug) {
cout << "Start vector is not a space." << endl;
}
route.push_back(Vector3(goal));
return route;
}
if(_showDebug) {
cout << "Starting at: " << startSpace->getArea().toString();
cout << "Ending at : " << goalSpace->getArea().toString();
}
if(_visualize) {
Box3& m = startSpace->getArea();
getGraphics().beginPath().setFillStyle(Color(0, 0, 127, 20))
.rect(m.origin.x+4, m.origin.y+4, m.size.x-8, m.size.y-8)
.fill();
Box3& n = goalSpace->getArea();
getGraphics().beginPath().setFillStyle(Color(0, 0, 127, 20))
.rect(n.origin.x+4, n.origin.y+4, n.size.x-8, n.size.y-8)
.fill();
}
priority_queue<Space*, vector<Space*>, CompareShapesAstar> open;
startSpace->isInOpenList = true;
open.push(startSpace);
if(_showBasicDebug) {
prettyInfo << "Pathfinding overhead: " << std::fixed << (phantom::Util::getTime() - a) << " seconds. ";
}
int spacesScanned = 0;
const double startTime = phantom::Util::getTime();
int timeout = 0;
while(true) {
if(open.empty()) {
if(_showBasicDebug || _showDebug) {
cout << " Open list empty." << endl;
double now = phantom::Util::getTime();
if(_showBasicDebug) {
prettyInfo << "No route found, scanned "<< spacesScanned << " Tile(s) in " << std::fixed << (now - startTime) << " seconds.";
}
}
break;
}
//.........这里部分代码省略.........