6

I want to mix a perspective and orthographic view, but I can't get it to work.

I want X and Y coordinates to be orthographic and Z perspective. For clarification I added a sketch of the desired transformation from OpenGL coordinates to screen display:

sketch of desired view

(I started from a tutorial, but couldn't find how to get values top, bottom, etc.)

hardmooth
  • 1,202
  • 2
  • 19
  • 36
  • Which version of OpenGL are you using? and do you already use custom Matrices? – vallentin Nov 13 '13 at 16:06
  • You want to combine a perspective matrix and a shearing matrix, I believe... I don't think there's a command for building a shearing matrix. You'll have to construct it yourself. – godel9 Nov 13 '13 at 17:18
  • The coordinates on the diagram don't look right, with 6 vertices having x coordinate 10. – JWWalker Nov 13 '13 at 18:02
  • @JWWalker: I fixed the coordinates, thanks for the hint. – hardmooth Nov 14 '13 at 08:07

2 Answers2

1

What you've drawn is simply perspective, not a mix. You just have to make sure that the viewing direction is parallel to the z axis to make the front and back faces of the box stay rectangular.

JWWalker
  • 22,385
  • 6
  • 55
  • 76
  • I've tried that and it works. Once I figured out, how to scale the scene such that the scene is maximized inside the view frustum, I'll post it as answer. – hardmooth Nov 19 '13 at 13:17
0

You could probably use glFrustum to achieve this.

If you use a standard perspective matrix and the camera faces the box front on, X/Y will be uniform, however movement away from the camera will move the X/Y coordinates towards the centre, shrinking them for a standard parallax effect. What you've drawn is movement towards the top of the window. All you need to do is crop the perspective projection to below its standard centre. That's where glFrustum comes in - move the normally symmetrical top/bottom arguments down, align the camera/view matrix along the axis you want and you should have the desired projection.

Any rotation of the camera/view will destroy the uniform projection in the X/Y plane. For camera movement you're then limited to panning and moving the glFrustum bounds.

EDIT Come to think of it, you could probably just throw in a glTranslatef(shearX, shearY, 0) before the call to gluPerspective and achieve the same thing.

jozxyqk
  • 16,424
  • 12
  • 91
  • 180