Particle Effects Without Particles

By robin, February 3, 2010 12:14 am

Particle effects are made by taking a lot of small bitmaps and varying their location and attributes over time. The resulting ‘animation’ can look like fire, smoke, or nearly anything else you like.

Shader ExampleNormally when coding these you create a small particle class or struct, and it holds things like position, color, direction, acceleration, alpha, scale, etc. These properties change each update which makes them ‘come alive’. You then assemble a bunch of these particles into ‘effects’ or some such thing. To leave a trail, or create blowing smoke, you can drop a series of these effects.

Our approach is similar, but we don’t use a particle class. Instead we use a random number between 0 and 1, and an equation. The random number is used to vary an effect, otherwise they can look very symetrical. So for example the alpha can be (255 * nextRandom()) to have it vary between invisible and visible. To make it also fade in, it can be (255 * nextRandom * t). To make it ease out on fading it can be (255 * nextRandom * Easing.FadeOutQuad(t, 255, 0)). I think you get the idea.

So instead of particles, there is just a calculation waiting to happen. Not having to deal with individual particle instances or state allows you to do things like change the particle count on the fly (by simply changing the loop size), or reverse time by changing ‘t’.

For anyone who does Flash, I’m sure the Easing idea is familiar. Robert Penner’s easing equations are universally popular, as they allow people to easily add tweening, fading and bouncing from code. I’m basing the equations on these, and adding a few non easing ones that are useful for particles (trig functions, weird functions, etc).

Rather than store the random numbers for each particle (which would require a particle class), we store the random seed and regenerate the same sequence of random numbers each update. This may sound slow, but reasonable random number generation can be surprisingly simple and blazingly fast (one billion numbers in 1.8 seconds on a p4!). We are using the FastRandom class by Colin Green which is really fast, and a drop in replacement for System.Random. This allows resetting the random seed without penalty. This is important as we reset the seed every update in order to get the same random number sequence time. It is also easy to extend – we have added saving state, so for example we can start at the 500th random number of a given seed without going through the first 499. Awesome code, I’d recommend using it for anything random in your game.

Note this code is available at http://www.codeplex.com/swf though the particle part hasn’t yet been added (using git locally, so it is a pain).

Here are some quick demo videos, I’d like to say they will clear up this crappy explanation, but I’ve seen them.

Part 1


Part 2

Remove components from circuit board with cooking oil

By robin, January 23, 2010 2:39 am

Want some easy components? I’ve tried lots of ways to get things off a board, but this works the best so far. Heat guns are too uneven, smelly and require your hands to be occupied. Desoldering is fine for things with few leads, but a pain for chips etc. Just skillet heat is also pretty uneven and can soften the plastic parts too much.

Solder melts at about 200C, and oil boils at about 250C (some types are hotter than others – canola oil is about 200C, peanut oil is about 250). So frying the boards bottom works great.

Place a thin layer of oil in a thrift store skillet (solder may contain lead, so don’t cook with the same one later). Ideally it will be adjustable temperature, and must have a flat bottom. Once the oil is hot, place the board in it for a few minutes. Ideally the oil doesn’t flow over the edge, though it may a little. You can then just pull most things off with a pair of leather gloves. Even plastic connectors tended to be fine — nice!

Note: Splattering oil is the big danger here. Safety goggle not an option. Leather gloves as well. Will try to get photos tomorrow…

Class View in VS2008

By robin, November 13, 2009 3:11 pm

One thing I really liked in Eclipse that is not in VS is the class view panel. I have no idea why that is missing, it is basically in every IDE down to almost emacs. There is a ‘Class Viewer’, but this is an object tree of all classes, and doesn’t follow along as you switch files.

My workaround, that is “not quite so lame but still very open to suggestions“, is to slide the Class View splitter almost to the top (exposing more class details space, less solution space), and then map refresh to F1. Yes F1 — I know it is supposed to be for help, but that is just stupid in an IDE. 911 is for help, function keys should map to common tasks (and not common features in programs).

So the setup is this:

  • View>Window>Class View (enabled)
  • drag the Class View to dock beside Solution View on the right.
  • drag the mid bar way up
  • Tools>Options>Environment::Keyboard — type “view.sync” into the Show Commands Containing input field
  • Assign F1 to that in Press Shortcut Keys
  • Be sure to click Assign to assign it.

While you are there you can map Copy to F3 and Paste to F4. Then you too can be happy like me, its fun.

Now anytime you want to see that view up to date just press F1. Yes, much lamer that auto update, but it is as close as I could get. It actually is pretty much OK like this.

Full Flash Character Animation in XNA with 3D Overlay

By robin, October 10, 2009 11:03 am

The animation engine in XNA is mostly complete now. It does multiframe symbols as well as nested animations. It also handles negative scales which Flash is fond of, and XNA not so much. The Box2D part is also working with nested animations, and there are some simple components in like Button with the different states. Next up is adding replacement markers. So for example if a flash symbol is exported as ‘$ship$’, the vector graphics will be replaced with a 3D model call ’ship’ at runtime. That model will then behave as a regular sprite or box2D element (so a 3D model that only moves in 2 dimensions, with 2D physics applied).

