At the IGDA Twin Cities meeting in March, the lead developer for Just Jam, Matt Heinzen, mentioned using rolling averages to do animation. This caught my attention, since it was a perfect phrase for a trick I have used a number of times in my programming. I thought I’d take a shot at explaining it here since I did a horrible job on the IGDATC Podcast.
A rolling average is also known as a moving average along with a few other cute names. Wikipedia does a good job explaining it in that Wikipedia way. You know, the equation way with complicated, but accurate, descriptions. I say a rolling average is just a way to take the average of a select part of data set. For example, in the last 7 days, I’ve averaged 0.6 cans of Mt. Dew a day. If, tomorrow, I don’t consume any Mt. Dew, my 7 day average will go down.
So how does this help in programming? For me, its usually a matter of convenience. You may have binary data and you want to smooth it out some for instance. To really smooth it out you may want to be aware of your time step, acceleration/deceleration, velocity, motion time, time into motion. Maybe even more. With a rolling average all you need is a target value.
Lets say you’ve got an arrow and you want to have it point somewhere. You don’t want to have super control over the animation of the arrow like I mention above, you simply want to tell it to point up or point down. However, it would be nice if the arrow rotation had some motion.
Let’s set up this example. There is an arrow pointing up, lets call that 0 degrees. Now at some moment you want to say point down, rotating 180 degrees. If all you do is say at one moment your 0 degrees, and the next moment your 180, there is no animation. Let’s use rolling average to smooth it out. All we need to know is the target rotation angle, which in this example is either 0 or 180, and the current angle. We need to pick a period, which in the Mt. Dew example was 7 days. In a typical game, and in most cases I’ve designed, they end up depending on the frame rate, lets not concern ourselves with that at the moment and pick a period of 10.
With that example, the first frame after the target angle is changed from 0 to 180, the rolling average will calculate it to be as follows.
That is to say instead of it immediately snapping to 180 degrees, the first frame after its told to go to 180 degrees it rotates to 18 degrees. The next frame would look like this:
And continuing on.
To help illustrate this I’ve made a little XNA program. You can either download it and give it a try (no guarantees), or watch this video.
Eight lifetimes were spent playing Call of Duty Black Ops on XBOX Live by then end of launch day on November 9th. Sensational, I know, but let me explain.
I’ve always found this math concept interesting, where you compare lifetimes to an event, especially if you equate it to big events like the Super Bowl. Basicaly any event where they brag about the number of viewers, or hours spent, or time committed to something means that lifetimes were used up. Major Nelsons recent tweet about Call of Duty Black Ops having 5.9 million hours played in the first day reminded me of this strange thought, so I had to find out. How many lifetimes were used playing Call of Duty on that first day?
|Major Nelson’s tweet from Nov. 19th, 2010|
The math is easy, so let me walk through it.
First off, what is the life expectancy of the average person? I decided to use the US average, since its probably the majority of players and is also fairly high. According to the CIA, the average life expectancy of a US citizen in 2010 is approximately 78 years.
Second is determining how many years 5.9 million hours is. 5,900,000 hours is 245833 days (5900000 hrs / 24 hrs/day) which is 673 years (245833 days / 365 days/year).
The rest is simple. If a lifetime is 78 years, and 673 years were spent playing, that means that 8.6 lifetimes (673 years / 78 years/lifetime) were spent.
What does this mean? Well, nothing really. It’s just an interesting number related to life. It doesn’t mean lives were wasted, because many many more are spent in more mundane things every day (such as traffic). It’s just interesting to see how we spend our time.