## Interpolating Ortho projection to 3d

Sage
Posts: 1,234
Joined: 2002.10
Post: #1
Maybe this is real easy, and I'm just bad at matrices, but I'll ask anyway:

I want to start with an orthographic projection of a flat plane, and then zoom out to reveal that the plane is actually a face of a 3d solid.

I need the orthographic projection to really be orthographic, i.e. as pixel-perfect as gluOrtho2d.

Is there a trick to getting a normal 3d projection matrix lined up so that known 3d coordinates (one plane) will fill the viewport?

thanks.
Oldtimer
Posts: 834
Joined: 2002.09
Post: #2
Wow, this sounds like a really cool idea... I have no real clue as for how to do it, other than manually interpolate the values in the projection matrix by hand. However, I am not a wiz at matrix maths.

I'll try to look into this, it sounds like cool effect.
Member
Posts: 177
Joined: 2002.08
Post: #3
You can convert screen to world coordinates with gluUnproject(). This will give you a 3D point on the near clipping plane. Do it for each corner of the screen and you get a quad that covers it.
Moderator
Posts: 869
Joined: 2003.01
Post: #4
I also think that linearly interpolating your ortho view and final projection matrix is the easiest way to start. For moving the camera, you should still be able just change the modelview matrix accordingly to the camera's motion.

- D.G
lpetrich
Unregistered

Post: #5
Alternatively, you could have your initial view direction be perpendicular to that surface. When rendered, that surface will then have the "right" shape and look as if it was orthographically projected.

This is because OpenGL's perspective transformation is bilinear -- (linear)/(linear):

xs = x/z
ys = y/z

So if the depth z is constant, the transformation on the remaining coordinates will effectively be orthographic.
Sage
Posts: 1,234
Joined: 2002.10
Post: #6
Quote:Originally posted by Mark Levin
You can convert screen to world coordinates with gluUnproject().

Thanks, after looking at a bunch of the gl man pages I got it working.

I tried simple linear interpolation between the 2d & 3d matrices before posting here; it doesn't work because the Z near/far planes are totally different as shown in the man pages.

What did end up working:
1) set up the model / projection / viewport I want
2) get the current values (model for example changes per frame for me) via glGet...
3) gluProject a known point (1,1,1 of a unit cube, for me) on the face I want to fill the the viewport with, to figure out it's Z value in screen coordinates
4) gluUnProject the viewport w,h and that Z value, to get scaling factors for the known point
5) scale the projection matrix [0][0] and [1][1] by those factors.

Now my unit cube's front face will align exactly with the corner of the viewport, and it works with any viewport size or fov. I just interpolate the scaling factors to shift between the ortho & 3d views.
Oldtimer
Posts: 834
Joined: 2002.09
Post: #7
I'd like to see a demo. Care to post one, or write up on it?
Sage
Posts: 1,234
Joined: 2002.10
Post: #8
Quote:Originally posted by Fenris
I'd like to see a demo. Care to post one, or write up on it?

Get the v4 beta referenced in this thread:

then, in game, hold down Control and type "egg" to see the 2D->3D interpolation.
Member
Posts: 304
Joined: 2002.04
Post: #9
cool effect.

I thought of another - possibly easier - way to do this effect. Use a view frustum where the near and far values are extremely large (and so the difference between the two is relatively tiny) - so the the effect of perspective is flattened out. You could have what looks like a 2d map of a city, for example - but as you bring the near and far values back to reasonable values - it becomes a 3d view of the city.

havent tried it yet tho,
Codemattic