A Class With A View
Another week passed, and another stepping stone completed on the road to rendering. This time around, I've been working through Zerbst and Duvel's specs for the cameras that will display a view of the game world to both player and creator...
The authors' watchword for this section, as well as the upcoming material for the rest of the base renderer was compromise. Specifically, a compromise between flexibility and simplicity. The access points into the engine must be simple enough to be usable by a novice game developer, without being so simple as to restrict the developer's ability to use the engine.
The functions allowing for camera manipulation. Seems simple enough, no?
And as it turned out, simplicity was quite important for simulating a camera in a 3D environment, as there turned out to be quite a bit more work for this subsystem than I bargained for. While there is still plenty of rendering work yet to do, what has been completed is the ability for the engine to calculate the transformation matrices that allow conversion between the coordinate systems of the 3D models, the game world, and the camera, as well as a couple matrices for mapping the 3D game world onto the 2D plane that is the camera's view. As it turned out, the math for this was rather difficult to wrap my head around from looking only at code.
Thankfully, Zerbst and Duvel provided some suggestions for topics on MSDN to help me understand the formulae for projection matrices, as well as Direct3D concepts like view ports. That ability of an author to admit when they are simplifying or underexplaining is highly appreciated! Pragmatic as well, since I'm sure the book would be at least twice its already prodigious length if the authors had taken the time to give in-depth explanations of every concept and derivations of every formula.
MSDN makes changing coordinate systems with matrices much easier to wrap your head around!
As I was reading and implementing, I did come across a couple items that struck me as having potential for being deprecated. Firstly, the authors noted a difference between OpenGL and Direct3D, specifically that OpenGL provides a helping hand as far as batching triangles for render calls is concerned, and I found myself wondering if this is still the case. This difference is highly relevant, as the next work on my plate is the implementation of a vertex manager that will do what OpenGL does out of the box! So the question is: have the later updates of DirectX 9, or even DirectX 10 or 11 improved this batching behavior at all? Or is this vertex manager still necessary to attain reasonable performance?
The second helpful tip that stuck in my mind was a note by Zerbst and Duvel that "modern" graphics cards and their drivers do not have a way to calculate an object's anticipated screen position withoutalso rendering that object. Hence, 3D Game Engine Programming shows the reader how to implement this function manually. However, this functionality seems like something so valuable and convenient that I wonder if it hasn't been implemented in modern graphics technology.
I'm not sure, but if any of you know the answers to these questions (or any other opinions or feedback, of course!) feel free to contact me.
Progress So Far: Implemented functions for building coordinate system and projection matrix transforms for 2D, orthogonal, and projection viewing modes.