void Octant::Insert(SceneNode* obj) { const BoundingBox& box = obj->GetWorldBoundingBox(); // If drawable is outside the root octant bounds, insert to root bool insertHere; if (this == root_) insertHere = cullingBox_.IsInside(box) != Intersection::INSIDE || CheckFit(box); else insertHere = CheckFit(box); if (insertHere) { Octant* oldOctant = obj->GetOctant(); if (oldOctant != this) { // Add first, then remove, because drawable count going to zero deletes the octree branch in question Add(obj); if (oldOctant) oldOctant->Remove(obj, false); } } else { Vector3 boxCenter = box.Center(); unsigned x = boxCenter.x < center_.x ? 0 : 1; unsigned y = boxCenter.y < center_.y ? 0 : 2; unsigned z = boxCenter.z < center_.z ? 0 : 4; GetOrCreateChild(x + y + z)->Insert(obj); } }
void Tessellation( Node& n1, Node& n2, Node& n3, Vertices& vertices, Indices& indices, unsigned curDepth, unsigned maxDepth ) { if( curDepth<maxDepth ) { Node *n12 = GetOrCreateChild(n1, n2, vertices); Node *n23 = GetOrCreateChild(n2, n3, vertices); Node *n31 = GetOrCreateChild(n3, n1, vertices); Tessellation( n1, *n12, *n31, vertices, indices, curDepth+1, maxDepth ); Tessellation( n2, *n23, *n12, vertices, indices, curDepth+1, maxDepth ); Tessellation( n3, *n31, *n23, vertices, indices, curDepth+1, maxDepth ); Tessellation( *n12, *n23, *n31, vertices, indices, curDepth+1, maxDepth ); } else { indices.push_back( n1.GetIndex() ); indices.push_back( n2.GetIndex() ); indices.push_back( n3.GetIndex() ); } }