예제 #1
0
 public Particle()
 {
     pointSprite = new ParticleVertex();
     pointSprite.Position = new Vector3(0, 0, 0);
     pointSprite.PointSize = 1.0f;
     pointSprite.Color = DEFAULT_COLOR.ToArgb();
 }
 public Particle()
 {
     pointSprite           = new ParticleVertex();
     pointSprite.Position  = new Vector3(0, 0, 0);
     pointSprite.PointSize = 1.0f;
     pointSprite.Color     = DEFAULT_COLOR.ToArgb();
 }
예제 #3
0
        /// <summary>
        /// Adds random particle at specified position
        /// </summary>
        /// <param name="p"></param>
        public void AddParticle( Vector2 pos, Vector2 vel, float lifeTime, float size0, float size1, float colorBoost = 1 )
        {
            if (injectionCount>=MaxInjectingParticles) {
                Log.Warning("Too much injected particles per frame");
                //injectionCount = 0;
                return;
            }

            //Log.LogMessage("...particle added");
            var v = vel + RadialRandomVector() * 5;
            var a = Vector2.UnitY * 10 - v * 0.2f;
            var r = rand.NextFloat( -MathUtil.Pi, MathUtil.Pi );
            var s = (rand.NextFloat(0,1)>0.5f) ? -1 : 1;

            var p = new ParticleVertex () {
                Position		=	new Vector4(pos,0,1),
                VelAccel		=	new Vector4(v.X, v.Y, a.X, a.Y ),
                Color0			=	Color4.Zero,
                Color1			=	rand.NextColor4() * colorBoost,
                SizeAngle		=	new Vector4( size0, size1, r, r + 2*s ),
                Timing			=	new Vector4( rand.NextFloat(lifeTime/7, lifeTime), 0, 0.01f, 0.01f ),
            };

            injectionBufferCPU[ injectionCount ] = p;
            injectionCount ++;
        }
예제 #4
0
        /// <summary>
        /// Adds random particle at specified position
        /// </summary>
        /// <param name="p"></param>
        public void AddParticle(Vector2 pos, Vector2 vel, float lifeTime, float size0, float size1, float colorBoost = 1)
        {
            if (injectionCount >= MaxInjectingParticles)
            {
                Log.Warning("Too much injected particles per frame");
                //injectionCount = 0;
                return;
            }

            //Log.LogMessage("...particle added");
            var v = vel + RadialRandomVector() * 5;
            var a = Vector2.UnitY * 10 - v * 0.2f;
            var r = rand.NextFloat(-MathUtil.Pi, MathUtil.Pi);
            var s = (rand.NextFloat(0, 1) > 0.5f) ? -1 : 1;

            var p = new ParticleVertex()
            {
                Position  = new Vector4(pos, 0, 1),
                VelAccel  = new Vector4(v.X, v.Y, a.X, a.Y),
                Color0    = Color4.Zero,
                Color1    = rand.NextColor4() * colorBoost,
                SizeAngle = new Vector4(size0, size1, r, r + 2 * s),
                Timing    = new Vector4(rand.NextFloat(lifeTime / 7, lifeTime), 0, 0.01f, 0.01f),
            };

            injectionBufferCPU[injectionCount] = p;
            injectionCount++;
        }
예제 #5
0
        public override void Initialize()
        {
            base.Initialize();

            // Partikel-Vertices und Indices anlegen
            particles = new ParticleVertex[maxParticles * 4];
            indices   = new ushort[maxParticles * 6];

            // Vertices und Indices initialisieren
            for (int i = 0; i < maxParticles; i++)
            {
                particles[i * 4 + 0] = new ParticleVertex(new Vector2(0, 0));
                particles[i * 4 + 1] = new ParticleVertex(new Vector2(1, 0));
                particles[i * 4 + 2] = new ParticleVertex(new Vector2(1, 1));
                particles[i * 4 + 3] = new ParticleVertex(new Vector2(0, 1));

                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 + 2);
                indices[i * 6 + 4] = (ushort)(i * 4 + 3);
                indices[i * 6 + 5] = (ushort)(i * 4 + 0);
            }

            // Vertex- und IndexBuffer anlegen
            indexBuffer  = new IndexBuffer(GraphicsDevice, typeof(ushort), indices.Length, BufferUsage.WriteOnly);
            vertexBuffer = new DynamicVertexBuffer(GraphicsDevice, typeof(ParticleVertex), particles.Length, BufferUsage.WriteOnly);

            // Indices in den Buffer kopieren
            indexBuffer.SetData(indices);
        }
