/** initilizes the texture with a rectangle measured Points */ public void initTexCoordsWithRect(CCRect pointRect) { // convert to pixels coords CCRect rect = new CCRect( pointRect.Origin.X * Director.SharedDirector.ContentScaleFactor, pointRect.Origin.Y * Director.SharedDirector.ContentScaleFactor, pointRect.Size.Width * Director.SharedDirector.ContentScaleFactor, pointRect.Size.Height * Director.SharedDirector.ContentScaleFactor); float wide = pointRect.Size.Width; float high = pointRect.Size.Height; if (this.Texture != null) { wide = this.Texture.Width; high = this.Texture.Height; } //#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL // GLfloat left = (rect.origin.x*2+1) / (wide*2); // GLfloat bottom = (rect.origin.y*2+1) / (high*2); // GLfloat right = left + (rect.size.width*2-2) / (wide*2); // GLfloat top = bottom + (rect.size.height*2-2) / (high*2); //#else float left = rect.Origin.X / wide; float bottom = rect.Origin.Y / high; float right = left + rect.Size.Width / wide; float top = bottom + rect.Size.Height / high; // #endif // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL // Important. Texture in cocos2d are inverted, so the Y component should be inverted ccMacros.CC_SWAP <float>(ref top, ref bottom); for (uint i = 0; i < this.TotalParticles; i++) { m_pQuads[i] = new ccV2F_C4B_T2F_Quad(); // bottom-left vertex: m_pQuads[i].bl.texCoords.u = left; m_pQuads[i].bl.texCoords.v = bottom; // bottom-right vertex: m_pQuads[i].br.texCoords.u = right; m_pQuads[i].br.texCoords.v = bottom; // top-left vertex: m_pQuads[i].tl.texCoords.u = left; m_pQuads[i].tl.texCoords.v = top; // top-right vertex: m_pQuads[i].tr.texCoords.u = right; m_pQuads[i].tr.texCoords.v = top; } }
public override void updateQuadWithParticle(CCParticle particle, CCPoint newPosition) { ccV2F_C4B_T2F_Quad quad = this.m_pQuads[base.m_uParticleIdx]; ccColor4B colorb = new ccColor4B((byte)(particle.color.r * 255f), (byte)(particle.color.g * 255f), (byte)(particle.color.b * 255f), (byte)(particle.color.a * 255f)); quad.bl.colors = colorb; quad.br.colors = colorb; quad.tl.colors = colorb; quad.tr.colors = colorb; float num = particle.size / 2f; if (particle.rotation != 0f) { float num2 = -num; float num3 = -num; float num4 = num; float num5 = num; float x = newPosition.x; float y = newPosition.y; float num8 = -ccMacros.CC_DEGREES_TO_RADIANS(particle.rotation); float num9 = (float)Math.Cos((double)num8); float num10 = (float)Math.Sin((double)num8); float num11 = ((num2 * num9) - (num3 * num10)) + x; float num12 = ((num2 * num10) + (num3 * num9)) + y; float num13 = ((num4 * num9) - (num3 * num10)) + x; float num14 = ((num4 * num10) + (num3 * num9)) + y; float num15 = ((num4 * num9) - (num5 * num10)) + x; float num16 = ((num4 * num10) + (num5 * num9)) + y; float num17 = ((num2 * num9) - (num5 * num10)) + x; float num18 = ((num2 * num10) + (num5 * num9)) + y; quad.bl.vertices.x = num11; quad.bl.vertices.y = num12; quad.br.vertices.x = num13; quad.br.vertices.y = num14; quad.tl.vertices.x = num17; quad.tl.vertices.y = num18; quad.tr.vertices.x = num15; quad.tr.vertices.y = num16; } else { quad.bl.vertices.x = newPosition.x - num; quad.bl.vertices.y = newPosition.y - num; quad.br.vertices.x = newPosition.x + num; quad.br.vertices.y = newPosition.y - num; quad.tl.vertices.x = newPosition.x - num; quad.tl.vertices.y = newPosition.y + num; quad.tr.vertices.x = newPosition.x + num; quad.tr.vertices.y = newPosition.y + num; } }
/** initilizes the texture with a rectangle measured Points */ public void initTexCoordsWithRect(CCRect pointRect) { // convert to pixels coords CCRect rect = new CCRect( pointRect.origin.x * CCDirector.sharedDirector().ContentScaleFactor, pointRect.origin.y * CCDirector.sharedDirector().ContentScaleFactor, pointRect.size.width * CCDirector.sharedDirector().ContentScaleFactor, pointRect.size.height * CCDirector.sharedDirector().ContentScaleFactor); float wide = pointRect.size.width; float high = pointRect.size.height; if (this.Texture != null) { wide = this.Texture.PixelsWide; high = this.Texture.PixelsHigh; } //#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL // GLfloat left = (rect.origin.x*2+1) / (wide*2); // GLfloat bottom = (rect.origin.y*2+1) / (high*2); // GLfloat right = left + (rect.size.width*2-2) / (wide*2); // GLfloat top = bottom + (rect.size.height*2-2) / (high*2); //#else float left = rect.origin.x / wide; float bottom = rect.origin.y / high; float right = left + rect.size.width / wide; float top = bottom + rect.size.height / high; // #endif // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL // Important. Texture in cocos2d are inverted, so the Y component should be inverted ccMacros.CC_SWAP<float>(ref top, ref bottom); for(uint i=0; i<this.TotalParticles; i++) { m_pQuads[i] = new ccV2F_C4B_T2F_Quad(); // bottom-left vertex: m_pQuads[i].bl.texCoords.u = left; m_pQuads[i].bl.texCoords.v = bottom; // bottom-right vertex: m_pQuads[i].br.texCoords.u = right; m_pQuads[i].br.texCoords.v = bottom; // top-left vertex: m_pQuads[i].tl.texCoords.u = left; m_pQuads[i].tl.texCoords.v = top; // top-right vertex: m_pQuads[i].tr.texCoords.u = right; m_pQuads[i].tr.texCoords.v = top; } }
public override void updateQuadWithParticle(CCParticle particle, CCPoint newPosition) { // colors ccV2F_C4B_T2F_Quad quad = m_pQuads[m_uParticleIdx]; ccColor4B color = new ccColor4B((Byte)(particle.color.r * 255), (Byte)(particle.color.g * 255), (Byte)(particle.color.b * 255), (Byte)(particle.color.a * 255)); quad.bl.colors = color; quad.br.colors = color; quad.tl.colors = color; quad.tr.colors = color; // vertices float size_2 = particle.size / 2; if (particle.rotation != 0) { float x1 = -size_2; float y1 = -size_2; float x2 = size_2; float y2 = size_2; float x = newPosition.X; float y = newPosition.Y; float r = -CCUtils.CC_DEGREES_TO_RADIANS(particle.rotation); float cr = (float)System.Math.Cos(r); float sr = (float)System.Math.Sin(r); float ax = x1 * cr - y1 * sr + x; float ay = x1 * sr + y1 * cr + y; float bx = x2 * cr - y1 * sr + x; float by = x2 * sr + y1 * cr + y; float cx = x2 * cr - y2 * sr + x; float cy = x2 * sr + y2 * cr + y; float dx = x1 * cr - y2 * sr + x; float dy = x1 * sr + y2 * cr + y; // bottom-left quad.bl.vertices.x = ax; quad.bl.vertices.y = ay; // bottom-right vertex: quad.br.vertices.x = bx; quad.br.vertices.y = by; // top-left vertex: quad.tl.vertices.x = dx; quad.tl.vertices.y = dy; // top-right vertex: quad.tr.vertices.x = cx; quad.tr.vertices.y = cy; } else { // bottom-left vertex: quad.bl.vertices.x = newPosition.X - size_2; quad.bl.vertices.y = newPosition.Y - size_2; // bottom-right vertex: quad.br.vertices.x = newPosition.X + size_2; quad.br.vertices.y = newPosition.Y - size_2; // top-left vertex: quad.tl.vertices.x = newPosition.X - size_2; quad.tl.vertices.y = newPosition.Y + size_2; // top-right vertex: quad.tr.vertices.x = newPosition.X + size_2; quad.tr.vertices.y = newPosition.Y + size_2; } }