4
\$\begingroup\$

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.

\$\endgroup\$

1 Answer 1

7
\$\begingroup\$

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.)

\$\endgroup\$
5
  • \$\begingroup\$ I think this is what I'm after. Just let me do a quick test before mark as answer. \$\endgroup\$ May 12, 2014 at 20:59
  • 1
    \$\begingroup\$ Marked as answer. Just note that OpenGL expects arrays representing matrices being in column-major order. \$\endgroup\$ May 13, 2014 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\$ May 13, 2014 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\$ May 13, 2014 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\$ May 13, 2014 at 3:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .