Itay.Ro

Member

13

109 Neutral

• Rank
Member

• Interests
Programming
1. XNA 2D Particles :)

Hi everyone sorry if I have mistakes with my English.. Im using XNA 3.1 and Im working on school project...so I decide to do 2D particle system! I want to do something like this: http://www.youtube.c...h?v=CyAZ2Y7nOTw http://www.youtube.c...h?v=eSWm_VImgFQ http://www.youtube.c...h?v=F5xwSLdG9n0 In the comments of the third video you can see that he wrote this: "[font="arial, sans-serif"] i? used fixed function, and the movement of the particles is done using newtons laws,[/font] [font="arial, sans-serif"] the cursor is an attractor and also the particles fall to the bottom of the[/font] [font="arial, sans-serif"] screen with gravity. Its all done using a verlet integration technique."[/font] [font="arial, sans-serif"] [/font] [font="arial, sans-serif"]So i read about verlet integration and found:[/font] [font="arial, sans-serif"]http://www.gamasutra...cobson_01.shtml[/font] http://www.gamedev.n...e-physics-r2714 Please some one can help me to write the code? this what I do for now: (the texture of each particle is 1X1 white picture for now) class Particle { public Vector2 pos, oldpos, a; // pos-current position , oldpos-old position , a-Acceleration public Color color; public Particle(Vector2 _pos, Vector2 _oldpos, Vector2 _a, Color _color) { pos = _pos; oldpos = _oldpos; a = _a; color = _color; } } [/quote] int WindowWidth = 800; int WindowHeight = 800; int MaxParticles; Vector2 Gravity = new Vector2(0,-0.98f); float TimeStep; private void UpdateParticles() { Vector2 temp; for (int i = 0; i < MaxParticles; i++) { temp = particles.pos; particles.pos += particles.pos - particles.oldpos + particles.a * TimeStep * TimeStep; particles.oldpos = temp; } } private void DrawParticles() { spriteBatch.Begin(); for (int i = 0; i < MaxParticles; i++) { spriteBatch.Draw(particleTex, particles.pos, particles.color); } spriteBatch.End(); } [/quote]