void AddFieldNode(CPLXMLNode* node, int iOrderPos) { if (iOrderPos >= (int)oFields.size()) oFields.resize(iOrderPos+1); //CPLDebug( "OGR_ILI", "Register field with OrderPos %d to Class %s", iOrderPos, GetName()); oFields[iOrderPos] = node; }
void ConvertFromLonLatToCartesian( const LonLatNodeVector & vecLonLatNodes, NodeVector & vecNodes ) { vecNodes.resize(vecLonLatNodes.size()); // Loop over all nodes int i; for (i = 0; i < vecLonLatNodes.size(); i++) { vecNodes[i].x = sin(vecLonLatNodes[i].lon) * cos(vecLonLatNodes[i].lat); vecNodes[i].y = cos(vecLonLatNodes[i].lon) * cos(vecLonLatNodes[i].lat); vecNodes[i].z = sin(vecLonLatNodes[i].lat); } }
void EntityEngine::generatePathfindingNodes(NodeVector & nodes) { // lay a grid over the static entities Timing tm; const int resolutionFactor = 1; const float collisionMarginFactor = 2.5f; const float gridSize = 1.0f / float(resolutionFactor); // 0.5f; //const float neighbourDistance = sqrt(gridSize * gridSize * 2.0f) * 1.1f; float floatHighestY = 0; float floatLowestY = 100000000000.0f; for (Entity const* ent : getStaticEntities()) { floatHighestY = std::max(floatHighestY, ent->getPosition().y()); floatLowestY = std::min(floatLowestY, ent->getPosition().y()); } dropNavigationNodes(nodes); // protect against no entities if (getStaticEntities().size() == 0) return; assert(floatHighestY > floatLowestY); logging::Info() << "Generating navigation grid for lowY: " << floatLowestY << " highY: " << floatHighestY; const int highestY = int(std::ceil(floatHighestY)); const int lowestY = int(std::floor(floatLowestY)); const int spanY = highestY - lowestY; const float spanX = 15.0f; const int nodeCount = (spanX * resolutionFactor) * (spanY * resolutionFactor); nodes.resize(nodeCount); // with a resolution of 2 times the tile size const int sizeX = spanX * resolutionFactor; const int sizeY = (spanY * resolutionFactor); for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { Vector2 pos(float(x) * gridSize, float(y) * gridSize + float(lowestY)); // do only add if there is no collision object near by if (!checkForCollisionObject(pos, gridSize * collisionMarginFactor)) { const int thisNodeLocation = sizeX * y + x; NodePtr n = &nodes[thisNodeLocation]; n->Location = pos; // connect to left if (x > 0) { // left same line n->Neighbours.push_back(&nodes[thisNodeLocation - 1]); // left lower if (y > 0) { n->Neighbours.push_back(&nodes[thisNodeLocation - 1 - sizeX]); } // left upper if (y < (sizeY - 1)) { n->Neighbours.push_back(&nodes[thisNodeLocation - 1 + sizeX]); } } if (x < (sizeX - 1)) { // right same line n->Neighbours.push_back(&nodes[thisNodeLocation + 1]); // right lower if (y > 0) { n->Neighbours.push_back(&nodes[thisNodeLocation + 1 - sizeX]); } // right upper if (y < (sizeY - 1)) { n->Neighbours.push_back(&nodes[thisNodeLocation + 1 + sizeX]); } } if (y > 0) { // lower one n->Neighbours.push_back(&nodes[thisNodeLocation - sizeX]); } if (y < (sizeY - 1)) { // upper one n->Neighbours.push_back(&nodes[thisNodeLocation + sizeX]); } } } } float dt = tm.end(); logging::Info() << "Building the Pathfinding grid took " << dt << " seconds"; }