void WaterPhysicsSystem::addFinalisedVertex(Vertex* _vertex, Edge* _edge, bool _leftEdge) { Vec2f a = _vertex->position; Vec2f b; Vertex* left; Vertex* right; Vertex** unsetVertex; Boundary* boundary = _vertex->getBoundary(); if (boundary == nullptr) { boundary = new Boundary(this); boundaries.push_back(boundary); } if (_leftEdge) { b = a + Vec2f(500, 0); left = _vertex; unsetVertex = &right; boundary->setLeft(_vertex); } else { b = a - Vec2f(500, 0); right = _vertex; unsetVertex = &left; boundary->setRight(_vertex); } Edge* opposingEdge = findIntersectingEdge(a, &b, _edge); if (opposingEdge) { *unsetVertex = new Vertex(b, nullptr, true); } else { *unsetVertex = nullptr; } if (left) boundary->setLeft(left); if (right) boundary->setRight(right); }
void WaterPhysicsSystem::addFinalisedEdge(Edge* _edge) { edges.push_back(_edge); Edge::EdgeType type = _edge->getEdgeType(); bool leftEdge; if (type == Edge::eLeftFloor || type == Edge::eLeftRoof) { leftEdge = true; } else { leftEdge = false; } addFinalisedVertex(_edge->getA(), _edge, leftEdge); addFinalisedVertex(_edge->getB(), _edge, leftEdge); // for (Boundary* boundary = boundaries.front(); boundary; boundary = boundary->getNextObject()) for (unsigned int i = 0; i != boundaries.size(); i++) { Boundary* boundary = boundaries[i]; if (boundary) try { Vec2f position = intersectionPosition(_edge->aPosition(), _edge->bPosition(), boundary->getLeftPosition(), boundary->getRightPosition()); Vertex* vertex = new Vertex(position, nullptr, true); if (leftEdge) { //assert(boundary->getLeft() == nullptr); boundary->setLeft(vertex); } else { // assert(boundary->getRight() == nullptr); boundary->setRight(vertex); } } catch (int i) {} } /* edges.push_back(_edge); Vec2f a = _edge->aPosition(); Vertex* vertex = _edge->getA(); bool jump = true; goto ACTUAL_START; START: vertex = _edge->getB(); jump = false; ACTUAL_START: Vec2f b; Edge::EdgeType type = _edge->getEdgeType(); bool leftEdge; if (type == Edge::eLeftFloor | type == Edge::eLeftRoof) { b = a + Vec2f(500, 0); leftEdge = true; } else { b = a - Vec2f(500, 0); leftEdge = false; } Edge* opposingEdge = findIntersectingEdge(a, &b, _edge); if (opposingEdge) { Vec2f a2 = opposingEdge->aPosition(); Vec2f b2 = a2 + Vec2f((leftEdge)?-500:500,0); Edge* opposingOpposingEdge = findIntersectingEdge(a2, &b2, opposingEdge); if (opposingOpposingEdge == _edge) { Edge* selfSplit = _edge->split(b2, nullptr); edges.push_back(selfSplit); } // else { a2 = opposingEdge->bPosition(); b2 = a2 + Vec2f((leftEdge)?-500:500,0); opposingOpposingEdge = findIntersectingEdge(a2, &b2, opposingEdge); if (opposingOpposingEdge == _edge) { Edge* selfSplit = _edge->split(b2, nullptr); edges.push_back(selfSplit); } } Edge* newEdge = opposingEdge->split(b, nullptr); edges.push_back(newEdge); } if (jump) { a = _edge->bPosition(); goto START; }*/ }