mirror of https://github.com/axmolengine/axmol.git
performance improvements in culling
This commit is contained in:
parent
04460750b8
commit
f77b92f1d7
|
@ -617,25 +617,30 @@ void Sprite::draw(void)
|
|||
// Culling function from cocos2d-iphone CCSprite.m file
|
||||
bool Sprite::culling() const
|
||||
{
|
||||
Size s = Director::getInstance()->getWinSize();
|
||||
float hcsx = _contentSize.width * 0.5f;
|
||||
float hcsy = _contentSize.height * 0.5f;
|
||||
// half size of the screen
|
||||
Size screen_half = Director::getInstance()->getWinSize();
|
||||
screen_half.width /= 2;
|
||||
screen_half.height /= 2;
|
||||
|
||||
float hcsx = _contentSize.width / 2;
|
||||
float hcsy = _contentSize.height / 2;
|
||||
|
||||
// convert to world coordinates
|
||||
float x = hcsx * _modelViewTransform.mat[0] + hcsy * _modelViewTransform.mat[4] + _modelViewTransform.mat[12];
|
||||
float y = hcsx * _modelViewTransform.mat[1] + hcsy * _modelViewTransform.mat[5] + _modelViewTransform.mat[13];
|
||||
|
||||
// center of screen is (0,0)
|
||||
x -= s.width/2;
|
||||
y -= s.height/2;
|
||||
x -= screen_half.width;
|
||||
y -= screen_half.height;
|
||||
|
||||
// convert content size to world coordinates
|
||||
float wchw = hcsx * fmaxf(fabsf(_modelViewTransform.mat[0] + _modelViewTransform.mat[4]), fabsf(_modelViewTransform.mat[0] - _modelViewTransform.mat[4]));
|
||||
float wchh = hcsy * fmaxf(fabsf(_modelViewTransform.mat[1] + _modelViewTransform.mat[5]), fabsf(_modelViewTransform.mat[1] - _modelViewTransform.mat[5]));
|
||||
|
||||
// compare if it in the positive quarter of the screen
|
||||
float tmpx = (fabsf(x)-wchw);
|
||||
float tmpy = (fabsf(y)-wchh);
|
||||
return (tmpx < s.width/2 && tmpy < s.height/2);
|
||||
return (tmpx < screen_half.width && tmpy < screen_half.height);
|
||||
}
|
||||
|
||||
// Node overrides
|
||||
|
|
Loading…
Reference in New Issue