Saturday 31 October 2009

Something grey and scratchy

Hallo.

My original plan for this week was to gut all of the content from my previous game, extend the rendering capabilities, and make a new game; this hasn't happened. 

Instead I decided to stop dicking about with pseudo 3D stuff and mash out the full renderer (or at least the core of it) in a blitzkrieg of code and relentless. Animating simple trees and spiders had got me in the mood for some more procedural animating too, so I decided to trial-run  my new renderer with a procedurally animated robot-man. The code I used to move his arms and legs was very similar to the methods used on the spiders, with the exception that I extended the algorithm to accept more parameters, so a greater range of 2-bone relationships can be created. Thar she is:

Technical crap. 

One of the first things I did once stuff was drawing on screen was try to optimize, as it was hella slow. Aside from standard stuff like avoiding divisions, not assigning memory more often than necessary etc... the thing which really made a massive impact was switching from using Gdi's Bitmap::SetPixel(x,y,color), to using a unsigned char* to directly edit each byte of colour in memory.

Each frame the renderer draws to a bitmap, before drawing the entire thing to screen at the end of the frame. In the previous aberration I was drawing directly to the screen using lots of small rectangles for pixels.

As for shading, I decided that Gouraud was the way to go for now, especially since I actually want to use the renderer to make a playable game. This probably took the longest out of everything to get right, although when I started implementing the shading I didn't really know what I was doing either.

To create the human I made Model and Bone classes, with the idea that a bone can contain its own child bone. However I ended up just chunking a whole bunch of bones inside a MHuman : Model and writing the code for the animation directly into MHuman. In retrospect, had the ends of the legs and arms been child-bones of the top parts it would have made my life easier. This is right at the top of the todo list next time I make a model. 

The human is made out of lots of differently-scaled versions of the same shape, each created using the same function. Hardcoding even that simple shape (10 verts, 16 polys) took a long time, so I think all my future content will have to created in a highly algorithmic way... I mean, I could just make something in a nice 3d rendering package and write an importer... but y'know it just wouldn't be the same :P 

Massif props to Bob Powell, whoever that is, for explaining about locking and unlocking a bitmap's bits in his Gdi Faq.

Also massif props to Lukasz Pasek for many little tips on Gdi+ and shading!


AdiĆ³s

No comments:

Post a Comment