Interpolating Ortho projection to 3d
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 pixelperfect 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.
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 pixelperfect 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.
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.
I'll try to look into this, it sounds like cool effect.
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.
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
 D.G
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.
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.
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.
I'd like to see a demo. Care to post one, or write up on it?
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:
http://www.idevgames.com/forum/showthrea...eadid=2586
then, in game, hold down Control and type "egg" to see the 2D>3D interpolation.
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
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
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
3D in Ortho  bmantzey  5  4,053 
Nov 20, 2008 02:34 AM Last Post: DoG 

Projection Matrix vs. Animation Speed  jbirac  0  1,860 
Dec 20, 2005 12:50 AM Last Post: jbirac 

Ortho + Aspect Ratios  jSTIN  2  3,050 
Apr 6, 2005 09:21 AM Last Post: jSTIN 

2D to 3D and back (Ortho and Perspective)  Phate  5  5,615 
Nov 30, 2003 10:56 AM Last Post: AnotherJake 

Ortho problems  Kattmat  6  3,514 
Oct 12, 2003 12:15 PM Last Post: Kattmat 