fixed issues and elevators
This commit is contained in:
@@ -155,18 +155,24 @@ public:
|
||||
}
|
||||
|
||||
for (StairNode& sn : stairNodes) {
|
||||
const float zPercent = (sn.z_cm - minZ) / (maxZ - minZ); // current percentage from minZ to maxZ
|
||||
//sn.z_cm = floor->getStartingZ()*100 + zPercent * floor->height*100; // apply percentage to floorStartZ <-> floorEndZ
|
||||
sn.z_cm = std::round(stairAbsStart_cm + zPercent * stairHeight_cm); // apply percentage to floorStartZ <-> floorEndZ
|
||||
const float zPercent = (sn.z_cm - minZ) / (maxZ - minZ); // current percentage from minZ to maxZ WHICH ONE IS CORRECT?
|
||||
//const float zPercent = (sn.z_cm - stairAbsStart_cm) / (stairAbsEnd_cm - stairAbsStart_cm); // current percentage from minZ to maxZ WHICH ONE IS CORRECT?
|
||||
//sn.z_cm = floor->getStartingZ()*100 + zPercent * floor->height*100; // apply percentage to floorStartZ <-> floorEndZ
|
||||
sn.z_cm = std::round(stairAbsStart_cm + zPercent * stairHeight_cm); // apply percentage to floorStartZ <-> floorEndZ
|
||||
}
|
||||
|
||||
// snap stair-nodes to nearby grid nodes, if possible
|
||||
if (tryImproveStairConnections) {
|
||||
for (StairNode& sn : stairNodes) {
|
||||
if (std::abs(sn.z_cm-stairAbsStart_cm) < gs_cm*0.75 && grid.hasNodeFor(GridPoint(sn.x_cm, sn.y_cm, stairAbsStart_cm)) ) {sn.z_cm = stairAbsStart_cm;}
|
||||
if (std::abs(sn.z_cm-stairAbsEnd_cm) < gs_cm*0.75 && grid.hasNodeFor(GridPoint(sn.x_cm, sn.y_cm, stairAbsEnd_cm))) {sn.z_cm = stairAbsEnd_cm;}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// // snap stair-nodes to nearby grid nodes, if possible
|
||||
// // we try to improve the number of connections between stair and starting/ending floor
|
||||
// if (tryImproveStairConnections) {
|
||||
// for (StairNode& sn : stairNodes) {
|
||||
// //if (std::abs(sn.z_cm-stairAbsStart_cm) < gs_cm*0.75 && grid.hasNodeFor(GridPoint(sn.x_cm, sn.y_cm, stairAbsStart_cm)) ) {sn.z_cm = stairAbsStart_cm;}
|
||||
// //if (std::abs(sn.z_cm-stairAbsEnd_cm) < gs_cm*0.75 && grid.hasNodeFor(GridPoint(sn.x_cm, sn.y_cm, stairAbsEnd_cm))) {sn.z_cm = stairAbsEnd_cm;}
|
||||
// //if (std::abs(sn.z_cm-stairAbsStart_cm) < gs_cm*1.5 && grid.hasNodeFor(GridPoint(sn.x_cm, sn.y_cm, stairAbsStart_cm)) ) {auxcon.push_back(AuxConnection(sn, GridPoint(sn.x_cm, sn.y_cm, stairAbsStart_cm)));}
|
||||
// //if (std::abs(sn.z_cm-stairAbsEnd_cm) < gs_cm*1.5 && grid.hasNodeFor(GridPoint(sn.x_cm, sn.y_cm, stairAbsEnd_cm))) {auxcon.push_back(AuxConnection(sn, GridPoint(sn.x_cm, sn.y_cm, stairAbsEnd_cm)));}
|
||||
// }
|
||||
// }
|
||||
|
||||
// stort all stair-nodes by z (ascending)
|
||||
const auto comp = [] (const StairNode& sn1, const StairNode& sn2) {return sn1.z_cm < sn2.z_cm;};
|
||||
@@ -235,6 +241,40 @@ public:
|
||||
|
||||
}
|
||||
|
||||
|
||||
// for larger grid-sizes stair connections to starting/ending floors are quite bad if the stairs are not 90degree aligned
|
||||
// to improve the number of connections between floor and stair, we brute-force search for connectable nodes (between stair and floor, given threshold)
|
||||
if (tryImproveStairConnections) {
|
||||
|
||||
// connect all stair-nodes to the floor if their distance is below this threshold
|
||||
const int maxDist_cm = gs_cm * 1.2;
|
||||
|
||||
for (StairNode& sn : stairNodes) {
|
||||
|
||||
const auto& gn1 = grid[sn.gridIdx];
|
||||
|
||||
// all stair-nodes that are near to a floor
|
||||
const bool lower = std::abs(sn.z_cm-stairAbsStart_cm) < maxDist_cm;
|
||||
const bool upper = std::abs(sn.z_cm-stairAbsEnd_cm) < maxDist_cm;
|
||||
|
||||
if (lower || upper) {
|
||||
|
||||
// cross-check with each grid node (slow...)
|
||||
for (const auto& gn2 : grid.getNodes()) {
|
||||
if (gn2.getDistanceInCM(gn1) > maxDist_cm) {continue;} // connect with a floor-node near the stair-node
|
||||
if (gn1.hasNeighbor(gn2.getIdx())) {continue;} // already connected?
|
||||
//if (gn2.hasNeighbor(gn1.getIdx())) {continue;}
|
||||
if (gn2.getIdx() == gn1.getIdx()) {continue;} // do not connect with myself
|
||||
if (gn2.fullyConnected()) {continue;} // skip full nodes
|
||||
if (gn1.fullyConnected()) {continue;} // skip full nodes
|
||||
grid.connectBiDir(gn1.getIdx(), gn2.getIdx()); // connect
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// sanity check
|
||||
// connectedWithHeights should contain 2 entries:
|
||||
// one for the starting floor
|
||||
@@ -274,11 +314,8 @@ public:
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user