void COctree::checkOverlapWithOctree(OctreeNode* node, object3d* obj) { if(!node || !obj) return; //sphere overlap test float obj_radius=obj->getAABB().getLongestAxis()*0.5f; vector3f obj_center(obj->getAABB().getCenter()); if(!node->getAABB().isOverlapsSphere(obj_radius, obj_center)) return; //chk if the curent node collides with 'obj' if(!node->getAABB().isOverLap(obj->getAABB())) return; //chk if the meshes collide with 'obj' std::vector<object3d*>* list=node->getObjectList(); for(std::vector<object3d*>::iterator it = list->begin(); it != list->end(); ++it) { object3d* transf=*it; if(!transf->isVisited()) { if(obj->getAABB().isOverLap(transf->getAABB())) { transf->setVisited(true); if(transf->isBaseFlag(object3d::eObject3dBaseFlag_Alpha)) m_cCollidedAlphaObjLst.Append(transf); else m_cCollidedObjLst.Append(transf); } } } for(int x=0;x<MAX_OCTREECHILD;x++) checkOverlapWithOctree(node->getChild(x), obj); }
/** * Calculates whether a ray intersects with a sphere. Returns true or false, * storing the collision point in result if true. */ bool Sphere::intersection(Ray prim_ray, Vec3 &result) { double t0, t1; Vec3 obj_center(pos); Vec3 L = (*prim_ray.p1) - obj_center; double a = prim_ray.p2->dot(*prim_ray.p2); double b = 2 * prim_ray.p2->dot(L); double c = L.dot(L) - (radius * radius); if(!solve_quadratic(a, b, c, t0, t1)) { return false; } else { prim_ray.eval(t0, result); return true; } }