diff --git a/cocos/renderer/CCRenderer.cpp b/cocos/renderer/CCRenderer.cpp index f84b0bd990..86ab1045b8 100644 --- a/cocos/renderer/CCRenderer.cpp +++ b/cocos/renderer/CCRenderer.cpp @@ -1031,32 +1031,27 @@ bool Renderer::checkVisibility(const Mat4 &transform, const Size &size) // only cull the default camera. The culling algorithm is valid for default camera. if (scene && scene->_defaultCamera != Camera::getVisitingCamera()) return true; - - // half size of the screen - Size screen_half = Director::getInstance()->getWinSize(); - screen_half.width /= 2; - screen_half.height /= 2; + auto director = Director::getInstance(); + Rect visiableRect(director->getVisibleOrigin(), director->getVisibleSize()); + + // transform center point to screen space float hSizeX = size.width/2; float hSizeY = size.height/2; - - Vec4 v4world, v4local; - v4local.set(hSizeX, hSizeY, 0, 1); - transform.transformVector(v4local, &v4world); - - // center of screen is (0,0) - v4world.x -= screen_half.width; - v4world.y -= screen_half.height; + Vec3 v3p(hSizeX, hSizeY, 0); + transform.transformPoint(&v3p); + Vec2 v2p = Camera::getVisitingCamera()->projectGL(v3p); // convert content size to world coordinates float wshw = std::max(fabsf(hSizeX * transform.m[0] + hSizeY * transform.m[4]), fabsf(hSizeX * transform.m[0] - hSizeY * transform.m[4])); float wshh = std::max(fabsf(hSizeX * transform.m[1] + hSizeY * transform.m[5]), fabsf(hSizeX * transform.m[1] - hSizeY * transform.m[5])); - - // compare if it in the positive quadrant of the screen - float tmpx = (fabsf(v4world.x)-wshw); - float tmpy = (fabsf(v4world.y)-wshh); - bool ret = (tmpx < screen_half.width && tmpy < screen_half.height); - + + // enlarge visable rect half size in screen coord + visiableRect.origin.x -= wshw; + visiableRect.origin.y -= wshh; + visiableRect.size.width += wshw * 2; + visiableRect.size.height += wshh * 2; + bool ret = visiableRect.containsPoint(v2p); return ret; }