Merge pull request #242 from dabingnn/fix_s9Sprite_texel_strech

fix texel strech in scale9 sprite
This commit is contained in:
pandamicro
2016-07-22 10:56:22 +08:00
committed by GitHub
@@ -115,20 +115,23 @@ public:
//uv computation should take spritesheet into account.
float u0, u3;
float v0, v3;
float texStrech = 0;
#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
texStrech = 0.5;
#endif
if (spriteFrame->isRotated()) {
u0 = textureRect.origin.x / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.height) / atlasWidth;
u0 = (textureRect.origin.x + texStrech) / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.height - texStrech) / atlasWidth;
v0 = textureRect.origin.y / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.width) / atlasHeight;
v0 = (textureRect.origin.y + texStrech) / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.width - texStrech) / atlasHeight;
}
else {
u0 = textureRect.origin.x / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.width) / atlasWidth;
u0 = (textureRect.origin.x + texStrech) / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.width - texStrech) / atlasWidth;
v0 = textureRect.origin.y / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.height) / atlasHeight;
v0 = (textureRect.origin.y + texStrech) / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.height - texStrech) / atlasHeight;
}
std::vector<cocos2d::Vec2> uvCoordinates(2);
@@ -244,28 +247,32 @@ public:
//uv computation should take spritesheet into account.
float u0, u1, u2, u3;
float v0, v1, v2, v3;
float texStrech = 0;
#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
texStrech = 0.5;
#endif
if (spriteFrame->isRotated()) {
u0 = textureRect.origin.x / atlasWidth;
u0 = (textureRect.origin.x + texStrech) / atlasWidth;
u1 = (bottomHeight + textureRect.origin.x) / atlasWidth;
u2 = (bottomHeight + centerHeight + textureRect.origin.x) / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.height) / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.height - texStrech) / atlasWidth;
v0 = textureRect.origin.y / atlasHeight;
v0 = (textureRect.origin.y + texStrech) / atlasHeight;
v1 = (leftWidth + textureRect.origin.y) / atlasHeight;
v2 = (leftWidth + centerWidth + textureRect.origin.y) / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.width) / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.width - texStrech) / atlasHeight;
}
else {
u0 = textureRect.origin.x / atlasWidth;
u0 = (textureRect.origin.x + texStrech) / atlasWidth;
u1 = (leftWidth + textureRect.origin.x) / atlasWidth;
u2 = (leftWidth + centerWidth + textureRect.origin.x) / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.width) / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.width - texStrech) / atlasWidth;
v0 = textureRect.origin.y / atlasHeight;
v0 = (textureRect.origin.y + texStrech) / atlasHeight;
v1 = (topHeight + textureRect.origin.y) / atlasHeight;
v2 = (topHeight + centerHeight + textureRect.origin.y) / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.height) / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.height - texStrech) / atlasHeight;
}
std::vector<cocos2d::Vec2> uvCoordinates(4);
@@ -343,19 +350,24 @@ public:
float u0, u3;
float v0, v3;
float texStrech = 0;
#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
texStrech = 0.5;
#endif
if (spriteFrame->isRotated()) {
u0 = textureRect.origin.x / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.height) / atlasWidth;
u0 = (textureRect.origin.x + texStrech) / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.height - texStrech) / atlasWidth;
v0 = textureRect.origin.y / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.width) / atlasHeight;
v0 = (textureRect.origin.y + texStrech) / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.width - texStrech) / atlasHeight;
}
else {
u0 = textureRect.origin.x / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.width) / atlasWidth;
u0 = (textureRect.origin.x + texStrech)/ atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.width - texStrech) / atlasWidth;
v0 = textureRect.origin.y / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.height) / atlasHeight;
v0 = (textureRect.origin.y + texStrech) / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.height - texStrech) / atlasHeight;
}
std::vector<cocos2d::Vec2> uvCoordinates(2);
@@ -496,19 +508,24 @@ public:
float u0, u3;
float v0, v3;
float texStrech = 0;
#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
texStrech = 0.5;
#endif
if (spriteFrame->isRotated()) {
u0 = textureRect.origin.x / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.height) / atlasWidth;
u0 = (textureRect.origin.x + texStrech)/ atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.height - texStrech) / atlasWidth;
v0 = textureRect.origin.y / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.width) / atlasHeight;
v0 = (textureRect.origin.y + texStrech) / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.width - texStrech) / atlasHeight;
}
else {
u0 = textureRect.origin.x / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.width) / atlasWidth;
u0 = (textureRect.origin.x + texStrech) / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.width - texStrech) / atlasWidth;
v0 = textureRect.origin.y / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.height) / atlasHeight;
v0 = (textureRect.origin.y + texStrech) / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.height - texStrech) / atlasHeight;
}
std::vector<cocos2d::Vec2> uvs(2);
uvs[0] = cocos2d::Vec2(u0,v3);
@@ -826,19 +843,24 @@ public:
float u0, u3;
float v0, v3;
float texStrech = 0;
#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
texStrech = 0.5;
#endif
if (spriteFrame->isRotated()) {
u0 = textureRect.origin.x / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.height) / atlasWidth;
u0 = (textureRect.origin.x + texStrech) / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.height - texStrech) / atlasWidth;
v0 = textureRect.origin.y / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.width) / atlasHeight;
v0 = (textureRect.origin.y + texStrech) / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.width - texStrech) / atlasHeight;
}
else {
u0 = textureRect.origin.x / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.width) / atlasWidth;
u0 = (textureRect.origin.x + texStrech) / atlasWidth;
u3 = (textureRect.origin.x + textureRect.size.width - texStrech) / atlasWidth;
v0 = textureRect.origin.y / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.height) / atlasHeight;
v0 = (textureRect.origin.y + texStrech) / atlasHeight;
v3 = (textureRect.origin.y + textureRect.size.height - texStrech) / atlasHeight;
}
this->_uvs[0].x = u0;