Exponential Spirals for Game Effects May 4th, 2009
Patrick Stein

In earlier posts, I mentioned finding polynomials, riffing off of damped harmonic motion, and then hitting on exponential spirals all trying to come up with a nice looking way to snap game tiles back into place when they are released. I want them to overshoot and then settle into place rather than snap directly into their spot.

The Basic Spiral

I am talking about a simple spiral of the form:

\theta(t) = Kt
r(t) = \alpha\left(Kt\right)^{n}
for some integer n.

That would be an equation for a spiral that starts at the origin and heads outward as t increases. For my application though, I want to end at the origin so I need to substitute 1-t in for t.

\theta(t) = K(1-t)
r(t) = \alpha\left(K(1-t)\right)^{n}

The math is also going to work out slightly better if I use n-2 in place of n in the above equations:

\theta(t) = K(1-t)
r(t) = \alpha\left(K(1-t)\right)^{n-2}

I don’t want the piece to spiral into place when released though. So, really, I am concerned with just the x coordinate from the above equations:

x(t) = r(t) \cos \theta(t) = \alpha K^{n-2} (1-t)^{n-2} \cos \left(K\left(1-t\right)\right)

To normalize everything, I am going to let \alpha = K^{2-n}. And, since I want my interpolation value to go from zero to one instead of one to zero, I am again going to subtract this all from one:

x(t) = 1 -  (1-t)^{n-2} \cos \left(K\left(1-t\right)\right)

Read the rest of this entry ⇒

A Eureka Moment May 1st, 2009
Patrick Stein

I was pondering the Phony Physics again as I set to work on my iPhone app.

In the previous post, I twiddled the equations for damped spring motion until I found something visually pleasing. Last night, I went back to the drawing (a.k.a. white) board.

What if I used an exponential spiral (parameterized by arc length). Then, I could easily adjust the number of times it bounces back and forth. I could use a spiral like r(t) = \alpha K (1-t)^n and \theta(t) = K(1-t) where K is some multiple of 2\pi. Then, I could walk along the spiral getting to the origin when t = 1 going around the origin \frac{K}{2\pi} times in the process. If I follow the curve at a fixed rate, then I guarantee that my oscillations will pick up speed as I approach the origin.

Rather than have it spiral into the center, I am just using the x-coordinate of the spiral as my new t value to interpolate with. I like the effect for the most part. It overshoots a little bit far on the first oscillation. I may tweak it some more before it’s all over. For now though, I am sticking with it.

I will post some graphs soon.

Sneak Peak: Artwork for Spelling iPhone App May 1st, 2009
Patrick Stein

My first iPhone app is a children’s spelling game. Development is coming along well now that I’ve discovered cocos2d-iphone. I should have screenshots to show early next week. For now, here is a sneak peak at one of the cards in the game.

three

First decent images from my new raytracer September 25th, 2008
Patrick Stein

Some time ago, I wrote an n-dimensional raytracer in C++. It does a fair number of things, none of them efficiently, most of the rigidly.

There are a bunch of things that I wanted to do with it for a long time, but it’s been too slow and rigid to make any of those things fun.

Enter Lisp. As soon as it made it through my skull that Lisp is actually compiled (honest-to-goodness your-CPU instructions), I wanted to rewrite the whole thing in Lisp. I have finally gotten started on doing that. And, I just made it to the point where I’m actually tracing rays. Here is a stereo pair of a three-dimensional scene:

lrt-l lrt-r

Read the rest of this entry ⇒

l