Saturday, June 12, 2010

Simple Easing

I found a really nice system for easing values over time. I haven't come up with a name for it, though. There's only one catch: in its current state, it only works over fixed time intervals. But there's probably a really simple fix for that.

In a normal code scenario (I'm going to use C) you declare a variable like this:
int variable;
Now, to use this now special "easing" system of variable change, you simply add two more variables to your declaration. The declaration now looks like this:
int variable;
int variableWant;
const int VARIABLE_SPEED = 3;
The first one is the original variable, which I'll call the "actual" value. The second one is the "want" variable, and the third is the "speed" variable. The "want" value is the one you will be changing, while the "actual" value is the one you'll be reading. "Want" is kinda like the "set" variable, while "actual" is the "get" variable. You can use any naming scheme for these variables, but those are the ones I use.

To make this work, you add the following code (which corresponds to the naming scheme above) to a regular-interval function:
variable = (variable * (VARIABLE_SPEED - 1) + variableWant) / VARIABLE_SPEED;
This may look complicated at first, but it's actually really simple. It calculates a new "actual" value based on the "actual" and "want" values by averaging them with specific weight on "actual." If you remember anything about averaging (which you should) you should remember that the last step is to divide by the number of added terms. Well, if you look above, there are (VARIABLE_SPEED - 1) "actual" terms, while there is 1 "want" term. This means that the total number of terms is (VARIABLE_SPEED - 1) + 1, or simply VARIABLE_SPEED, which is what we divide by.

The last variable which hasn't gotten enough attention is VARIABLE_SPEED. This variable's function is simple: it determines the rate at which the ease takes place. If this value is 1, the ease will happen instantly. If the value is 3, the ease will happen rather slow. For a value of 100, you'll be waiting a while.

The only issue with this method of variable change over time is that, theoretically, for values of VARIABLE_SPEED greater than 1, the "actual" value never actually becomes the "want" value. Adding this functionality simply means adding an if statement that sets the "actual" to the "want" for differences less than some constant.

Saturday, May 22, 2010

Pink Floyd vs Muse

I'm a HUGE Pink Floyd fan. Their music is genius! I've never heard such an expressive band in my life!

Anyway, I have a friend who is a huge fan of this new band called Muse. I asked him what kind of music Muse makes. He replied "It's sorta space rock kinda stuff." Now Pink Floyd is also space rock, so I said "Oh, kinda like Pink Floyd?" He said "No, definitely nothing like that. Don't ever compare them to Pink Floyd again!" This got me kinda irritated because I love Pink Floyd and because no band in the history of rock music can compare to Pink Floyd.

So I did a bit of reading, listened to a few of their songs on YouTube (what comes up when you search "Muse.") I decided to be fair, because I'd hate for someone to judge Pink Floyd by "Another Brick in the Wall (Part 2)" and "Comfortably Numb," so I went out to Lala and listened to their entire "The Resistance" album.

How in the world can anybody say Muse is better than Pink Floyd?

I won't go into detail about why Pink Floyd is better than Muse, or why my musical tastes are better or somehow "more correct" than yours, but Pink Floyd changed the face of music. Muse simply added a pop music twist to it and jumped on the space rock bandwagon.

Pink Floyd is one of the best selling bands of time, right up there with Led Zeppelin and the Rolling Stones, and for a very good reason. Not only are they sonically amazing, but their lyrics are so poetic and are something for everyone to relate to.

Change is good and it's foolish to be stuck in the past, but when things keep getting worse and worse, can you blame me for wanting to go back?

From Pink Floyd's "Dark Side of the Moon," which was a top 100 selling album for 12 years:

Amazing lyrics, amazing sound, amazing guitar solo. On my top ten PF songs.

Compare to this immensely popular song from Muse:

Mediocre lyrics, okayish sound, and lame guitar solo.

Friday, April 16, 2010

If there was no government...

If the government just crashed, for whatever reason, and was unable to enforce any laws or provide any government services:

Obviously, crime would be on the rise. It would probably start with small crimes like theft. As people became used to the idea of crime, things would crawl their way up to murder.

The first and most important thing would be to group up with other people. Survival would be much easier in groups.

As the group grew, we would have to find some sort of place to base our operations. A school of some sort would probably be the best place to go. Schools have all of the infrastructure necessary to run a small group like that.

The group would start out as socialistic, with each person giving something to the group to help each other survive. The driving force behind capitalism is greed, so such a system would be too dangerous at first.

The two major focuses of the group at first would be:
  • Building an effective defense system
  • Finding sources of energy (eg. food, gas, solar power, etc.)
We could, in theory, simply rob stores for these things, but that could quickly become problematic.

The best way to go about this, at first, would be to find and defend various supermarkets. This is still robbing, but it's on a much larger scale. Eventually, however, we would have to find renewable sources of energy.

Once we have enough to support the growth of our group, we would have to start focusing on increasing the size of the group.

Diplomacy with other groups would be very important.

For example, one sort of diplomatic situation might go as follows:
  • Some members of the group go to a supermarket which is controlled by another group.

  • We ask if our leader can talk with the other group's leader.

  • If they don't want us talking with their leader, then we'll just leave them alone and be done with it.

  • If they let us, then we'll discuss merging groups. There would be innumerable advantages to merging: bigger is better, we can share, etc.

  • If they like the idea of merging, then we merge.
If our group gets big enough, there will probably be other equally large groups. Then we can reinstitute capitalism, trade with other groups, and have wars with other groups.

Things will be back to normal :)

