Monday, February 26, 2007

NeHe Lesson 09: Moving Bitmaps In 3D Space

The 9th lesson covers more ground on moving things around and applying color to black and white textures. The lesson can be read here.

This is the first time in these tutorials where we see a nice little example on how to use the D's foreach loop. It is used to initialize all the stars in the array. It is very clean looking and easy to follow. The only thing to remember in a situation like this, is to use the 'inout' modifier on the star variable so that the changes stick.

foreach (i, inout star ; stars)
{
star.angle = 0.0f;
star.dist = cast(float)i / stars.length * 5.0f;
star.r = rand.next() % 256;
star.g = rand.next() % 256;
star.b = rand.next() % 256;
}

The foreach loop is used in the drawing function also. There too the 'inout' modifier must be used because we update the values in the star at the end.

The rest of the code can be read here.

5 comments:

Mason said...

Where can I find a good star.bmp?

OdeFu said...

Don't know about good, but the original image can be downloaded from here.

Mason said...

Great, thanks a lot.

I also appreciate you porting all the lessons to D, and with Tango!!!! Tango is definitely the way to go. Hopefully it will leave the beta stage soon....

Your lessons are a big help!

Have you taken a look at the ArcLib library project over at dsource.org? Do you think it's better to stick with SDL and openGL, or use a library?

OdeFu said...

Well, these are not my lessons. I'm just writing the code in D and putting them up for others. But thanks just the same. :)

I haven't really looked at the ArcLib, but as far as I know it's 2D only. So if that is what you need and want to do games then I suggest using a library like ArcLib. If you want to dig deeper then it would be a good idea to write one yourself.

maswey said...

thank you nice sharing
cep programsymbian programnokia programhtml kodlarıbedava cep oyunlarıcilt bakımı