From 4b768c5fd81a5cfd6b0e4e1fc5210630a7f8e75e Mon Sep 17 00:00:00 2001 From: Vincent Yang Date: Tue, 23 Jun 2015 15:22:27 +0800 Subject: [PATCH] =?UTF-8?q?fixbug:=20cpp-test=20->=20NewRenderer=20?= =?UTF-8?q?=EF=BC=88drag=20the=20layer=20to=20test=20the=20result=20of=20c?= =?UTF-8?q?ulling=EF=BC=89,=20some=20object=20will=20be=20culling=20before?= =?UTF-8?q?=20out=20of=20screen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos/renderer/CCRenderer.cpp | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) 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; }