pointRect should be in Texture coordinates, not pixel coordinates
| 147 | |
| 148 | // pointRect should be in Texture coordinates, not pixel coordinates |
| 149 | void ParticleSystemQuad::initTexCoordsWithRect(const Rect& pointRect) |
| 150 | { |
| 151 | // convert to Tex coords |
| 152 | |
| 153 | Rect rect = |
| 154 | Rect(pointRect.origin.x * AX_CONTENT_SCALE_FACTOR(), pointRect.origin.y * AX_CONTENT_SCALE_FACTOR(), |
| 155 | pointRect.size.width * AX_CONTENT_SCALE_FACTOR(), pointRect.size.height * AX_CONTENT_SCALE_FACTOR()); |
| 156 | |
| 157 | float wide = (float)pointRect.size.width; |
| 158 | float high = (float)pointRect.size.height; |
| 159 | |
| 160 | if (_texture) |
| 161 | { |
| 162 | wide = (float)_texture->getPixelsWide(); |
| 163 | high = (float)_texture->getPixelsHigh(); |
| 164 | } |
| 165 | |
| 166 | #if AX_FIX_ARTIFACTS_BY_STRECHING_TEXEL |
| 167 | float left = (rect.origin.x * 2 + 1) / (wide * 2); |
| 168 | float bottom = (rect.origin.y * 2 + 1) / (high * 2); |
| 169 | float right = left + (rect.size.width * 2 - 2) / (wide * 2); |
| 170 | float top = bottom + (rect.size.height * 2 - 2) / (high * 2); |
| 171 | #else |
| 172 | float left = rect.origin.x / wide; |
| 173 | float bottom = rect.origin.y / high; |
| 174 | float right = left + rect.size.width / wide; |
| 175 | float top = bottom + rect.size.height / high; |
| 176 | #endif // ! AX_FIX_ARTIFACTS_BY_STRECHING_TEXEL |
| 177 | |
| 178 | // Important. Texture in axmol are inverted, so the Y component should be inverted |
| 179 | std::swap(top, bottom); |
| 180 | |
| 181 | V3F_C4B_T2F_Quad* quads = nullptr; |
| 182 | unsigned int start = 0, end = 0; |
| 183 | if (_batchNode) |
| 184 | { |
| 185 | quads = _batchNode->getTextureAtlas()->getQuads(); |
| 186 | start = _atlasIndex; |
| 187 | end = _atlasIndex + _totalParticles; |
| 188 | } |
| 189 | else |
| 190 | { |
| 191 | quads = _quads; |
| 192 | start = 0; |
| 193 | end = _totalParticles; |
| 194 | } |
| 195 | |
| 196 | for (unsigned int i = start; i < end; i++) |
| 197 | { |
| 198 | // bottom-left vertex: |
| 199 | quads[i].bl.texCoords.u = left; |
| 200 | quads[i].bl.texCoords.v = bottom; |
| 201 | // bottom-right vertex: |
| 202 | quads[i].br.texCoords.u = right; |
| 203 | quads[i].br.texCoords.v = bottom; |
| 204 | // top-left vertex: |
| 205 | quads[i].tl.texCoords.u = left; |
| 206 | quads[i].tl.texCoords.v = top; |
no test coverage detected