0

I don't know how to setup distance

where I should stand to look at my 2d stuff(which at center there is a ball pos:1024/2,768/2)

I use gluLookAt and glPerspective to give my 2d rotated object more 3d feel

anyway here is the code I use with glOrtho:

    glMatrixMode ( GL_PROJECTION );
    glLoadIdentity(); 
    glOrthof ( 0, 1024, 768, 0, 0, 1000.0f );
    glMatrixMode ( GL_MODELVIEW );
    glLoadIdentity();

and this is when I try to setup with glPerspective and gluLookAt:

  glMatrixMode ( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective(90,1024/768,0,300);
    gluLookAt(1024 * 0.5,768 * 0.5f,-????,   1024 * 0.5,768 * 0.5,0,   0,-1,0);
    glMatrixMode ( GL_MODELVIEW );
    glLoadIdentity();

Basically I just want those codes that works the same,I am not sure how to setup the fovy value of gluPerspective,and the ??? from gluLookAt,how to project the full size with width 1024,and height 768?

4

1 回答 1

0

Well glOrtho is supposed to yield a parallel projection, so essentially using gluPerspective is going exactly the other way. If you're hoping to find a special case of gluPerspective that acts like glOrtho, the problem is that the matrices they generate are different in some ways you can't reach - note the bottom right corner, in particular, in what they generate:

glOrtho

   |     2                               |
   |----------      0          0      t  |
   |right-left                         x |
   |                                     |
   |                 2                   |
   |    0       ----------     0      t  |
   |            top-bottom             y |
   |                                     |
   |                                     |
   |    0           0          -2        |
   |                        --------  t  |
   |                        far-near   z |
   |                                     |
   |    0           0          0      1  |


gluPerspective

   |    f                                   |
   |  ------  0      0            0         |
   |  aspect                                |
   |                                        |
   |    0     f      0            0         |
   |                                        |
   |             zFar+zNear  2*zFar*zNear   |
   |    0     0  ----------  ------------   |
   |             zNear-zFar   zNear-zFar    |
   |                                        |
   |    0     0      -1           0         |

So it's going to be hard to set the 2/(top-bottom) and the bottom row correctly, for starters.

If this line is the core of your issue:

gluLookAt(1024 * 0.5,768 * 0.5f,-????,   1024 * 0.5,768 * 0.5,0,   0,-1,0);

...then just set thee -???? to a positive value indicating the distance to your eye from the center of the scene (OpenGL's positive Z points towards the viewer).

于 2012-11-20T13:08:21.320 回答