예제 #6
0
 public void CreateRenderData()
 {
     //Bart,bart,bart toch *6!!
     for (int i = 0; i < particles.Length * 6; i += 6)
     {
         Vector2 uv = getUVFromIndex(i / 6);
         renderData[i]     = new ParticleVertex(uv, new Vector2(-0.5f, -0.5f));
         renderData[i + 1] = new ParticleVertex(uv, new Vector2(0.5f, -0.5f));
         renderData[i + 2] = new ParticleVertex(uv, new Vector2(0.5f, 0.5f));
         renderData[i + 3] = new ParticleVertex(uv, new Vector2(-0.5f, -0.5f));
         renderData[i + 4] = new ParticleVertex(uv, new Vector2(0.5f, 0.5f));
         renderData[i + 5] = new ParticleVertex(uv, new Vector2(-0.5f, 0.5f));
     }
 }
예제 #7
0
        void CreateQuad(ref int count, Vector3 position, Vector2 size, Color4 color, float angle, ParticleTexture texture, float frame, Vector3 src_right, Vector3 src_up)
        {
            var sz1     = new Vector3(size.X * -0.5f, size.Y * -0.5f, angle);
            var sz2     = new Vector3(size.X * 0.5f, size.Y * -0.5f, angle);
            var sz3     = new Vector3(size.X * -0.5f, size.Y * 0.5f, angle);
            var sz4     = new Vector3(size.X * 0.5f, size.Y * 0.5f, angle);
            var frameNo = (int)Math.Floor((texture.FrameCount - 1) * frame);
            int i       = frameNo * 4;

            vertices[count++] = new ParticleVertex()
            {
                Position          = position,
                Color             = color,
                TextureCoordinate = texture.Coordinates[i + 2],
                Dimensions        = sz1,
                Right             = src_right,
                Up = src_up
            };
            vertices[count++] = new ParticleVertex()
            {
                Position          = position,
                Color             = color,
                TextureCoordinate = texture.Coordinates[i],
                Dimensions        = sz2,
                Right             = src_right,
                Up = src_up
            };
            vertices[count++] = new ParticleVertex()
            {
                Position          = position,
                Color             = color,
                TextureCoordinate = texture.Coordinates[i + 3],
                Dimensions        = sz3,
                Right             = src_right,
                Up = src_up
            };
            vertices[count++] = new ParticleVertex()
            {
                Position          = position,
                Color             = color,
                TextureCoordinate = texture.Coordinates[i + 1],
                Dimensions        = sz4,
                Right             = src_right,
                Up = src_up
            };
        }
        void CreateQuad(ref int count, Vector3 position, Vector2 size, Color4 color, float angle, Vector2 topleft, Vector2 topright, Vector2 bottomleft, Vector2 bottomright, Vector3 src_right, Vector3 src_up)
        {
            var sz1 = new Vector3(size.X * -0.5f, size.Y * -0.5f, angle);
            var sz2 = new Vector3(size.X * 0.5f, size.Y * -0.5f, angle);
            var sz3 = new Vector3(size.X * -0.5f, size.Y * 0.5f, angle);
            var sz4 = new Vector3(size.X * 0.5f, size.Y * 0.5f, angle);

            vertices[count++] = new ParticleVertex()
            {
                Position          = position,
                Color             = color,
                TextureCoordinate = bottomleft,
                Dimensions        = sz1,
                Right             = src_right,
                Up = src_up
            };
            vertices[count++] = new ParticleVertex()
            {
                Position          = position,
                Color             = color,
                TextureCoordinate = topleft,
                Dimensions        = sz2,
                Right             = src_right,
                Up = src_up
            };
            vertices[count++] = new ParticleVertex()
            {
                Position          = position,
                Color             = color,
                TextureCoordinate = bottomright,
                Dimensions        = sz3,
                Right             = src_right,
                Up = src_up
            };
            vertices[count++] = new ParticleVertex()
            {
                Position          = position,
                Color             = color,
                TextureCoordinate = topright,
                Dimensions        = sz4,
                Right             = src_right,
                Up = src_up
            };
        }
        private void InitParticles()
        {
            IsTransparent = true;
            _nbQuads      = _particlesBuffer.Length;

            for (int i = 0; i < _particlesBuffer.Length; i++)
            {
                _particlesBuffer[i].Life    = -1;
                _particlesBuffer[i].InvMass = 1f;
                _particlesBuffer[i].Mass    = 1f;
                _particlesBuffer[i].Color   = 0xFFFFFFFF;
                _particlesBuffer[i].Alpha   = 0;
            }

            float size = 1;

            _quads = new ParticleVertex[_nbQuads * 4];
            _vd    = VertexDescriptor.GetDescriptor <ParticleVertex>();
            short[] indices = new short[_nbQuads * 6];;

            for (int i = 0; i < _nbQuads; i++)
            {
                // P0----P1
                // |   / |
                // | /   |
                // P3----P2
                _quads[4 * i]     = new ParticleVertex(-0.5f * size, 0.5f * size, 0, 0, 0);  //P0
                _quads[4 * i + 1] = new ParticleVertex(0.5f * size, 0.5f * size, 0, 1, 0);   //P1
                _quads[4 * i + 2] = new ParticleVertex(-0.5f * size, -0.5f * size, 0, 0, 1); //P3
                _quads[4 * i + 3] = new ParticleVertex(0.5f * size, -0.5f * size, 0, 1, 1);  //P2

                indices[6 * i]     = (short)(4 * i);
                indices[6 * i + 1] = (short)(4 * i + 1);
                indices[6 * i + 2] = (short)(4 * i + 2);

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

            _vb = GraphicDeviceFactory.Device.CreateVertexBuffer(ResourceUsage.Dynamic, CpuAccessFlags.Write, data: _quads);
            _ib = GraphicDeviceFactory.Device.CreateIndexBuffer(data: indices);
        }
        private void BuildVertexBuffer()
        {
            //
            // Create the buffer to kick-off the particle system.
            //
            var vbd = new BufferDescription
            {
                Usage          = ResourceUsage.Default,
                SizeInBytes    = Marshal.SizeOf(typeof(ParticleVertex)) * 1,
                BindFlags      = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags    = ResourceOptionFlags.None
            };

            // The initial particle emitter has type 0 and age 0.  The rest
            // of the particle attributes do not apply to an emitter.
            var p = new ParticleVertex
            {
                Type = 0,
                Age  = 0.0f
            };

            using (var ds = new DataStream(Marshal.SizeOf(p), true, true))
            {
                ds.Write(p);
                ds.Position = 0;

                _initVB = new Buffer(_dxDevice, ds, vbd);
            }

            //
            // Create the ping-pong buffers for stream-out and drawing.
            //
            vbd.SizeInBytes = Marshal.SizeOf(typeof(ParticleVertex)) * _maxParticles;
            vbd.BindFlags   = BindFlags.VertexBuffer | BindFlags.StreamOutput;

            _drawVB      = new Buffer(_dxDevice, vbd);
            _streamOutVB = new Buffer(_dxDevice, vbd);
        }
예제 #11
0
 public void WriteParticleVertex(ParticleVertex v)
 {
 }
예제 #12
0
 public void WriteParticleVertex(ParticleVertex v)
 {
     throw new NotImplementedException();
 }
예제 #13
0
 public void WriteParticleVertex(ParticleVertex v)
 {
 }