Don't you love it when you get one of the those "A HA!" moments? Well, one
came to me tonight. It should have come to me a long time ago. It's not really
ground breaking either. It's one of those things that you know in the back of
your head, but you finally understand the beauty of it after you've been doing
it for a long time. My "A HA!" moment tonight was a true understanding of the
LERP (Linear Interpolation). You use it in a lot of places in 3D programming.
Simply put, Linear Interpolation is a way of predicting or modeling an
objects state at a particular time. Let's say you have an object that starts at
a certain point (P0) and ends up in another point (P1) a given time later (T).
Assuming a constant velocity, you can predict where the object is at any time
between t0 and tT. Right? Get it? Well, another beauty of the LERP is the
equation for the LERP.
Pt = P0 + t(P1-P0).
Simple as that. For any t, you can calculate where an object is. My "A HA!"
moment came when I realized that P can be almost anything.
- a number in R3 (Real space)
- a vector
- a color
- ... the list goes on.
And, another nice feature of the lerp is that lerping a vector is the same as
lerping it's components or vica versa. Look here:
vector v = LERP(v0, t) = vector(LERP(v0.x, t), LERP(v0.y, t), LERP(v0.z, t)).
Cooler still is that a LERP can be converted to a non-linear interoplation (NLERP)
by changing t into a function of t.
t = ease(t) = (sinf(PI * (t-0.5f)) + 1.0f) * 0.5f; [This gives a nice ease
in/ease out because of the sin function]
Well, enough about the definition of the LERP. I'll tell you how I came about
loving the LERP. I spent this evening finishing up the code to get the new map
into Political Machine. The problem with our old map (besides some graphic
issues), was that New England and the Atlantic seaboard are way too small to
display any useful information. The solution, put some larger state
representations in the ocean.
So, we've got our extended displays up. Notice that only states
that have an icon in them are displayed. We didn't want to keep the screen too
cluttered. The extended display is only needed when there's action in the small
state. Well, we want the extended display to be seamlessly integrated into the
regular display. This was fine, except for one problem. How would a player put
an icon in the extended display if it wasn't visible? The solution is to
use the LERP to interpolate the picked point onto the extended display. Gotta
love the lerp.
What I did was calculate the u and v for the picked point in the
bounding box of the initial display and used them to interpolate the new
position in the extended display. Isn't that cool? It was also quick and easy.
Well, that was it. I spent another 15 minutes or so fixing up the little bugs
here and there and I was done. For instance error checking to detect when the
user was moving between different points in the same extended display. This
threw off the u/v calculation because the points weren't in the original's
bounding box. Also, allowing a user to move the character between extended
displays, but only visible extended displays. I had to do some checking to make
sure that the displays were visible. My pick projection code works at the mesh
level so we were still hitting the invisible meshes.
I did spend an hour or so tweaking the map display. I found a cool little
color op called Modulate2X. See if you can notice the difference.
It looks like it just lightens the image, it does more than that
really, but the effect looks the same. I just thought that it looked better than
the regular modulate we had before. Don't you?
Anyways, it's getting late and I should get to bed. I at wanted
to at least get Political Machine in a state where Scott and Brad can run with
the new map this week. I'll most likely spend most of my time this week on the
other project. Lotsa stuff to do. Little time.
Oh yeah. Scott, if you're reading this, remind me to tell you
about the extended display arrows. We need to put them into another group so I
can differentiate between them and the actual display. They're throwing off the
bounding box calculations.