Progress report 9/4/03
As I mentioned in my article from earlier today, I wrote a function that could rotate meshes to compensate for 3DStudio Max's camera.
So, now as soon as I load a mesh, I rotate it, scale it, and move it up on the map so that it's above the tilemap rather than skewered by it, and re-calculate the normals so that the lighting will be correct. The rotation, scaling and move up code are very similar. I lock the vertex buffer, and use a while loop to adjust each vertex in the mesh. Re-calculating the normals was really easy, because there's a function in D3DX that does it for you, but I wrote a wrapper function for it:
// get the face count
// get the FVF flags
// calculate vertex size
if ((fvf & D3DFVF_NORMAL) == 0)
hr = D3DXComputeNormals(this->m_pMesh,NULL);
While I was pretty sure that Microsoft was intelligent enough to have normals in their vertex type, the wrapper function is nice because if we ever switch mesh types, we'll be covered.
Joe helped me determine the correct order of operations for modifying the mesh, which was a good thing. I forgot to take my allergy medicine today, so I was having allergic reactions even before Paul started to put together his new desk or our new bookcases were dragged into the lab. I was coughing and sneezing and generally feeling miserable, so I took Sudafed, which I did have on me, even though it tends to have odd effects on me. So my concentration was a bit sketchy in the morning.
I also finally put in some code so that we could click on a ship to select it. It's very rudimentary, since a lot of the work is already done for me in GalCiv 1 and I just have to start porting stuff. But I needed to be able to select different ships. We also could use something to mark that the ship is selected. I was just going to draw a circle, but there's no circle function, and so Joe suggested using a texture. But if I'm going to do that, maybe I should just wait to see if Alex wants to make a cool mesh.
Now that our meshes were modified before we turned them into game objects, instead of having to rotate the object each frame, I could finish making adjustments to the moment and rotation code to account for the change from top down perspective to isometric orthogonal. I also fixed the hit detection so that it wouldn't let the ships go offscreen, and a bug where offscreen objects didn't do hit checks.
Tomorrow, Joe and I will probably have to discuss separating the gfx from the data so that we can make it multi-threaded. He's not going to let me get away with leaving them together for long.