Sunday, December 21, 2008

INTRODUCTION TO 3D GRAPHICS

This blog entry is to document everything that I have done so far for intro to 3d. I have been so disorganised this yea it is untrue. I have found this module extremely difficult, which caused me to get behind with the work, as it was taking me two weeks rather than one to get each section done.

Lets begin at week 4

This is where it all started to go wrong. This week I had to implement a virtual camera this used my matrix class extensively as we needed to create a view matrix based on position and rotation passed into the method and second to store the projection matrix. The next task was to get the program to load models from Quake 2 (.md2 file format). We were given the code for this as it would have taken an absolute age to get it working by ourselves. The main problem I had this week was the camera class. I just over complicated the entire thing, I could tell you what the camera had to had and how you calculated each matrix but I could not write it down in code, but with a little help from my lecturer I managed to get it working but a week after I should have.

Week 5

This week was the big one, where we first got something rendering on screen. First of all I had to finish implementing the camera class, by giving it the screen transform to complete the set of matrices the renderer needed to display models on screen.

Next was getting a wireframe on screen this took a while to implement as I was stepping through what we had been told to implement slowly making sure is was getting it right. To begin with I had strange bug, where I was getting the lines on screen but only two and they filled the screen. This was due to my matrix multiplication method was calculating using the transpose of one of the matrices in the calculation. With that fixed I then had the problem that there was nothing on screen. After 4 hours of looking I found that when I dehomogonised the verts of the model, it wasn't just dividing the verts value by w but adding the result to the original value meaning the value was in the thousands when the screen transform was peformed on them placing the model well out of view of the camera. So instead of saying

_transformedVerts[i].Divide(_transformedVerts[i]._w);

I changed it to

_transformedVerts[i] = _transformedVerts[i].Divide(_transformedVerts[i]._w);

After that I had my model cube on screen. Next was to apply rotation to it, which was pretty straight forward I found as I was just applying a rotation matrix to the original verts at the very beginning of the update before anything else was dealt with. Week 6

I was starting to catch up with the work this week as I had my wirframe on screen and rotating. The next job was to cull the backfaces of the model as these would not be seen if the model is solid and so would be a waste of time drawing them on the screen.


After that we were given the task of sorting the verts so they were in some kind of order so that verts at the back were being drawn first and verts at the front being drawn last. After that was getting some solid colour on the model. The result was a model that looked 2D as there was no shading so just looked like a solid object. This is where I fell behind again, lighting took up a lot of time as I got extremely confused and over complicated things again. This took me some time to get sorted and eventually got to a point where I had something on screen but it was all blocky and wasn't actually shading. It was either solid colour or black. After realising I had missed out a few lines and moving the where the calculation for the light was done, I had what looked like an x-ray on screen. And after another week (into week 10 now, really behind, remember this is week 7 work) I finally had the model shading properly on screen. After that I stupidly stopped working on the renderer for a week to my Game Development Techniques project to a point where I was nearly finished.

So in week 11 I started to look at making the renderer work with scanlines and setting pixels to the right colour for the polygons rather than using Gdi+ FillPolygon() method.

Scanlines really confused me and it took me several attempts to understand it properly and get it working. Whan I finally had something on screen I had two problems. The first was that the polygons were a little spikey in places and the second was half the polygons were not being rendered. The first problem was due to the calculation of the scanlines is done using floats and ints. When calculating the differences of x and y of two verts the values had to be cast as ints as so not to make the spikes meaning the float result didn't have too main numbers after the point.
There next problem was that each polygon is drawn separately and so becuase of this applying scanlines to the entire window would be silly! So as to limit the amount of scanline being looked at I had a minimum and maximum y value which would be the top and bottom of the polygon respectively as 0 is the top of the screen. But when calculating the max and min values I was checking the wrong way and that meant I was only getting half of the polygons. So this is where I got up to for the deadline of the project. But I will be carrying on with it over Christmas, so that it is the best it can ever be.

Here is an image of the actual program handed in for the deadline. Each model has 2 directional lights on them and the polygons are being rendered using scanlines.

No comments: