- Plane::Halfspace halfspace;
- int octantNum = -1;
-
- Plane xy = node->node.getAabb().getPlaneXY();
- halfspace = xy.intersectsSphere(entity->getSphere());
-
- if (halfspace == Plane::POSITIVE)
- {
- Plane xz = node->node.getAabb().getPlaneXZ();
- halfspace = xz.intersectsSphere(entity->getSphere());
-
- if (halfspace == Plane::POSITIVE)
- {
- Plane yz = node->node.getAabb().getPlaneYZ();
- halfspace = yz.intersectsSphere(entity->getSphere());
-
- if (halfspace == Plane::POSITIVE)
- {
- octantNum = 2;
- }
- else if (halfspace == Plane::NEGATIVE)
- {
- octantNum = 3;
- }
- }
- else if (halfspace == Plane::NEGATIVE)
- {
- Plane yz = node->node.getAabb().getPlaneYZ();
- halfspace = yz.intersectsSphere(entity->getSphere());
-
- if (halfspace == Plane::POSITIVE)
- {
- octantNum = 1;
- }
- else if (halfspace == Plane::NEGATIVE)
- {
- octantNum = 0;
- }
- }
- }
- else if (halfspace == Plane::NEGATIVE)
- {
- Plane xz = node->node.getAabb().getPlaneXZ();
- halfspace = xz.intersectsSphere(entity->getSphere());
-
- if (halfspace == Plane::POSITIVE)
- {
- Plane yz = node->node.getAabb().getPlaneYZ();
- halfspace = yz.intersectsSphere(entity->getSphere());
-
- if (halfspace == Plane::POSITIVE)
- {
- octantNum = 6;
- }
- else if (halfspace == Plane::NEGATIVE)
- {
- octantNum = 7;
- }
- }
- else if (halfspace == Plane::NEGATIVE)
- {
- Plane yz = node->node.getAabb().getPlaneYZ();
- halfspace = yz.intersectsSphere(entity->getSphere());
-
- if (halfspace == Plane::POSITIVE)
- {
- octantNum = 5;
- }
- else if (halfspace == Plane::NEGATIVE)
- {
- octantNum = 4;
- }
- }
- }
-
- if (octantNum == -1)
- {
- node->node.objects.push_front(entity);
- return node;
- }
- else
- {
- if (node->isLeaf())
- {
- addChildren(node);
- }
-
- Ptr child = node->getChild(octantNum);
- if (child)
- {
- return add(child, entity);
- }
- else
- {
- std::cerr << "no child at index " << octantNum << std::endl;
- return Ptr();
- }
- //return WeakPtr();
- }