Exemplo n.º 1
0
        bool UpdateParticle(ref CCParticleRadial particleRadial, float dt)
        {
            if (UpdateParticleBase(ref particleRadial.ParticleBase, dt))
            {
                particleRadial.Angle  += particleRadial.DegreesPerSecond * dt;
                particleRadial.Radius += particleRadial.DeltaRadius * dt;

                CCPoint position = particleRadial.ParticleBase.Position;
                position.X = -CCMathHelper.Cos(particleRadial.Angle) * particleRadial.Radius;
                position.Y = -CCMathHelper.Sin(particleRadial.Angle) * particleRadial.Radius;
                particleRadial.ParticleBase.Position = position;

                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        // Initialise particle

        void InitParticle(ref CCParticleGravity particleGrav, ref CCParticleBase particleBase)
        {
            InitParticleBase(ref particleBase);

            // direction
            float a = MathHelper.ToRadians(Angle + AngleVar * CCRandom.Float_Minus1_1());

            if (EmitterMode == CCEmitterMode.Gravity)
            {
                CCPoint v = new CCPoint(CCMathHelper.Cos(a), CCMathHelper.Sin(a));
                float   s = GravityMode.Speed + GravityMode.SpeedVar * CCRandom.Float_Minus1_1();

                particleGrav.Direction       = v * s;
                particleGrav.RadialAccel     = GravityMode.RadialAccel + GravityMode.RadialAccelVar * CCRandom.Float_Minus1_1();
                particleGrav.TangentialAccel = GravityMode.TangentialAccel + GravityMode.TangentialAccelVar * CCRandom.Float_Minus1_1();

                if (GravityMode.RotationIsDir)
                {
                    particleBase.Rotation = -MathHelper.ToDegrees(CCPoint.ToAngle(particleGrav.Direction));
                }
            }
        }
        void UpdateQuad(ref CCV3F_C4B_T2F_Quad quad, ref CCParticleBase particle)
        {
            CCPoint newPosition;

            if (PositionType == CCPositionType.Free)
            {
                newPosition.X = particle.Position.X - (currentPosition.X - particle.StartPosition.X);
                newPosition.Y = particle.Position.Y - (currentPosition.Y - particle.StartPosition.Y);
            }
            else
            {
                newPosition = particle.Position;
            }

            CCColor4B color = new CCColor4B();

            if (OpacityModifyRGB)
            {
                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  = -CCMathHelper.ToRadians(particle.Rotation);
                float cr = CCMathHelper.Cos(r);
                float sr = CCMathHelper.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;
            }
        }
Exemplo n.º 4
0
        void UpdateQuad(ref CCV3F_C4B_T2F_Quad quad, ref CCParticleBase particle)
        {
            CCPoint newPosition;

            if (PositionType == CCPositionType.Free || PositionType == CCPositionType.Relative)
            {
                newPosition.X = particle.Position.X - (currentPosition.X - particle.StartPosition.X);
                newPosition.Y = particle.Position.Y - (currentPosition.Y - particle.StartPosition.Y);
            }
            else
            {
                newPosition = particle.Position;
            }

            // 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 (BatchNode != null)
            {
                newPosition.X += Position.X;
                newPosition.Y += Position.Y;
            }

            CCColor4B color = new CCColor4B();

            if (OpacityModifyRGB)
            {
                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  = -CCMathHelper.ToRadians(particle.Rotation);
                float cr = CCMathHelper.Cos(r);
                float sr = CCMathHelper.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;
            }
        }