public void copy(CCParticle particleCopied) { this.pos.x = particleCopied.pos.x; this.pos.y = particleCopied.pos.y; this.startPos.x = particleCopied.startPos.x; this.startPos.y = particleCopied.startPos.y; this.color.r = particleCopied.color.r; this.color.g = particleCopied.color.g; this.color.b = particleCopied.color.b; this.color.a = particleCopied.color.a; this.deltaColor.r = particleCopied.deltaColor.r; this.deltaColor.g = particleCopied.deltaColor.g; this.deltaColor.b = particleCopied.deltaColor.b; this.deltaColor.a = particleCopied.deltaColor.a; this.size = particleCopied.size; this.deltaSize = particleCopied.deltaSize; this.rotation = particleCopied.rotation; this.deltaRotation = particleCopied.deltaRotation; this.timeToLive = particleCopied.timeToLive; this.modeA.dir.x = particleCopied.modeA.dir.x; this.modeA.dir.y = particleCopied.modeA.dir.y; this.modeA.radialAccel = particleCopied.modeA.radialAccel; this.modeA.tangentialAccel = particleCopied.modeA.tangentialAccel; this.modeB.angle = particleCopied.modeB.angle; this.modeB.degreesPerSecond = particleCopied.modeB.degreesPerSecond; this.modeB.radius = particleCopied.modeB.radius; this.modeB.deltaRadius = particleCopied.modeB.deltaRadius; }
public override void draw() { base.draw(); BlendState blendState = CCApplication.sharedApplication().GraphicsDevice.BlendState; BlendState alphaBlend = BlendState.AlphaBlend; if (base.IsBlendAdditive) { alphaBlend = BlendState.Additive; } CCApplication.sharedApplication().spriteBatch.Begin(SpriteSortMode.Deferred, alphaBlend); for (int i = 0; i < base.ParticleCount; i++) { CCParticle particle = base.m_pParticles[i]; CCPoint obPoint = CCPointExtension.ccpAdd(CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(), base.nodeToWorldTransform()), new CCPoint(this.m_pQuads[i].bl.vertices.x, this.m_pQuads[i].bl.vertices.y)); obPoint = CCDirector.sharedDirector().convertToUI(obPoint); Vector2 position = new Vector2(obPoint.x, obPoint.y); Color color = new Color(particle.color.r, particle.color.g, particle.color.b, particle.color.a); float scale = 1f; if (this.Texture.getTexture2D().Width > this.Texture.getTexture2D().Height) { scale = particle.size / ((float)this.Texture.getTexture2D().Height); } else { scale = particle.size / ((float)this.Texture.getTexture2D().Width); } float rotation = particle.rotation; Vector2 origin = new Vector2((float)(this.Texture.getTexture2D().Width / 2), (float)(this.Texture.getTexture2D().Height / 2)); Rectangle?sourceRectangle = null; CCApplication.sharedApplication().spriteBatch.Draw(this.Texture.getTexture2D(), position, sourceRectangle, color, rotation, origin, scale, SpriteEffects.None, 0f); } CCApplication.sharedApplication().spriteBatch.End(); CCApplication.sharedApplication().GraphicsDevice.BlendState = blendState; }
public override void updateQuadWithParticle(CCParticle particle, CCPoint newPosition) { this.m_pVertices[base.m_uParticleIdx].pos = ccTypes.vertex2(newPosition.x, newPosition.y); this.m_pVertices[base.m_uParticleIdx].size = particle.size; ccColor4B colorb = new ccColor4B((byte)(particle.color.r * 255f), (byte)(particle.color.g * 255f), (byte)(particle.color.b * 255f), (byte)(particle.color.a * 255f)); this.m_pVertices[base.m_uParticleIdx].color = colorb; }
public override void updateQuadWithParticle(CCParticle particle, CCPoint newPosition) { // place vertices and colos in array m_pVertices[m_uParticleIdx].pos = ccTypes.vertex2(newPosition.x, newPosition.y); m_pVertices[m_uParticleIdx].size = particle.size; ccColor4B color = new ccColor4B((Byte)(particle.color.r * 255), (Byte)(particle.color.g * 255), (Byte)(particle.color.b * 255), (Byte)(particle.color.a * 255)); m_pVertices[m_uParticleIdx].color = color; }
public bool addParticle() { if (this.isFull()) { return(false); } CCParticle particle = this.m_pParticles[this.m_uParticleCount]; this.initParticle(particle); this.m_uParticleCount++; return(true); }
public void resetSystem() { this.m_bIsActive = true; this.m_fElapsed = 0f; this.m_uParticleIdx = 0; while (this.m_uParticleIdx < this.m_uParticleCount) { CCParticle particle = this.m_pParticles[this.m_uParticleIdx]; particle.timeToLive = 0f; this.m_uParticleIdx++; } }
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; } }
//! should be overriden by subclasses public virtual void updateQuadWithParticle(CCParticle particle, CCPoint newPosition) { // should be overriden }
public void copy(CCParticle particleCopied) { pos.x = particleCopied.pos.x; pos.y = particleCopied.pos.y; startPos.x = particleCopied.startPos.x; startPos.y = particleCopied.startPos.y; color.r = particleCopied.color.r; color.g = particleCopied.color.g; color.b = particleCopied.color.b; color.a = particleCopied.color.a; deltaColor.r = particleCopied.deltaColor.r; deltaColor.g = particleCopied.deltaColor.g; deltaColor.b = particleCopied.deltaColor.b; deltaColor.a = particleCopied.deltaColor.a; size = particleCopied.size; deltaSize = particleCopied.deltaSize; rotation = particleCopied.rotation; deltaRotation = particleCopied.deltaRotation; timeToLive = particleCopied.timeToLive; // modeA modeA.dir.x = particleCopied.modeA.dir.x; modeA.dir.y = particleCopied.modeA.dir.y; modeA.radialAccel = particleCopied.modeA.radialAccel; modeA.tangentialAccel = particleCopied.modeA.tangentialAccel; // mocdB modeB.angle = particleCopied.modeB.angle; modeB.degreesPerSecond = particleCopied.modeB.degreesPerSecond; modeB.radius = particleCopied.modeB.radius; modeB.deltaRadius = particleCopied.modeB.deltaRadius; }
//! Initializes a system with a fixed number of particles public virtual bool initWithTotalParticles(uint numberOfParticles) { m_uTotalParticles = numberOfParticles; m_pParticles = new CCParticle[m_uTotalParticles]; if (null == m_pParticles) { Debug.WriteLine("Particle system: not enough memory"); return false; } for (int i = 0; i < m_uTotalParticles; i++) { m_pParticles[i] = new CCParticle(); } // default, active m_bIsActive = true; // default blend function m_tBlendFunc.src = 1;// CC_BLEND_SRC; m_tBlendFunc.dst = 0x0303;// CC_BLEND_DST; // default movement type; m_ePositionType = eParticlePositionType.kCCPositionTypeFree; // by default be in mode A: m_nEmitterMode = (int)eParticleMode.kCCParticleModeGravity; // default: modulate // XXX: not used // colorModulate = YES; m_bIsAutoRemoveOnFinish = false; // profiling #if CC_ENABLE_PROFILERS /// @todo _profilingTimer = [[CCProfiler timerWithName:@"particle system" andInstance:self] retain]; #endif // Optimization: compile udpateParticle method //updateParticleSel = @selector(updateQuadWithParticle:newPosition:); //updateParticleImp = (CC_UPDATE_PARTICLE_IMP) [self methodForSelector:updateParticleSel]; // udpate after action in run! this.scheduleUpdateWithPriority(1); return true; }
public override void draw() { base.draw(); BlendState oldBlendState = Application.SharedApplication.GraphicsDevice.BlendState; BlendState eBlendState = BlendState.AlphaBlend; if (this.IsBlendAdditive) { eBlendState = BlendState.Additive; } Application.SharedApplication.SpriteBatch.Begin(SpriteSortMode.Deferred, eBlendState); for (int i = 0; i < this.ParticleCount; i++) { CCParticle particle = m_pParticles[i]; CCPoint uiPoint = CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(), this.nodeToWorldTransform()); uiPoint = CCPointExtension.ccpAdd(uiPoint, new CCPoint(m_pQuads[i].bl.vertices.x, m_pQuads[i].bl.vertices.y)); uiPoint = Director.SharedDirector.ConvertToUI(uiPoint); Vector2 vecPosition = new Vector2(uiPoint.X, uiPoint.Y); Color color = new Color(particle.color.r, particle.color.g, particle.color.b, particle.color.a); float scale = 1.0f; if (Texture.Texture2D.Width > Texture.Texture2D.Height) { scale = particle.size / Texture.Texture2D.Height; } else { scale = particle.size / Texture.Texture2D.Width; } float rotation = particle.rotation; Vector2 origin = new Vector2(Texture.Texture2D.Width / 2, Texture.Texture2D.Height / 2); Application.SharedApplication.SpriteBatch.Draw(this.Texture.Texture2D, vecPosition, null, color, rotation, origin, scale, SpriteEffects.None, 0); //CCPoint uiPoint = CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(), this.nodeToWorldTransform()); //uiPoint.x += m_pQuads[i].bl.vertices.x; //uiPoint.y += m_pQuads[i].bl.vertices.y; //uiPoint = CCDirector.sharedDirector().convertToUI(uiPoint); //Vector2 vecPosition = new Vector2(uiPoint.x, uiPoint.y); //Color color = new Color(m_pQuads[i].bl.colors.r, // m_pQuads[i].bl.colors.g, // m_pQuads[i].bl.colors.b, // m_pQuads[i].bl.colors.a); //Vector2 origin = new Vector2(Texture.Texture2D.Width/2, Texture.Texture2D.Height/2); //Application.SharedApplication.SpriteBatch.Draw(this.Texture.Texture2D, vecPosition, null, color, 0, origin, 1.0f, SpriteEffects.None, 0); } Application.SharedApplication.SpriteBatch.End(); Application.SharedApplication.GraphicsDevice.BlendState = oldBlendState; // // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY // // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY // // Unneeded states: - // glBindTexture(GL_TEXTURE_2D, m_pTexture->getName()); // #define kQuadSize sizeof(m_pQuads[0].bl) // int offset = (int) m_pQuads; // // vertex // int diff = offsetof( ccV2F_C4B_T2F, vertices); // glVertexPointer(2,GL_FLOAT, kQuadSize, (GLvoid*) (offset+diff) ); // // color // diff = offsetof( ccV2F_C4B_T2F, colors); // glColorPointer(4, GL_UNSIGNED_BYTE, kQuadSize, (GLvoid*)(offset + diff)); // // tex coords // diff = offsetof( ccV2F_C4B_T2F, texCoords); // glTexCoordPointer(2, GL_FLOAT, kQuadSize, (GLvoid*)(offset + diff)); // bool newBlend = (m_tBlendFunc.src != CC_BLEND_SRC || m_tBlendFunc.dst != CC_BLEND_DST) ? true : false; // if( newBlend ) // { // glBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst ); // } // CCAssert( m_uParticleIdx == m_uParticleCount, "Abnormal error in particle quad"); // glDrawElements(GL_TRIANGLES, (GLsizei)(m_uParticleIdx*6), GL_UNSIGNED_SHORT, m_pIndices); // // restore blend state // if( newBlend ) // glBlendFunc( CC_BLEND_SRC, CC_BLEND_DST ); //#if CC_USES_VBO // glBindBuffer(GL_ARRAY_BUFFER, 0); //#endif }
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; } }
private void UpdateQuad(ref CCV3F_C4B_T2F_Quad quad, ref CCParticle particle) { CCPoint newPosition; if (m_ePositionType == CCPositionType.kCCPositionTypeFree || m_ePositionType == CCPositionType.kCCPositionTypeRelative) { newPosition.X = particle.pos.X - (s_currentPosition.X - particle.startPos.X); newPosition.Y = particle.pos.Y - (s_currentPosition.Y - particle.startPos.Y); } else { newPosition = particle.pos; } // translate newPos to correct position, since matrix transform isn't performed in batchnode // don't update the particle with the new position information, it will interfere with the radius and tangential calculations if (m_pBatchNode != null) { newPosition.X += m_tPosition.X; newPosition.Y += m_tPosition.Y; } CCColor4B color; if (m_bOpacityModifyRGB) { color.R = (byte) (particle.color.R * particle.color.A * 255); color.G = (byte) (particle.color.G * particle.color.A * 255); color.B = (byte) (particle.color.B * particle.color.A * 255); color.A = (byte)(particle.color.A * 255); } else { color.R = (byte)(particle.color.R * 255); color.G = (byte)(particle.color.G * 255); color.B = (byte)(particle.color.B * 255); color.A = (byte)(particle.color.A * 255); } quad.BottomLeft.Colors = color; quad.BottomRight.Colors = color; quad.TopLeft.Colors = color; quad.TopRight.Colors = color; // vertices float size_2 = particle.size / 2; if (particle.rotation != 0.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 = -MathHelper.ToRadians(particle.rotation); float cr = MHelper.Cos(r); float sr = MHelper.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.BottomLeft.Vertices.X = ax; quad.BottomLeft.Vertices.Y = ay; // bottom-right vertex: quad.BottomRight.Vertices.X = bx; quad.BottomRight.Vertices.Y = by; // top-left vertex: quad.TopLeft.Vertices.X = dx; quad.TopLeft.Vertices.Y = dy; // top-right vertex: quad.TopRight.Vertices.X = cx; quad.TopRight.Vertices.Y = cy; } else { // bottom-left vertex: quad.BottomLeft.Vertices.X = newPosition.X - size_2; quad.BottomLeft.Vertices.Y = newPosition.Y - size_2; // bottom-right vertex: quad.BottomRight.Vertices.X = newPosition.X + size_2; quad.BottomRight.Vertices.Y = newPosition.Y - size_2; // top-left vertex: quad.TopLeft.Vertices.X = newPosition.X - size_2; quad.TopLeft.Vertices.Y = newPosition.Y + size_2; // top-right vertex: quad.TopRight.Vertices.X = newPosition.X + size_2; quad.TopRight.Vertices.Y = newPosition.Y + size_2; } }
private bool UpdateParticle(ref CCParticle p, float dt) { // life p.timeToLive -= dt; if (p.timeToLive > 0) { // Mode A: gravity, direction, tangential accel & radial accel if (m_nEmitterMode == CCEmitterMode.kCCParticleModeGravity) { float radial_x = 0; float radial_y = 0; float tmp_x, tmp_y; float tangential_x, tangential_y; float x = p.pos.X; float y = p.pos.Y; if (x != 0 || y != 0) { float l = 1.0f / (float) Math.Sqrt(x * x + y * y); radial_x = x * l; radial_y = y * l; } tangential_x = radial_x; tangential_y = radial_y; //radial = CCPointExtension.ccpMult(radial, p.modeA.radialAccel); radial_x *= p.modeA.radialAccel; radial_y *= p.modeA.radialAccel; // tangential acceleration float newy = tangential_x; tangential_x = -tangential_y; tangential_y = newy; //tangential = CCPointExtension.ccpMult(tangential, p.modeA.tangentialAccel); tangential_x *= p.modeA.tangentialAccel; tangential_y *= p.modeA.tangentialAccel; // (gravity + radial + tangential) * dt //tmp = CCPointExtension.ccpAdd(CCPointExtension.ccpAdd(radial, tangential), modeA.gravity); //tmp = CCPointExtension.ccpMult(tmp, dt); //p.modeA.dir = CCPointExtension.ccpAdd(p.modeA.dir, tmp); //tmp = CCPointExtension.ccpMult(p.modeA.dir, dt); //p.pos = CCPointExtension.ccpAdd(p.pos, tmp); tmp_x = (radial_x + tangential_x + modeA.gravity.X) * dt; tmp_y = (radial_y + tangential_y + modeA.gravity.Y) * dt; p.modeA.dir.X += tmp_x; p.modeA.dir.Y += tmp_y; p.pos.X += p.modeA.dir.X * dt; p.pos.Y += p.modeA.dir.Y * dt; } // Mode B: radius movement else { // Update the angle and radius of the particle. p.modeB.angle += p.modeB.degreesPerSecond * dt; p.modeB.radius += p.modeB.deltaRadius * dt; p.pos.X = -MHelper.Cos(p.modeB.angle) * p.modeB.radius; p.pos.Y = -MHelper.Sin(p.modeB.angle) * p.modeB.radius; } // color p.color.R += (p.deltaColor.R * dt); p.color.G += (p.deltaColor.G * dt); p.color.B += (p.deltaColor.B * dt); p.color.A += (p.deltaColor.A * dt); // size p.size += (p.deltaSize * dt); if (p.size < 0) { p.size = 0; } // angle p.rotation += (p.deltaRotation * dt); return true; } return false; }
//! Initializes a particle public void initParticle(CCParticle particle) { Debug.Assert(null != particle, "particle shouldn't be null."); // timeToLive // no negative life. prevent division by 0 particle.timeToLive = m_fLife + m_fLifeVar * ccMacros.CCRANDOM_MINUS1_1(); particle.timeToLive = (((0) > (particle.timeToLive)) ? (0) : (particle.timeToLive)); // position particle.pos.x = m_tSourcePosition.x + m_tPosVar.x * ccMacros.CCRANDOM_MINUS1_1(); particle.pos.x *= CCDirector.sharedDirector().ContentScaleFactor; particle.pos.y = m_tSourcePosition.y + m_tPosVar.y * ccMacros.CCRANDOM_MINUS1_1(); particle.pos.y *= CCDirector.sharedDirector().ContentScaleFactor; // Color ccColor4F start = new ccColor4F(); start.r = CCPointExtension.clampf(m_tStartColor.r + m_tStartColorVar.r * ccMacros.CCRANDOM_MINUS1_1(), 0, 1); start.g = CCPointExtension.clampf(m_tStartColor.g + m_tStartColorVar.g * ccMacros.CCRANDOM_MINUS1_1(), 0, 1); start.b = CCPointExtension.clampf(m_tStartColor.b + m_tStartColorVar.b * ccMacros.CCRANDOM_MINUS1_1(), 0, 1); start.a = CCPointExtension.clampf(m_tStartColor.a + m_tStartColorVar.a * ccMacros.CCRANDOM_MINUS1_1(), 0, 1); ccColor4F end = new ccColor4F(); end.r = CCPointExtension.clampf(m_tEndColor.r + m_tEndColorVar.r * ccMacros.CCRANDOM_MINUS1_1(), 0, 1); end.g = CCPointExtension.clampf(m_tEndColor.g + m_tEndColorVar.g * ccMacros.CCRANDOM_MINUS1_1(), 0, 1); end.b = CCPointExtension.clampf(m_tEndColor.b + m_tEndColorVar.b * ccMacros.CCRANDOM_MINUS1_1(), 0, 1); end.a = CCPointExtension.clampf(m_tEndColor.a + m_tEndColorVar.a * ccMacros.CCRANDOM_MINUS1_1(), 0, 1); particle.color = start; particle.deltaColor.r = (end.r - start.r) / particle.timeToLive; particle.deltaColor.g = (end.g - start.g) / particle.timeToLive; particle.deltaColor.b = (end.b - start.b) / particle.timeToLive; particle.deltaColor.a = (end.a - start.a) / particle.timeToLive; // size float startS = m_fStartSize + m_fStartSizeVar * ccMacros.CCRANDOM_MINUS1_1(); startS = (((0) > (startS)) ? (0) : (startS)); // No negative value startS *= CCDirector.sharedDirector().ContentScaleFactor; particle.size = startS; if( m_fEndSize == (float)eParticleShowingProperty.kCCParticleStartSizeEqualToEndSize ) { particle.deltaSize = 0; } else { float endS = m_fEndSize + m_fEndSizeVar * ccMacros.CCRANDOM_MINUS1_1(); endS = (((0) > (endS)) ? (0) : (endS)); // No negative values endS *= CCDirector.sharedDirector().ContentScaleFactor; particle.deltaSize = (endS - startS) / particle.timeToLive; } // rotation float startA = m_fStartSpin + m_fStartSpinVar * ccMacros.CCRANDOM_MINUS1_1(); float endA = m_fEndSpin + m_fEndSpinVar * ccMacros.CCRANDOM_MINUS1_1(); particle.rotation = startA; particle.deltaRotation = (endA - startA) / particle.timeToLive; // position if( m_ePositionType == eParticlePositionType.kCCPositionTypeFree ) { CCPoint p = this.convertToWorldSpace(new CCPoint(0,0)); particle.startPos = CCPointExtension.ccpMult( p, CCDirector.sharedDirector().ContentScaleFactor ); } else if ( m_ePositionType == eParticlePositionType.kCCPositionTypeRelative ) { particle.startPos = CCPointExtension.ccpMult( m_tPosition, CCDirector.sharedDirector().ContentScaleFactor ); } // direction float a = ccMacros.CC_DEGREES_TO_RADIANS(m_fAngle + m_fAngleVar * ccMacros.CCRANDOM_MINUS1_1()); // Mode Gravity: A if( m_nEmitterMode == (int)eParticleMode.kCCParticleModeGravity ) { CCPoint v = new CCPoint( (float)System.Math.Cos( a ), (float)System.Math.Sin( a )); float s = modeA.speed + modeA.speedVar * ccMacros.CCRANDOM_MINUS1_1(); s *= CCDirector.sharedDirector().ContentScaleFactor; // direction particle.modeA.dir = CCPointExtension.ccpMult( v, s ); // radial accel particle.modeA.radialAccel = modeA.radialAccel + modeA.radialAccelVar * ccMacros.CCRANDOM_MINUS1_1(); particle.modeA.radialAccel *= CCDirector.sharedDirector().ContentScaleFactor; // tangential accel particle.modeA.tangentialAccel = modeA.tangentialAccel + modeA.tangentialAccelVar * ccMacros.CCRANDOM_MINUS1_1(); particle.modeA.tangentialAccel *= CCDirector.sharedDirector().ContentScaleFactor; } // Mode Radius: B else { // Set the default diameter of the particle from the source position float startRadius = modeB.startRadius + modeB.startRadiusVar * ccMacros.CCRANDOM_MINUS1_1(); float endRadius = modeB.endRadius + modeB.endRadiusVar * ccMacros.CCRANDOM_MINUS1_1(); startRadius *= CCDirector.sharedDirector().ContentScaleFactor; endRadius *= CCDirector.sharedDirector().ContentScaleFactor; particle.modeB.radius = startRadius; if( modeB.endRadius == (float)eParticleShowingProperty.kCCParticleStartRadiusEqualToEndRadius ) particle.modeB.deltaRadius = 0; else particle.modeB.deltaRadius = (endRadius - startRadius) / particle.timeToLive; particle.modeB.angle = a; particle.modeB.degreesPerSecond = ccMacros.CC_DEGREES_TO_RADIANS(modeB.rotatePerSecond + modeB.rotatePerSecondVar * ccMacros.CCRANDOM_MINUS1_1()); } }
public virtual void updateQuadWithParticle(CCParticle particle, CCPoint newPosition) { }
public override void update(float dt) { if (this.m_bIsActive && (this.m_fEmissionRate != 0f)) { float num = 1f / this.m_fEmissionRate; this.m_fEmitCounter += dt; while ((this.m_uParticleCount < this.m_uTotalParticles) && (this.m_fEmitCounter > num)) { this.addParticle(); this.m_fEmitCounter -= num; } this.m_fElapsed += dt; if ((this.m_fDuration != -1f) && (this.m_fDuration < this.m_fElapsed)) { this.stopSystem(); } } this.m_uParticleIdx = 0; CCPoint tPosition = new CCPoint(0f, 0f); if (this.m_ePositionType == eParticlePositionType.kCCPositionTypeFree) { tPosition = base.convertToWorldSpace(new CCPoint(0f, 0f)); tPosition.x *= CCDirector.sharedDirector().ContentScaleFactor; tPosition.y *= CCDirector.sharedDirector().ContentScaleFactor; } else if (this.m_ePositionType == eParticlePositionType.kCCPositionTypeRelative) { tPosition = base.m_tPosition; tPosition.x *= CCDirector.sharedDirector().ContentScaleFactor; tPosition.y *= CCDirector.sharedDirector().ContentScaleFactor; } while (this.m_uParticleIdx < this.m_uParticleCount) { CCParticle particle = this.m_pParticles[this.m_uParticleIdx]; particle.timeToLive -= dt; if (particle.timeToLive > 0f) { CCPoint pos; if (this.m_nEmitterMode == 0) { CCPoint v = new CCPoint(0f, 0f); if ((particle.pos.x != 0f) || (particle.pos.y != 0f)) { v = CCPointExtension.ccpNormalize(particle.pos); } CCPoint point4 = v; v = CCPointExtension.ccpMult(v, particle.modeA.radialAccel); float x = point4.x; point4.x = -point4.y; point4.y = x; point4 = CCPointExtension.ccpMult(point4, particle.modeA.tangentialAccel); CCPoint point2 = CCPointExtension.ccpMult(CCPointExtension.ccpAdd(CCPointExtension.ccpAdd(v, point4), this.modeA.gravity), dt); particle.modeA.dir = CCPointExtension.ccpAdd(particle.modeA.dir, point2); point2 = CCPointExtension.ccpMult(particle.modeA.dir, dt); particle.pos = CCPointExtension.ccpAdd(particle.pos, point2); } else { particle.modeB.angle += particle.modeB.degreesPerSecond * dt; particle.modeB.radius += particle.modeB.deltaRadius * dt; particle.pos.x = -((float)Math.Cos((double)particle.modeB.angle)) * particle.modeB.radius; particle.pos.y = -((float)Math.Sin((double)particle.modeB.angle)) * particle.modeB.radius; } particle.color.r += particle.deltaColor.r * dt; particle.color.g += particle.deltaColor.g * dt; particle.color.b += particle.deltaColor.b * dt; particle.color.a += particle.deltaColor.a * dt; particle.size += particle.deltaSize * dt; particle.size = (0f > particle.size) ? 0f : particle.size; particle.rotation += particle.deltaRotation * dt; if ((this.m_ePositionType == eParticlePositionType.kCCPositionTypeFree) || (this.m_ePositionType == eParticlePositionType.kCCPositionTypeRelative)) { CCPoint point6 = CCPointExtension.ccpSub(tPosition, particle.startPos); pos = CCPointExtension.ccpSub(particle.pos, point6); } else { pos = particle.pos; } this.updateQuadWithParticle(particle, pos); this.m_uParticleIdx++; } else { if (this.m_uParticleIdx != (this.m_uParticleCount - 1)) { this.m_pParticles[this.m_uParticleIdx].copy(this.m_pParticles[(int)((IntPtr)(this.m_uParticleCount - 1))]); } this.m_uParticleCount--; if ((this.m_uParticleCount == 0) && this.m_bIsAutoRemoveOnFinish) { base.unscheduleUpdate(); base.m_pParent.removeChild(this, true); return; } } } this.postStep(); }
public void initParticle(CCParticle particle) { particle.timeToLive = this.m_fLife + (this.m_fLifeVar * ccMacros.CCRANDOM_MINUS1_1()); particle.timeToLive = (0f > particle.timeToLive) ? 0f : particle.timeToLive; particle.pos.x = this.m_tSourcePosition.x + (this.m_tPosVar.x * ccMacros.CCRANDOM_MINUS1_1()); particle.pos.x *= CCDirector.sharedDirector().ContentScaleFactor; particle.pos.y = this.m_tSourcePosition.y + (this.m_tPosVar.y * ccMacros.CCRANDOM_MINUS1_1()); particle.pos.y *= CCDirector.sharedDirector().ContentScaleFactor; ccColor4F colorf = new ccColor4F { r = CCPointExtension.clampf(this.m_tStartColor.r + (this.m_tStartColorVar.r * ccMacros.CCRANDOM_MINUS1_1()), 0f, 1f), g = CCPointExtension.clampf(this.m_tStartColor.g + (this.m_tStartColorVar.g * ccMacros.CCRANDOM_MINUS1_1()), 0f, 1f), b = CCPointExtension.clampf(this.m_tStartColor.b + (this.m_tStartColorVar.b * ccMacros.CCRANDOM_MINUS1_1()), 0f, 1f), a = CCPointExtension.clampf(this.m_tStartColor.a + (this.m_tStartColorVar.a * ccMacros.CCRANDOM_MINUS1_1()), 0f, 1f) }; ccColor4F colorf2 = new ccColor4F { r = CCPointExtension.clampf(this.m_tEndColor.r + (this.m_tEndColorVar.r * ccMacros.CCRANDOM_MINUS1_1()), 0f, 1f), g = CCPointExtension.clampf(this.m_tEndColor.g + (this.m_tEndColorVar.g * ccMacros.CCRANDOM_MINUS1_1()), 0f, 1f), b = CCPointExtension.clampf(this.m_tEndColor.b + (this.m_tEndColorVar.b * ccMacros.CCRANDOM_MINUS1_1()), 0f, 1f), a = CCPointExtension.clampf(this.m_tEndColor.a + (this.m_tEndColorVar.a * ccMacros.CCRANDOM_MINUS1_1()), 0f, 1f) }; particle.color = colorf; particle.deltaColor.r = (colorf2.r - colorf.r) / particle.timeToLive; particle.deltaColor.g = (colorf2.g - colorf.g) / particle.timeToLive; particle.deltaColor.b = (colorf2.b - colorf.b) / particle.timeToLive; particle.deltaColor.a = (colorf2.a - colorf.a) / particle.timeToLive; float num = this.m_fStartSize + (this.m_fStartSizeVar * ccMacros.CCRANDOM_MINUS1_1()); num = (0f > num) ? 0f : num; num *= CCDirector.sharedDirector().ContentScaleFactor; particle.size = num; if (this.m_fEndSize == -1f) { particle.deltaSize = 0f; } else { float num2 = this.m_fEndSize + (this.m_fEndSizeVar * ccMacros.CCRANDOM_MINUS1_1()); num2 = (0f > num2) ? 0f : num2; num2 *= CCDirector.sharedDirector().ContentScaleFactor; particle.deltaSize = (num2 - num) / particle.timeToLive; } float num3 = this.m_fStartSpin + (this.m_fStartSpinVar * ccMacros.CCRANDOM_MINUS1_1()); float num4 = this.m_fEndSpin + (this.m_fEndSpinVar * ccMacros.CCRANDOM_MINUS1_1()); particle.rotation = num3; particle.deltaRotation = (num4 - num3) / particle.timeToLive; if (this.m_ePositionType == eParticlePositionType.kCCPositionTypeFree) { CCPoint v = base.convertToWorldSpace(new CCPoint(0f, 0f)); particle.startPos = CCPointExtension.ccpMult(v, CCDirector.sharedDirector().ContentScaleFactor); } else if (this.m_ePositionType == eParticlePositionType.kCCPositionTypeRelative) { particle.startPos = CCPointExtension.ccpMult(base.m_tPosition, CCDirector.sharedDirector().ContentScaleFactor); } float num5 = ccMacros.CC_DEGREES_TO_RADIANS(this.m_fAngle + (this.m_fAngleVar * ccMacros.CCRANDOM_MINUS1_1())); if (this.m_nEmitterMode == 0) { CCPoint point2 = new CCPoint((float)Math.Cos((double)num5), (float)Math.Sin((double)num5)); float s = this.modeA.speed + (this.modeA.speedVar * ccMacros.CCRANDOM_MINUS1_1()); s *= CCDirector.sharedDirector().ContentScaleFactor; particle.modeA.dir = CCPointExtension.ccpMult(point2, s); particle.modeA.radialAccel = this.modeA.radialAccel + (this.modeA.radialAccelVar * ccMacros.CCRANDOM_MINUS1_1()); particle.modeA.radialAccel *= CCDirector.sharedDirector().ContentScaleFactor; particle.modeA.tangentialAccel = this.modeA.tangentialAccel + (this.modeA.tangentialAccelVar * ccMacros.CCRANDOM_MINUS1_1()); particle.modeA.tangentialAccel *= CCDirector.sharedDirector().ContentScaleFactor; } else { float num7 = this.modeB.startRadius + (this.modeB.startRadiusVar * ccMacros.CCRANDOM_MINUS1_1()); float num8 = this.modeB.endRadius + (this.modeB.endRadiusVar * ccMacros.CCRANDOM_MINUS1_1()); num7 *= CCDirector.sharedDirector().ContentScaleFactor; num8 *= CCDirector.sharedDirector().ContentScaleFactor; particle.modeB.radius = num7; if (this.modeB.endRadius == -1f) { particle.modeB.deltaRadius = 0f; } else { particle.modeB.deltaRadius = (num8 - num7) / particle.timeToLive; } particle.modeB.angle = num5; particle.modeB.degreesPerSecond = ccMacros.CC_DEGREES_TO_RADIANS(this.modeB.rotatePerSecond + (this.modeB.rotatePerSecondVar * ccMacros.CCRANDOM_MINUS1_1())); } }
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 = - ccMacros.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; } }
private void InitParticle(ref CCParticle particle) { // timeToLive // no negative life. prevent division by 0 particle.timeToLive = Math.Max(0, m_fLife + m_fLifeVar * Random.Float_Minus1_1()); // position particle.pos.X = m_tSourcePosition.X + m_tPosVar.X * Random.Float_Minus1_1(); particle.pos.Y = m_tSourcePosition.Y + m_tPosVar.Y * Random.Float_Minus1_1(); // Color CCColor4F start; start.R = MathHelper.Clamp(m_tStartColor.R + m_tStartColorVar.R * Random.Float_Minus1_1(), 0, 1); start.G = MathHelper.Clamp(m_tStartColor.G + m_tStartColorVar.G * Random.Float_Minus1_1(), 0, 1); start.B = MathHelper.Clamp(m_tStartColor.B + m_tStartColorVar.B * Random.Float_Minus1_1(), 0, 1); start.A = MathHelper.Clamp(m_tStartColor.A + m_tStartColorVar.A * Random.Float_Minus1_1(), 0, 1); CCColor4F end; end.R = MathHelper.Clamp(m_tEndColor.R + m_tEndColorVar.R * Random.Float_Minus1_1(), 0, 1); end.G = MathHelper.Clamp(m_tEndColor.G + m_tEndColorVar.G * Random.Float_Minus1_1(), 0, 1); end.B = MathHelper.Clamp(m_tEndColor.B + m_tEndColorVar.B * Random.Float_Minus1_1(), 0, 1); end.A = MathHelper.Clamp(m_tEndColor.A + m_tEndColorVar.A * Random.Float_Minus1_1(), 0, 1); particle.color = start; particle.deltaColor.R = (end.R - start.R) / particle.timeToLive; particle.deltaColor.G = (end.G - start.G) / particle.timeToLive; particle.deltaColor.B = (end.B - start.B) / particle.timeToLive; particle.deltaColor.A = (end.A - start.A) / particle.timeToLive; // size float startS = m_fStartSize + m_fStartSizeVar * Random.Float_Minus1_1(); startS = Math.Max(0, startS); // No negative value particle.size = startS; if (m_fEndSize == kCCParticleStartSizeEqualToEndSize) { particle.deltaSize = 0; } else { float endS = m_fEndSize + m_fEndSizeVar * Random.Float_Minus1_1(); endS = Math.Max(0, endS); // No negative values particle.deltaSize = (endS - startS) / particle.timeToLive; } // rotation float startA = m_fStartSpin + m_fStartSpinVar * Random.Float_Minus1_1(); float endA = m_fEndSpin + m_fEndSpinVar * Random.Float_Minus1_1(); particle.rotation = startA; particle.deltaRotation = (endA - startA) / particle.timeToLive; // position if (m_ePositionType == CCPositionType.kCCPositionTypeFree) { particle.startPos = ConvertToWorldSpace(CCPoint.Zero); } else if (m_ePositionType == CCPositionType.kCCPositionTypeRelative) { particle.startPos = m_tPosition; } // direction float a = MathHelper.ToRadians(m_fAngle + m_fAngleVar * Random.Float_Minus1_1()); // Mode Gravity: A if (m_nEmitterMode == CCEmitterMode.kCCParticleModeGravity) { var v = new CCPoint(MHelper.Cos(a), MHelper.Sin(a)); float s = modeA.speed + modeA.speedVar * Random.Float_Minus1_1(); // direction particle.modeA.dir = CCPointExtension.Multiply(v, s); // radial accel particle.modeA.radialAccel = modeA.radialAccel + modeA.radialAccelVar * Random.Float_Minus1_1(); // tangential accel particle.modeA.tangentialAccel = modeA.tangentialAccel + modeA.tangentialAccelVar * Random.Float_Minus1_1(); } // Mode Radius: B else { // Set the default diameter of the particle from the source position float startRadius = modeB.startRadius + modeB.startRadiusVar * Random.Float_Minus1_1(); float endRadius = modeB.endRadius + modeB.endRadiusVar * Random.Float_Minus1_1(); particle.modeB.radius = startRadius; if (modeB.endRadius == kCCParticleStartRadiusEqualToEndRadius) { particle.modeB.deltaRadius = 0; } else { particle.modeB.deltaRadius = (endRadius - startRadius) / particle.timeToLive; } particle.modeB.angle = a; particle.modeB.degreesPerSecond = MathHelper.ToRadians(modeB.rotatePerSecond + modeB.rotatePerSecondVar * Random.Float_Minus1_1()); } }