Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent deformation when rotating about the line-of-sight in OpenGL?

Tags:

c

opengl

I've drawn an ellipse in the XZ plane, and set my perspective slightly up on the Y-axis and back on the Z, looking at the center of ellipse from a 45-degree angle, using gluPerspective() to set my viewing frustrum.

ellipse

Unrotated, the major axis of the ellipse spans the width of my viewport. When I rotate 90-degrees about my line-of-sight, the major axis of the ellipse now spans the height of my viewport, thus deforming the ellipse (in this case, making it appear less eccentric).

rotated ellipse

What do I need to do to prevent this deformation (or at least account for it), so rotation about the line-of-sight preserves the perceived major axis of the ellipse (in this case, causing it to go beyond the viewport)?

like image 463
rampion Avatar asked Jan 25 '23 03:01

rampion


2 Answers

It looks like you're using 1.0 as the aspect when you call gluPerspective(). You should use width/height. For example, if your viewport is 640x480, you would use 1.33333 as the aspect argument.

like image 73
shea241 Avatar answered Jan 29 '23 22:01

shea241


According to the OpenGL Spec:

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

Aspect should be a function of your window width and height. Specifically width divided by height (but watch out for division by zero).

Perhaps you are using 1 as the aspect which is not accurate unless your window is a square.

like image 20
Martin Avatar answered Jan 29 '23 20:01

Martin