public ParticleSystem(ParticleSettings settings, Effect effect)
        {
            if (settings == null) throw new ArgumentNullException("settings");
            if (effect == null) throw new ArgumentNullException("effect");
            if (settings.Texture == null) throw new ArgumentException("Texture is null.");

            Enabled = true;

            this.settings = settings;

            //----------------------------------------------------------------
            // システム名

            Name = settings.Name;

            //----------------------------------------------------------------
            // エフェクト

            particleEffect = new ParticleEffect(effect);
            particleEffect.Initialize(settings, settings.Texture);

            graphicsDevice = particleEffect.GraphicsDevice;

            //----------------------------------------------------------------
            // パーティクル

            particles = new ParticleVertex[settings.MaxParticles * 4];

            for (int i = 0; i < settings.MaxParticles; i++)
            {
                particles[i * 4 + 0].Corner = new Short2(-1, -1);
                particles[i * 4 + 1].Corner = new Short2(1, -1);
                particles[i * 4 + 2].Corner = new Short2(1, 1);
                particles[i * 4 + 3].Corner = new Short2(-1, 1);
            }

            //----------------------------------------------------------------
            // 頂点バッファ

            vertexBuffer = new DynamicVertexBuffer(
                graphicsDevice, ParticleVertex.VertexDeclaration, settings.MaxParticles * 4, BufferUsage.WriteOnly);

            //----------------------------------------------------------------
            // インデックス バッファ

            var indices = new ushort[settings.MaxParticles * 6];
            for (int i = 0; i < settings.MaxParticles; i++)
            {
                indices[i * 6 + 0] = (ushort) (i * 4 + 0);
                indices[i * 6 + 1] = (ushort) (i * 4 + 1);
                indices[i * 6 + 2] = (ushort) (i * 4 + 2);

                indices[i * 6 + 3] = (ushort) (i * 4 + 0);
                indices[i * 6 + 4] = (ushort) (i * 4 + 2);
                indices[i * 6 + 5] = (ushort) (i * 4 + 3);
            }

            indexBuffer = new IndexBuffer(graphicsDevice, typeof(ushort), indices.Length, BufferUsage.WriteOnly);
            indexBuffer.SetData(indices);
        }
Beispiel #2
0
 internal void Initialize(ParticleSettings settings, Texture2D texture)
 {
     Parameters["Duration"].SetValue((float)settings.Duration.TotalSeconds);
     Parameters["DurationRandomness"].SetValue(settings.DurationRandomness);
     Parameters["Gravity"].SetValue(settings.Gravity);
     Parameters["EndVelocity"].SetValue(settings.EndVelocity);
     Parameters["MinColor"].SetValue(settings.MinColor.ToVector4());
     Parameters["MaxColor"].SetValue(settings.MaxColor.ToVector4());
     Parameters["RotateSpeed"].SetValue(new Vector2(settings.MinRotateSpeed, settings.MaxRotateSpeed));
     Parameters["StartSize"].SetValue(new Vector2(settings.MinStartSize, settings.MaxStartSize));
     Parameters["EndSize"].SetValue(new Vector2(settings.MinEndSize, settings.MaxEndSize));
     Parameters["Texture"].SetValue(texture);
 }
Beispiel #3
0
        public ParticleSystem(ParticleSettings settings, Effect effect)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (effect == null)
            {
                throw new ArgumentNullException("effect");
            }
            if (settings.Texture == null)
            {
                throw new ArgumentException("Texture is null.");
            }

            Enabled = true;

            this.settings = settings;

            //----------------------------------------------------------------
            // システム名

            Name = settings.Name;

            //----------------------------------------------------------------
            // エフェクト

            particleEffect = new ParticleEffect(effect);
            particleEffect.Initialize(settings, settings.Texture);

            graphicsDevice = particleEffect.GraphicsDevice;

            //----------------------------------------------------------------
            // パーティクル

            particles = new ParticleVertex[settings.MaxParticles * 4];

            for (int i = 0; i < settings.MaxParticles; i++)
            {
                particles[i * 4 + 0].Corner = new Short2(-1, -1);
                particles[i * 4 + 1].Corner = new Short2(1, -1);
                particles[i * 4 + 2].Corner = new Short2(1, 1);
                particles[i * 4 + 3].Corner = new Short2(-1, 1);
            }

            //----------------------------------------------------------------
            // 頂点バッファ

            vertexBuffer = new DynamicVertexBuffer(
                graphicsDevice, ParticleVertex.VertexDeclaration, settings.MaxParticles * 4, BufferUsage.WriteOnly);

            //----------------------------------------------------------------
            // インデックス バッファ

            var indices = new ushort[settings.MaxParticles * 6];

            for (int i = 0; i < settings.MaxParticles; i++)
            {
                indices[i * 6 + 0] = (ushort)(i * 4 + 0);
                indices[i * 6 + 1] = (ushort)(i * 4 + 1);
                indices[i * 6 + 2] = (ushort)(i * 4 + 2);

                indices[i * 6 + 3] = (ushort)(i * 4 + 0);
                indices[i * 6 + 4] = (ushort)(i * 4 + 2);
                indices[i * 6 + 5] = (ushort)(i * 4 + 3);
            }

            indexBuffer = new IndexBuffer(graphicsDevice, typeof(ushort), indices.Length, BufferUsage.WriteOnly);
            indexBuffer.SetData(indices);
        }
 internal void Initialize(ParticleSettings settings, Texture2D texture)
 {
     Parameters["Duration"].SetValue((float) settings.Duration.TotalSeconds);
     Parameters["DurationRandomness"].SetValue(settings.DurationRandomness);
     Parameters["Gravity"].SetValue(settings.Gravity);
     Parameters["EndVelocity"].SetValue(settings.EndVelocity);
     Parameters["MinColor"].SetValue(settings.MinColor.ToVector4());
     Parameters["MaxColor"].SetValue(settings.MaxColor.ToVector4());
     Parameters["RotateSpeed"].SetValue(new Vector2(settings.MinRotateSpeed, settings.MaxRotateSpeed));
     Parameters["StartSize"].SetValue(new Vector2(settings.MinStartSize, settings.MaxStartSize));
     Parameters["EndSize"].SetValue(new Vector2(settings.MinEndSize, settings.MaxEndSize));
     Parameters["Texture"].SetValue(texture);
 }