Particle Wind

Started by
0 comments, last by LessBread 15 years ago
Hello. I'm new here, please move this if it's posted in the wrong section. I've been working on a basic 2d particle system i XNA and so far things have gone pretty smoothly. (The problem I'm having isn't related to any part of XNA so I decided to post it here) I wanted to have "local" wind on the particles, not the same wind on the entire area. So I made a 2d array called "windMap" that is the screen-height/10 in "Y"-size and screen-width/10 in "X"-size, so every value in the array can be used to represent a 10x10 area. The values in the windmap adds it's wind-speed to the particles in that area and that part works well. My problem is with the movement of the wind in the "windMap". I've made something basic that transfers wind from left to right and spreads it out vertically. (The X is the X-speed and the Y is the Y-speed) for (int i = 1; i < windSizeX-1; i++) { for (int ii = 1; ii < windSizeY-1; ii++) { //slowdown windMap[i, ii].X = windMap[i, ii].X *0.5f; windMap[i, ii].Y = windMap[i, ii].Y * 0.5f; //transfer 100% of the remaining windpower windMap.X += windMap[i, ii].X * 0.25f; windMap.Y += windMap[i, ii].Y * 0.25f; windMap.X += windMap[i, ii].X * 0.5f; windMap.Y += windMap[i, ii].Y * 0.5f; windMap.X += windMap[i, ii].X * 0.25f; windMap.Y += windMap[i, ii].Y * 0.25f; //more wind slowdown windMap[i, ii].X *= 0.95f; windMap[i, ii].Y *= 0.95f; } } http://img529.imageshack.us/img529/5020/screenshotlowq.jpg (it "blows" from &#111;ne point at the top of the blue thing) It works pretty well but the wind can &#111;nly spread from left to right. I need the wind to spread correctly according to the angle it blows at. I can get the direction of the wind (not shown in the code). Does anybody have any suggestions? <!–EDIT–><span class=editedby><!–/EDIT–>[Edited by - Blueberry on April 22, 2009 7:48:40 AM]<!–EDIT–></span><!–/EDIT–>
Advertisement
Here's a general response.

x,y | x,y
---------
-,+ | +,+
---------
-,- | +,-


If your wind only blows left to right, it might be due to only adding positive offsets to the position of the particles. That would be the upper right hand quadrant of the above map (+,+). If this is the case, then adding negative offsets (-,-) should result in wind that blows right to left and adding a mixture of positive and negative (+,-), (-,+) should result in wind that blows crosswise in either direction depending on whether a negative offset is applied to x or y.

If you want to direct the wind using an angle (e.g. rotating a steering wheel).

double radians = angle * 0.01745f; // convert degrees to radians
x += (mx * cos(radians));
y += (my * sin(radians));

where mx,my is the speed of the particle on either axis. See The Unit Circle.




[Edited by - LessBread on April 22, 2009 1:09:31 PM]
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

This topic is closed to new replies.

Advertisement