fixbug: cpp-test -> NewRenderer (drag the layer to test the result of culling), some object will be culling before out of screen.

This commit is contained in:
Vincent Yang 2015-06-23 15:22:27 +08:00
parent 0f5c343e1e
commit 4b768c5fd8
1 changed files with 14 additions and 19 deletions

View File

@ -1032,31 +1032,26 @@ bool Renderer::checkVisibility(const Mat4 &transform, const Size &size)
if (scene && scene->_defaultCamera != Camera::getVisitingCamera()) if (scene && scene->_defaultCamera != Camera::getVisitingCamera())
return true; return true;
// half size of the screen auto director = Director::getInstance();
Size screen_half = Director::getInstance()->getWinSize(); Rect visiableRect(director->getVisibleOrigin(), director->getVisibleSize());
screen_half.width /= 2;
screen_half.height /= 2;
// transform center point to screen space
float hSizeX = size.width/2; float hSizeX = size.width/2;
float hSizeY = size.height/2; float hSizeY = size.height/2;
Vec3 v3p(hSizeX, hSizeY, 0);
Vec4 v4world, v4local; transform.transformPoint(&v3p);
v4local.set(hSizeX, hSizeY, 0, 1); Vec2 v2p = Camera::getVisitingCamera()->projectGL(v3p);
transform.transformVector(v4local, &v4world);
// center of screen is (0,0)
v4world.x -= screen_half.width;
v4world.y -= screen_half.height;
// convert content size to world coordinates // 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 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])); 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 // enlarge visable rect half size in screen coord
float tmpx = (fabsf(v4world.x)-wshw); visiableRect.origin.x -= wshw;
float tmpy = (fabsf(v4world.y)-wshh); visiableRect.origin.y -= wshh;
bool ret = (tmpx < screen_half.width && tmpy < screen_half.height); visiableRect.size.width += wshw * 2;
visiableRect.size.height += wshh * 2;
bool ret = visiableRect.containsPoint(v2p);
return ret; return ret;
} }