8
\$\begingroup\$

I've been trying to make a formula for the projection matrix where your vertical axis is projected orthographically but your horizontal axis will have perspective to it.

So the view frustum would look like this: View frustrum

I studied how the formulae of orthographic projection and perspective projection and how they where achieved. And tried to modify those to try to reach projection I wanted. It seemed to me it wasn't possible to have one axis scale to Z and the other not (or to have them scale at a different factor).

It it possible to reach the perspective I want? If so what would the projection matrix look like?

\$\endgroup\$
3
  • 3
    \$\begingroup\$ That's one seriously weird looking frustum... Can you share with us why you need something like that? \$\endgroup\$ Jul 9, 2015 at 19:53
  • \$\begingroup\$ I'de like to use it for the camera of a game I'm working on. It's a 2D sideview game, but I'de like to have objects move paralax over eachother, without having them come from the ground / ceiling when the camera moves vertical. \$\endgroup\$ Jul 10, 2015 at 9:38
  • \$\begingroup\$ That's a great project and question then. I hope you will find an answer for that (though this kind of camera is not what you see everyday). \$\endgroup\$ Jul 10, 2015 at 12:25

2 Answers 2

2
\$\begingroup\$

This projection matrix should do the trick:

.tg  {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
<table class="tg">
  <tr>
    <th class="tg-031e">1/r</th>
    <th class="tg-031e">0</th>
    <th class="tg-031e">0</th>
    <th class="tg-031e">0</th>
  </tr>
  <tr>
    <td class="tg-031e">0</td>
    <td class="tg-031e">1/t</td>
    <td class="tg-031e">0</td>
    <td class="tg-031e">0</td>
  </tr>
  <tr>
    <td class="tg-031e">0</td>
    <td class="tg-031e">0</td>
    <td class="tg-031e">-2/(f-n)</td>
    <td class="tg-031e">-(f+n)/(f-n)</td>
  </tr>
</table>

r = half the width of nearplane

t = half the height of nearplane

f = distance to farplane

n = distance to nearplane

So for example, try picking:

r = 0.1 (width will be 0.2)

t = 0.5 (height will be 1.0)

f = 1000 (far plane at distance 1000)

n = 1 (nearplane at distance 1)

\$\endgroup\$
0
\$\begingroup\$

Unfortunately, I don't think this is possible by just altering the projection matrix. After the projection matrix, the final screen coordinates are calculated by dividing (x, y, z) by w. For a perspective matrix, w is set to z. For a orthographic matrix, w is set to 1. You can't have a different w values for horizontal versus vertical. The other answer to this question is just a standard orthographic matrix.

If you have access to the shader itself and are willing to add another step, you could just use an orthographic projection but do the horizontal perspective correction manually.

\$\endgroup\$

You must log in to answer this question.

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