The Real M.V.P. Is Trinity

It’s ironic that Trinity makes Neo ask “What Is The Matrix?”, because it takes three Matrices to position every vertex of a model in 3-D space. It’s so appropriate that one of the first things Trinity does is float in space as the camera rotates on the Y-Axis. The M.V.P. Matrix, or Model-View-Projection, is a Model Matrix for the object’s location, times the View Matrix of the camera, times the Projection Matrix of the screen.

I don’t know much about how it works on the inside, because the Matrix Math library in OpenTK takes care of that. I would have learned more about Matrix math in high school, but instead I wrote a program on my TI-82 graphing calculator using its’ built-in Matrix functions. The app would pause at each step and print out the numbers so that I could “show my work”.

Fortunately for me there are Matrix math libraries, and I’ve got a much bigger calculator. Because even if I remembered anything else from high school at this point, I never really even learned Matrix math to begin with. So if Matrix math sounds scary to you just keep in mind I used to feel the same way.

A Matrix can be used solely to Translate, Rotate, or Scale, or a combination of those. Multiplying them together makes a Matrix that does a combination of actions, and all of the 16 numbers involved are stored in one 4×4 Matrix. You can even take out a Translation or Scaling and keep the Rotation, or other such possibilities.

The Model Matrix is the simplest to explain: it contains the Transformation, Rotation, and Scaling of the object you’re trying to draw. The View Matrix, AKA the WorldView Matrix, starts with the location of the Camera, but flipped negative. Essentially, it translates the World away from the Player, and then the Model Matrix moves the Player back to the center of the Camera’s focus. The Translate is multiplied a Rotate around the Y-axis, then a Rotate up or down on the X-axis, and a Tilt rotation on the Z-axis. Finally, we Translate on the Z-Axis to Zoom out, which uses a negative number.

Then comes the Projection Matrix, which is based on the Aspect Ratio of the screen, or the Width divided by Height. The other parameters are the Field of View, and the Near and Far drawing distance. Field of View, as you may know, is for sniper zooming if the value is below 1.0, and wide angle view above 1.0, which becomes a fish-eye lens if you push it high enough.

The Near and Far parameters control how close and far from the screen objects will be clipped. If this range is too high, the Depth Buffer loses precision. You’ll wind up with “depth flickering” if two far-away objects are close enough. In the JEOZ Engine I use more than one Projection Matrix for close or far rendering.

Now if you’re like me and you are already familiar with classic OpenGL Immediate Mode, or as I lovingly call it, glIAmAnIdiotMode, the View Matrix is done in the opposite sequence. First you Zoom out, then Rotate, then Translate. Immediate mode is complely deprecated, so I felt self-deprecation was in order. From now on it should be referred to as a pejorative just to make sure no one is foolish enough to keep using it. My only defense for using it at first is that I already knew it from back in 1999, and I knew it wouldn’t be too difficult to transition later. JEOZ is fully modernized now.

Coincidentally, I was learning about Matrices in math class in 1998, then The Matrix came out in 1999, and I began OpenGL a couple months after that. I suppose Morpheus was right, “There are no accidents.”

Leave a Reply