void QuadTree::split(){ float halfWidth = m_bounds.width / 2.f; float halfheight = m_bounds.height / 2.f; float x = m_bounds.left; float y = m_bounds.top; m_nodes.push_back(QuadTree(m_level + 1, sf::FloatRect(x, y, halfWidth, halfheight))); //top left m_nodes.push_back(QuadTree(m_level + 1, sf::FloatRect(x + halfWidth, y, halfWidth, halfheight))); //top right m_nodes.push_back(QuadTree(m_level + 1, sf::FloatRect(x + halfWidth, y + halfheight, halfWidth, halfheight))); //bottom right m_nodes.push_back(QuadTree(m_level + 1, sf::FloatRect(x, y + halfheight, halfWidth, halfheight))); //bottom left }
bool Utils::overlap(Object *Object1, Object *Object2, callbackFunctionQuadTree *Callback) { return false; if((!Object1) || !Object1->exists || (!Object2) || !Object2->exists ) return false; quadTree = QuadTree(QuadTree::bounds->x,QuadTree::bounds->y,QuadTree::bounds->width,QuadTree::bounds->height); quadTree.add(Object1, QuadTree::A_LIST); if(Object1 == Object2) return quadTree.overlap(false,Callback); quadTree.add(Object2,QuadTree::B_LIST); return quadTree.overlap(true,Callback); }
bool Utils::collide(Object *Object1, Object *Object2) { return false; if( (Object1 == NULL) || !Object1->exists || (Object2 == NULL) || !Object2->exists ) return false; quadTree = QuadTree(quadTreeBounds.x,quadTreeBounds.y,quadTreeBounds.width,quadTreeBounds.height); quadTree.add(Object1,QuadTree::A_LIST); bool match = (Object1 == Object2); if(!match) quadTree.add(Object2,QuadTree::B_LIST); bool cx = quadTree.overlap(!match,&solveXCollision); bool cy = quadTree.overlap(!match,&solveYCollision); return cx || cy; }