Here is a quick demo:

Going to L.A. for the week, but I should have time to finish up the first game with this (almost there).

Xna>swf video, attempt two

By robin, September 18, 2009 12:25 pm

I made a new video demo’ing the swf>xna tool (with Box2d Automation). The first was 15 mins, too long for youtube (thanks for pointing that out Kevin and Zman). I took out all the jokes that weren’t funny (specifcally, all the jokes) and now it is only 8 mins. Funny how that works…

Swf to Xna Tool Video Demo 1

Uploaded the new video that is under 10 mins, sorry about that : ).

The tool/framework we use to build Xna games is now being used, though still a ways from feature complete. It is now in the content pipeline, so bringing in the assets is automated. This is a short-ish demo of the tool and some of its Box2D capabilities. I’ll make one of how the framework works next, as that gets filled out (it has a parallel AS3 framework, so the same flash file works in xna and in as3 (using the flash file directly)). I sound like a weenie. I know everyone thinks they do in a video, but I am a weenie as well, so I’m a little more sensitive.

All this swf parsing/generating code lives at http://www.codeplex.com/swf, although this part isn’t uploaded yet due to being in such flux. Eventually this will all be there, along with the game frameworks for flash and Xna. (There are other things in there, like a swf to xaml converter, swf dump etc, though it is a very ‘personal’ project unfortunately, aka mostly useful to the person who wrote it : ).

Cured a wart with compressed air

By robin, September 6, 2009 8:42 pm

I’ve had a wart that wouldn’t go away for about 5+ years now. I wasn’t that annoying, but it was persistent. I tried duct tape, wart remover, wart bandaids, and even criminally expensive ($40!) wart freezer (twice!!)… yet it always came back.

Recently I tried a compressed air canister (the kind to blow dust out of your computer) — and what do you know it worked!

You turn it upside down, and *slowly* squeeze the trigger. This allows liquid air to drip out one drop at a time, onto said wart. You can freeze the crap out of it, and it is accurate enough to that you don’t need any other protection. Mostly it is handy enough you can do it a few times a day for a few days, which I think is what did the trick. Cheap, easy, effective and plenty of air left over to blow the dust out of your CPU.

Best part, you no longer have to love me warts and all.

Swf Renderer for C# and XNA

By robin, August 2, 2009 4:59 pm

Working feverishly on a renderer for swfs, and it is coming along nicely. I am trying to keep it very fast, I think the best speed will be combo gpu/cpu. The cpu part is using a fair bit of bezier ‘premanipulation’, and then a line scan with basic antialiasing. The goal is to be able to use tiny vector defs for xna games, making them easy to download/store, and zune friendly. It will also be fairly easily portable as the rendering algorithm is just using code and a memory bitmap (so not gdi etc dependencies). No assembler for this version as you can’t use PInvoke in XNA and afaik that rules out assembly (need to investigate more, I am using ‘unsafe’ already though, so maybe).

Every time I delve into the swf format, I marvel at what a fricken genius John Gay is. Anyone can put every possible feature in, given time, and end up with a bloated piece of crap software. Great software is a result of deep thought, which results in everything you need and nothing you don’t. But this, it is only half of what you are sure you needed, and yet the result is twice as much as you thought you could ever use. Its like a winning F1 car that somehow has a movie theater inside it.

Here is a screenshot of the CPU only part, more to come..

Rendering swf files using scanline algoithm etc

Feynman lectures online

By robin, July 18, 2009 6:41 pm

Richard Feynman (why isn’t there a movie about him?) gave brilliant lectures, wrote brilliant books, came up with brilliant science, and was reasonable on the bongos so they say. There is a totally amazing series of his lectures online now, for free, thanks to Bill Gates. You have to get past Silverlight, and thus the stuttering video (and no download), and the side by side giant portraits of Feynman and Bill G (what, are we supposed to compare?). That said, it is really really great that this stuff is online and totally worth a watch. Hopefully as retirement sets in, Bill G will not feel obliged to use a Microsoft technology to wrap his gifts in (but rather feel free to use one that, err, works properly, microsoft or otherwise). I understand he had to pay to put this out there for us, so a big thanks in any case — frankly though, the idea that this isn’t world property already is a travesty.

Anyway, WELL worth watching…

Richard Feynman

Flash to XNA with Box2D

By robin, July 15, 2009 10:28 am

My brother and I are working on some XBox mini games, and one of the goals is to be able to really *crank* stuff out (ideally one every week once we are set up). This of course will involve some automation tools — the first will be flash>xna and the second will be box2d. Atm the state of the flash one is vectors and positioning are coming in, but so far no animation or multiple frames. The goal is full animation, but probably no code. I have a similar framework on the go for the XNA side, which is probably enough.

For box2d I’m using the Flash>box2d output from a previous tool (http://debreuil.com/v2d/) to create box2d screens. For this the vectors are coming in, and the basic bodies are working. Need to add joints etc still.

v2d in xna

Once these are complete and cleaned up I’m planning on getting a content pipeline thing going. Then we need to get cranking on games : ).

Panorama theme by Themocracy