std::vector<Entity*> SceneManager::clipEntityWithFrustum( const std::vector<Entity*>& ents) const { PlaneList frustumPlanes = getCamera()->getVolumePlanes(EPID_all); std::vector<Entity*> rents; for (int i = 0; i < (int)ents.size(); ++i) { Entity* ent = ents[i]; Matrix4x4 worldViewMat = ent->getSceneNode()->getWorldMatrix() * getCamera()->getViewMatrix(); AABB aabb = ent->getBoundAABB(); transform(aabb, worldViewMat); if (intersect(frustumPlanes, aabb.getCorners()) == EIC_front) continue; Sphere sphere = ent->getBoundSphere(); transform(sphere, worldViewMat); if (intersect(frustumPlanes, sphere) == EIC_front) continue; rents.push_back(ent); } Log::instance()->addMsg("frustum clip : %d/%d", ents.size() - rents.size(), ents.size()); return rents; }
bool ConvexHull::intersect(const AABB& aabb, const SimpleTransform& transform, const Vec3& scale) const { auto corners = std::array<Vec3, 8>(); aabb.getCorners(corners, transform, scale); for (auto& plane : planes_) { // Check if the AABB lies on the front of this plane, if so then there is no intersection with this convex hull for (auto j = 0U; j < 8; j++) { if (plane.distance(corners[j]) < 0.0f) break; if (j == 7) return false; } } return true; }