Montag, 23. Februar 2009

New Game Project

The work on my new computer game project has started today. It will be something really cool!

Freitag, 20. Februar 2009

Montag, 16. Februar 2009

Molecular Biology of the Cell

I've bought the famous book by Alberts et al. today, and yes, it is worth the investment: You'll find there a lot of facts about cell biology which aren't mentioned in Wikipedia and which can't be easily googled, either.

I remember my father gave me a book called "The Cell" by Christian de Duve when I was 10 years old. But back then I was more interested in computers and never read more than the first few chapters.

Now cell biology is the subject of science that interests me most.

Donnerstag, 12. Februar 2009

Buggy code at NeHe

I wonder how it's possible that there is buggy code at NeHe. The NeHe website is mentioned by programmers so often in their forum postings that I believe many of them have at least tried using code from that site. So am I the first to notice these bugs or what?

In the bitmap loading routine at NeHe, the bitmap's dimensions are resized to the closest powers of two. This is necessary because otherwise (at least in some implementations) OpenGL won't be able to make a texture out of the bitmap. But: The code presented at NeHe sometimes resizes the bitmap to a size smaller than the original size. Thus parts of the image are cut off. That's stupid and wrong! Moreover, the code uses the log function, which is probably quite inefficient.

Better use my code:

void Bitmap::ResizeImageToClosestPowerOfTwo ()
GLint glMaxTexDim;

glGetIntegerv (GL_MAX_TEXTURE_SIZE, &glMaxTexDim);

if (lWidthPixels <= glMaxTexDim)
lWidthPixels = ClosestPowerOfTwo (lWidthPixels);
lWidthPixels = glMaxTexDim;

if (lHeightPixels <= glMaxTexDim)
lHeightPixels = ClosestPowerOfTwo (lHeightPixels);
lHeightPixels = glMaxTexDim;

long Bitmap::ClosestPowerOfTwo (long v)
bool breakcond = false;
for (long i = 31; i >= 0 && !breakcond; i--)
long temp = v | (1 << i);
if (temp == v)
if (v != (v & (1 << i)))
v = 1 << (i + 1);
breakcond = true;

return v;

Montag, 9. Februar 2009

The world of physiology

I think I'm starting to give birth to my best idea of the past years:
Writing stories about the immune system, about the human body. Extrapolating human physiology to the human world.

Think: How would you describe what the T and B lymphocytes are doing? It's like guards walking around on the streets with big magnets which are able to detect infections in human bodies, and then the human beings are carried to doctors who either give them poisonous injections to kill them (B) or eat them (T).

Couldn't fascinating stories be written on the basis of such analogies? And, moreover, you'd learn far more about pathophysiology and gain a better understanding than by just learning facts from textbooks.

Freitag, 6. Februar 2009

Sequence points (C++)

I bumped into an article about sequence points in C++. ( That's a concept I didn't know yet, but even so, I always intuitively wrote my programs in such a way that these problems are avoided.

Status report

My game project has made good progress; if it continues like this, I'll be done soon.

Dienstag, 3. Februar 2009

Lens effect

There is a cool new 256b intro at, called ind. It shows a rotating sphere divided into several fields, which flicker in funky colours.

This intro is basically based on the lens effect. The lens effect is a distortion that projects all pixels from a square onto a circle surrounding it. How is this done?

If we try to imagine how it works, we will perhaps start with the y coordinates of the projection of the topmost line of the square: We notice that the points in the horizontal center are the topmost ones and the elevation declines to the edges, where it becomes zero, i.e. the edges are printed at the same position as in the square. With what mathematical formula can this be achieved? Simple subtraction wouldn't make it a circle. We need a trigonometric function. Which one? Let's figure it out: We use the distance from the horizontal center point as its parameter. If it is 0, the height must have the highest value, and if it is maximal, the height must be 0. A trigonometric function that has this property is... cosine! So we'll use cosine.

Now we must just consider that the level of elevation also depends on the y coordinate of the original point in the square. The closer we get to the vertical center of the square, the "flatter" the curve becomes. So we also have to multiply with a factor dependent on the y coordinate.

The computation of the x coordinate works in an analogous way.

The code to precalculate the transformations needed for applying the lens effect could basically look like this:

int pos = 0;
for (int y = 0; y < size; y++)
for (int x = 0; x < size; x++)
coords [pos].x = cos (((double) y / center - 1) * 3.1415 / 2) * (((double) x / center) - 1) * factor;
coords [pos].y = cos (((double) x / center - 1) * 3.1415 / 2) * (((double) y / center) - 1) * factor;
pos ++;

Now what's this variable called "factor"? Well, it determines the smoothness of your projection, how much it looks like a real circle. Try inserting various values for it.

Can you find out the optimal value for "factor" - either by trying it out or, even better, by computing it mathematically?