How to prevent deformation when rotating around line of sight in OpenGL?

I drew an ellipse in the XZ plane and slightly increased my perspective along the Y axis and back to Z, looking at the center of the ellipse at a 45 degree angle, using gluPerspective () to set my frustrum view.

ellipse

The non-opposing, large axis of the ellipse spans the width of my viewport. When I rotate 90 degrees relative to my line of sight, the large axis of the ellipse now spans the height of my viewport, thereby warping the ellipse (in which case it becomes less eccentric).

rotated ellipse

What do I need to do to prevent this deformation (or at least explain it), so rotating around the line of sight retains the perceived large axis of the ellipse (in this case, causing it to go beyond the viewing window)?

+4
source share
3 answers

It looks like you are using 1.0 as an aspect when calling gluPerspective (). You should use width / height. For example, if your viewport is 640x480, you should use 1.33333 as an aspect argument.

+5
source

According to the OpenGL specification:

void gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar ) 

The aspect should be a function of the width and height of the window. In particular, the width is divided by height (but watch for division by zero).

Perhaps you are using 1 as an aspect that is not accurate if your window is not square.

+3
source

It looks like the aspect parameter of your gluPerspective setting needs to be configured. See the man page . If your window was physically square, the aspect ratio would be 1, and your problem would disappear. However, your window is rectangular, so trimming the view should not be square.

Set the proportions to window_width / window_height and your ellipse should look right. Note that you need to update it whenever the window is resized; if you use GLUT, install glutReshapeFunc and recount the projection matrix there.

+1
source

Source: https://habr.com/ru/post/1276785/


All Articles