Wednesday, April 7, 2010

Polygon Collision Detection and Response

Hello.

To express my regret for not having posted recently, I'm going to explain my method of polygon collision detection and response.

It's quite simple really. For polygons described in a series of points and a single test point, here's a description of the algorithm I use to move that point the shortest distance outside the polygon:
  • Assume the current closest point is infinitely far away.
  • For every single line segment between the points:
    • Find the point closest to the test point on that segment. You can use whatever method you wish for this part. This part's just a little bit of vector calculus. Here's a hint: if the closest point is not one of the endpoints on the segment, the vector to it from the test point will be perpendicular to the segment.
    • If that point is closer to the test point then the current closest point, then it becomes the current closest point
  • The current closest point is the fastest way out of the polygon.
There's a lot of math involved, but it's simple linear algebra and vector stuff. I'm sure you can figure it out.

Saturday, February 13, 2010

Night of '10 Jan 11 - JJ Abrams

It's been a while since I've had a weird dream. I've had trouble remembering them. But I remembered this one for some reason.

Recently I got the Adobe CS4 Production Premium, complete with Premiere, After Effects, Illustrator, Photoshop, and many others. This has thrown me into a filmmaking frenzy. I haven't made any real full length feature films yet (I'll let you know when I do) but I'm beginning to get all of these great ideas for them. It's as if having the tools to create has inspired creation.

Anyway, last night I had this dream...

I had a dream that I came up with some genius idea for a movie, and that some famous producer was considering funding it. Naturally, I was flattered that any big name producer would even consider producing a film by an inexperienced director like myself.

It turns out that this producer was the one and only J.J. Abrams. Abrams is my favorite filmmaker of all time. I contacted him, even though every part of me believed he wouldn't want to deal with me. I thought I would do it just so I could say I did. You can imagine my shock when I got a phone call saying he was coming over to my house to talk with me about my idea!

So he shows up at my house, and as I open the door, I see Mr. Thompson, a teacher of mine, staring right back at me.

MR. THOMPSON WAS J.J. ABRAMS! I asked him why he never told me this secret, and he said it was because he never thought it was relevant. This made things even better because he knows me and would undoubtedly want to produce my film.

Then I woke up.

Saturday, February 6, 2010

C struct Inheritance

Inheritance is generally thought of as belonging to object oriented programming languages like C++ and Python, but it can actually work with procedural languages like C.

In C, there is a data type called the struct, which is basically a collection of various types.

A struct typedef like this:

typedef struct
{
int val1;
char *name;
} super_t;

can be "sub-structed" by another struct typedef like this:

typedef struct
{
super_t sup; // this HAS to go at the beginning of the struct
char otherval;
} sub_t;


With the types set up like this, if a pointer to a variable of type sub_t is casted to a pointer to super_t, then the attributes of super_t can be accessed like normal.

The only problem is that a sub_t instance needs to get the values of its superclass through the sup variable.

Saturday, January 30, 2010

Film Leaders FTW!

I love leaders. I've made a number of them in After Effects and add them to all my projects whenever I can. They're both useful and awesome. You can cram a ton of information in them, like producer, aspect ratio, title, director, actors names, legal stuff. It's like the fine print. The circle around the numbers also helps make sure the aspect ratio is correct, and the tone should be a perfect 1kHz tone on the 2 (this one is .88kHz) to help make sure frame rate and audio sync are correct.

I don't care much for standardizing leaders, especially with the way video is in today's world. If there is to be any standardization, it should be on what information should be contained within a leader. I think that 4 seconds of assurance that the film is being displayed properly is good, and that it's always good to hide some secret proof that it's your movie.