I want to make a quick demo program showing a cube, or a user loaded model, rotating in screen rendered with one of three projections: perspective, isometric and cavalier.

Using the fixed pipeline, how can I build a projection matrix for cavalier projection?

I think I can start with the orthographic projection matrix and then tweak the values, by eye, until I get the z of the vertices go to the right and up as farther the z is. I want the lines parallel to the z axis rendered as vertical lines 45 degrees rotated to the right.


For a cavalier projection, it looks like you would want to start with an orthographic projection and then apply a shear to the z-axis.

In other words, for OpenGL you would want to multiply the projection matrix on the left by a matrix of the form:

\begin{matrix} 1 & 0 & a & 0 \\ 0 & 1 & a & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{matrix}

where a is the shear factor, which you'd tune to taste. (You could also use two separate shear factors along x and y, if you wanted an angle other than 45 degrees.)

  • \$\begingroup\$ I think this is what I'm after. Just let me do a quick test before mark as answer. \$\endgroup\$ – Hatoru Hansou May 12 '14 at 20:59
  • 1
    \$\begingroup\$ Marked as answer. Just note that OpenGL expects arrays representing matrices being in column-major order. \$\endgroup\$ – Hatoru Hansou May 13 '14 at 0:58
  • \$\begingroup\$ @HatoruHansou: That should not matter in this answer, it is not given in anything that resembles array notation. If there were commas in this, then that might imply something about the order of the elements in memory. This is just a generic matrix, you can figure out that it is supposed to be 1,0,0,0, 0,1,0,0, a,a,1,0, 0,0,0,1 from the API tags. \$\endgroup\$ – Andon M. Coleman May 13 '14 at 1:18
  • 2
    \$\begingroup\$ @HatoruHansou The property of the matrix that matters here is the side from which you multiply in the vectors. In the fixed function pipeline you have post-multiplication (Mv) which results in the a elements being in the third column. If you used pre-multiplication (vM), the a elements would be in the third row instead. Storage order and multiplication side are orthogonal concerns, their only relation is that messing up both at the same time tends to result in something that sometimes appears to be right. \$\endgroup\$ – Lars Viklund May 13 '14 at 2:08
  • 1
    \$\begingroup\$ I didn't take that matrix as an array. The answer is ok as it is but, believe me, someone may arrive here as result of a web search and simply add the commas, some will realize what just happened when running their programs, others may need to think for a while. OpenGL documentation contains warnings about the elements order because people tend to expect the opposite order, isn't it? \$\endgroup\$ – Hatoru Hansou May 13 '14 at 3:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.