Skip to content

Commit

Permalink
fixbug: cpp-test -> NewRenderer (drag the layer to test the result of…
Browse files Browse the repository at this point in the history
… culling), some object will be culling before out of screen.
  • Loading branch information
yangws committed Jun 23, 2015
1 parent 0f5c343 commit 4b768c5
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions cocos/renderer/CCRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 4b768c5

Please sign in to comment.