## Montag, 23. Februar 2009

### New Game Project

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

## Samstag, 21. Februar 2009

## Freitag, 20. Februar 2009

### Biology Quiz

http://www.biologie-online.eu/test

14/15 answers right - seems like I

14/15 answers right - seems like I

*did*learn something at university after all.## 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.

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);

else

lWidthPixels = glMaxTexDim;

if (lHeightPixels <= glMaxTexDim)

lHeightPixels = ClosestPowerOfTwo (lHeightPixels);

else

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;

}

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);

else

lWidthPixels = glMaxTexDim;

if (lHeightPixels <= glMaxTexDim)

lHeightPixels = ClosestPowerOfTwo (lHeightPixels);

else

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.

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.

## Samstag, 7. Februar 2009

### When a CV makes you wonder...

Getting informed on the PhD programs offered at my medical university, I was reading the CVs of some of the group leaders, and I was surprised to see that a full professor of biochemistry mentioned in his CV that he has passed all grades at high school as well as his school leaving examination with highest honors. He is a full professor; why does he mention his successes at school? Isn't just being a professor a sign of excellence?

Mentioning one's successes at school makes sense if you haven't completed a degree yet. But once you have a degree, your performance at school becomes irrelevant. The degree is much more important than what you did at school. And once you are working scientifically and have made interesting new discoveries, even your degree becomes uninteresting.

Therefore, since I already have a first degree, I've decided to remove the piece of information about my school-leaving examination from my CV.

Mentioning one's successes at school makes sense if you haven't completed a degree yet. But once you have a degree, your performance at school becomes irrelevant. The degree is much more important than what you did at school. And once you are working scientifically and have made interesting new discoveries, even your degree becomes uninteresting.

Therefore, since I already have a first degree, I've decided to remove the piece of information about my school-leaving examination from my CV.

### LOL!

From the homepage of another professor of biochemistry:

"In 1979 he returned to Vienna and took a position as University Assistant; he obtained the venera docendi for Biochemistry in 1991 and is currently holding a position as Assistant Professor at the Department of Medical Biochemistry."

Venera = sexually transmitted diseases. Wow, what an embarrassing typo!

"In 1979 he returned to Vienna and took a position as University Assistant; he obtained the venera docendi for Biochemistry in 1991 and is currently holding a position as Assistant Professor at the Department of Medical Biochemistry."

Venera = sexually transmitted diseases. Wow, what an embarrassing typo!

## Freitag, 6. Februar 2009

### Sequence points (C++)

I bumped into an article about sequence points in C++. (http://www.angelikalanger.com/Articles/VSJ/SequencePoints/SequencePoints.html) 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.

## Dienstag, 3. Februar 2009

### Lens effect

There is a cool new 256b intro at pouet.net, 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?

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?

Abonnieren
Posts (Atom)