| 1505 | } |
| 1506 | |
| 1507 | Terrain::QuadTree::QuadTree(int x, int y, int w, int h, Terrain* terrain) |
| 1508 | { |
| 1509 | _terrain = terrain; |
| 1510 | _needDraw = true; |
| 1511 | _parent = nullptr; |
| 1512 | _tl = nullptr; |
| 1513 | _tr = nullptr; |
| 1514 | _bl = nullptr; |
| 1515 | _br = nullptr; |
| 1516 | _posX = x; |
| 1517 | _posY = y; |
| 1518 | this->_height = h; |
| 1519 | this->_width = w; |
| 1520 | if (_width > terrain->_chunkSize.width && _height > terrain->_chunkSize.height) // subdivision |
| 1521 | { |
| 1522 | _isTerminal = false; |
| 1523 | this->_tl = new QuadTree(x, y, _width / 2, _height / 2, terrain); |
| 1524 | this->_tl->_parent = this; |
| 1525 | this->_tr = new QuadTree(x + _width / 2, y, _width / 2, _height / 2, terrain); |
| 1526 | this->_tr->_parent = this; |
| 1527 | this->_bl = new QuadTree(x, y + _height / 2, _width / 2, _height / 2, terrain); |
| 1528 | this->_bl->_parent = this; |
| 1529 | this->_br = new QuadTree(x + _width / 2, y + _height / 2, _width / 2, _height / 2, terrain); |
| 1530 | this->_br->_parent = this; |
| 1531 | |
| 1532 | _localAABB.merge(_tl->_localAABB); |
| 1533 | _localAABB.merge(_tr->_localAABB); |
| 1534 | _localAABB.merge(_bl->_localAABB); |
| 1535 | _localAABB.merge(_br->_localAABB); |
| 1536 | } |
| 1537 | else // is terminal Node |
| 1538 | { |
| 1539 | int m = _posY / terrain->_chunkSize.height; |
| 1540 | int n = _posX / terrain->_chunkSize.width; |
| 1541 | _chunk = terrain->_chunkesArray[m][n]; |
| 1542 | _isTerminal = true; |
| 1543 | _localAABB = _chunk->_aabb; |
| 1544 | _chunk->_parent = this; |
| 1545 | |
| 1546 | for (auto&& triangle : _chunk->_trianglesList) |
| 1547 | { |
| 1548 | triangle.transform(_terrain->getNodeToWorldTransform()); |
| 1549 | } |
| 1550 | } |
| 1551 | _worldSpaceAABB = _localAABB; |
| 1552 | _worldSpaceAABB.transform(_terrain->getNodeToWorldTransform()); |
| 1553 | } |
| 1554 | |
| 1555 | void Terrain::QuadTree::draw() |
| 1556 | { |
nothing calls this directly
no test coverage detected