Fast pixel-perfect collision detection.

I doubt I am the first to discover this, but I have developed a way to get K access time regardless of the size of the two-dimensional plane you’re working with.

The general idea is to arrange your data in such a way that you can access any point on a two-dimensional plane as a single number and vice versa. For example, given a plane 10 pixels wide by 5 pixels tall, the point (6, 2) will represent 6 + (2 * 10) = 26, or the 26th element of your array. The value stored at this index can be whatever you want; I chose true to mean solid (collision) and false to mean empty (no collision).

To illustrate this, picture your plane as a grid, but instead of using points (x, y pairs) to denote location, you use a single number. Read the grid like you read a book: left-to-right, top-to-bottom. So say you have a 10×5 plane, you’d read it like this…

0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49

These numbers map perfectly as indices to an array whose values are true or false (solid or empty). This way, it doesn’t matter how big your grid/plane/level is, the time required to access element 5 is identical to the time it takes to access element 5,000,000.

Here are some benchmarks in Ruby to show how fast array index lookup is. Each array was accessed 1,000 times with a hard-coded number:

                         user     system      total        real
10,000 elements      0.000000   0.000000   0.000000 (  0.000393)
2,500,000 elements   0.000000   0.000000   0.000000 (  0.000307)

As you can see, even if you perform this operation hundreds of times per second (as you might in a video game) the performance remains good.

I did all this in Ruby and Gosu, but I imagine it’ll work for any language. The basic formula I used to generate the indices looks like this:

rows.each do |row|
  row.each do |col|
    pixels[col + (row * map.width)] = true/false
  end
end

The rest of your game can maintain the traditional (x, y) coordinate system. However, when you want to check for collisions, you must convert that point into its numerical representation. This is identical to the index-calculation I showed you earlier:

x + (y * map.width) # x is col and y is row

If you’re generating tiles of a specific size (e.g. 16×16) from a text file (as in Gosu’s Captain Ruby example), you’re going to have to perform some extra manipulation to create the full range of pixels.

Imagine a text file containing 50 rows of text. Each row contains 100 characters. Each character represents a 16×16 tile in your level. If you perform the array index creation based on the number of characters in your file, you will get 50 * 100 = 5000 pixels instead of the actual (16 * 100) * (16 * 50) = 1,280,000 pixels in your level. Quite the difference.

Don’t legalize it, decriminalize it.

Legalize it! Legalize it! Legalize it! Legalize marijuana! The masses chant. To some, it sounds like a good idea. Thin out America’s prison population, end unnecessary stigmatization, create new jobs and provide the elderly with a powerful, natural medicine.

But what’s that sound? A seemingly single, tiny voice in the corner. What’s it saying?

Don’t legalize it! Don’t legalize it! Don’t legalize it! Don’t legalize marijuana! Don’t legalize any currently illegal drugs! Instead, decriminalize marijuana and all other currently illegal drugs.

The difference appears deceptively subtle at first, so much so that one might wonder if I am indeed rooting for the same cause. I assure you I am not. I will illustrate the differences.

To legalize something is to make it “legal by law”. Which is, in plain words, asking the government for permission and being granted that permission.

Decriminalization, however, would be the deletion of all laws surrounding currently illegal drugs and replacing them with nothing. In effect, the government would have a “hands-off” approach to drugs.

Decriminalization is ideal because it would allow the market (keeping in mind that America’s markets are far from free, so do not call it a “free market”) to work. In effect, doing all the things I mentioned in the first paragraph without government intervention.

So the next time you hear someone talk about legalizing marijuana, or any other drug, please, set them straight.

Pay us, or we will kill you.

The following is a press released located at No State.

PRESS RELEASE

FOR IMMEDIATE RELEASE

Bratislava resident renounces American citizenship, becomes stateless person

