void ocTriTree::intersect(const z3D::Core::AABB& aabb, vector<int32_t>& tris) { Opcode::AABBCache cache; cache.Model = &_pimpl.get().model; IceMaths::AABB box; box.SetMinMax(Point(&aabb.minimum().x), Point(&aabb.maximum().x)); bool okay = _pimpl.get().aabb_collider.Collide(cache, box, _pimpl.get().model); if(!okay) return; Z_STATIC_ASSERT( sizeof(udword) == sizeof(uint32_t), WRONG_ASSUMPTION ); size_t count = _pimpl.get().aabb_collider.GetNbTouchedPrimitives(); uint32_t* tris2 = (uint32_t*)_pimpl.get().aabb_collider.GetTouchedPrimitives(); if(count) tris.insert(tris.end(), tris2, tris2 + count); }
bool AABBTreeOfTrianglesBuilder::ComputeGlobalBox(const udword* primitives, udword nb_prims, IceMaths::AABB& global_box) const { // Checkings if(!primitives || !nb_prims) return false; // Initialize global box IceMaths::Point Min(MAX_FLOAT, MAX_FLOAT, MAX_FLOAT); IceMaths::Point Max(MIN_FLOAT, MIN_FLOAT, MIN_FLOAT); // Loop through triangles VertexPointers VP; while(nb_prims--) { // Get current triangle-vertices mIMesh->GetTriangle(VP, *primitives++); // Update global box Min.Min(*VP.Vertex[0]).Min(*VP.Vertex[1]).Min(*VP.Vertex[2]); Max.Max(*VP.Vertex[0]).Max(*VP.Vertex[1]).Max(*VP.Vertex[2]); } global_box.SetMinMax(Min, Max); return true; }