BRATISLAVA, SLOVAKIA, 10 December 2008 – Citing US war, human rights abuses, rapacious state capitalism and hypocrisy, Bratislava resident Michael Gogulski announced today that he has renounced his United States citizenship and become a stateless person as a means of “political divorce”.

Gogulski, 36, renounced his citizenship on 8 December 2008 at the American embassy in Bratislava, surrendering his US passport and culminating a two-week process and months of personal preparations. He currently awaits a Certificate of Loss of Nationality of the United States confirming his loss of American citizenship. As Gogulski has no other citizenship, he is now a stateless person.

“I was disgusted to be associated through citizenship with the most dangerous gang of criminals in the world, the United States government. Renouncing my citizenship is a means of achieving a political divorce with that vile institution,” Gogulski said. “American politicians extol their state in terms of liberty, human rights, free markets and the rule of law. Examination of the country’s history and present actions reveals nothing but lies and hypocrisy. The genocide of Native Americans, slavery, nuclear slaughter at Hiroshima and Nagasaki, support for brutal dictators, the torture of innocents at places like Guantánamo and Abu Ghraib, the massive robberies for the benefit of big business in the name of ‘rescuing’ the economy, the world’s biggest prison population, the growth of a domestic police state and the brutal wars of oppression underway in Iraq, Afghanistan and Somalia paint a rather different picture. America, via its government agents, is truly exceptional – exceptionally evil,” he stated.

Gogulski says that when he receives the Certificate of Loss of Nationality he will apply to the Slovak Interior Ministry for a Travel Document – similar to a passport – under the 1954 Convention on the Status of Stateless Persons, which Slovakia signed in 2000. He says that he has no plans to leave Bratislava until then, and that he recognizes that his life without citizenship will be more difficult, especially with respect to travel. But, “if the Schengen Zone is to be my cage,” Gogulski states, “I think it’s large enough for me. There’s enough to explore within Europe to last a lifetime.”

On his personal blog, Gogulski indicates that he works as a freelance translator and editor. He also writes about anarchism and supports the revolutionary theory called agorism, which posits that free-market service providers will compete with and eventually supplant states, giving rise to a voluntary society. “Governments pride themselves on notions of ‘equality’ and ‘rule of law’, but fail to apply the same standards to themselves that their subjects must endure,” he says, explaining his political philosophy. “The foundation of state power, taxation, is robbery. That the robbers have fancy uniforms, impressive titles and the sanction of law does not in the slightest way change the basic formula for extortion: pay us, or we will kill you.”

Michael Gogulski’s blog can be found at www.nostate.com.

Sad conclusion, or cause for celebration?

Might makes right.

Despite the logical prowess of the Austrian School, anarcho-capitalism and libertarianism theory in general, that statement is true.

With eyes wide open, I layed motionless in my bed. The gentle, pulsing glow from my computer provided the only source of light. “Annihilation” by A Perfect Circle played repeatedly.

The power of any social system lies in its mindshare. The flavor of the day, whether freedom or slavery, is subject to the power of might. If I kill you before you kill me, I am in a position of being correct by default; there is no longer a dissenting opinion.

If you disagree with me, I will kill you, too.

Then pen is mightier than the sword.

Given this fundamental understanding, I have a decision to make. To give up my efforts, or persevere.

I choose to persevere. To continue. To spread the ideas. To teach those willing to listen.

Adding rational expressions.

  1. I am adding rational expressions, so I want to find a common denominator.
  2. Common denominator found, I want to multiple every rational expression by the LCD. Additionally, each rational expression should be re-written with its denominator in simplified/factored form so I can cancel out terms.
  3. I should have no more fractions. Now I want to combine like terms and generally solve as I would a linear equation. However, in the event this is a quadratic equation, or an equation to the power of 2, I want to mold the equation into a trinomial of standard form. Once done I will factor the trinomial into a pair of binomials. Once done I will take each binomial and set its value equal to zero. This is known as the multiplication property of zero. Doing this for both binomials should yield two answers for X. Check them.