## glOrtho, gluOrtho2D, and glRotate

### glOrtho, gluOrtho2D, and glRotate

I am using the redbook in an effort to gain better understanding of
glRotate and its effect with different Orthographic projections.

Given this poly, Ortho, and glRotate, I am able to rotate the object
as expected (counterclockwise).

Note that the center of the poly and center of the Ortho are (0,0).

void Draw_A_Rectangle()
{

glVertex2f(-25, 25);
glVertex2f(25, 25);
glVertex2f(25, -25);
glVertex2f(-25, -25);

glEnd();

Quote:}

void display()
{   ...
glRotatef(spin, 0.0, 0.0, 1.0);
....

Quote:}

void reshape(int w, int h)
{   ...
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0;
...

Quote:}

BUT, what if I want to rotate an object whose center is not origin of
the Orthographic Projection?  What would be the correct glRotate
command (assuming there is one) to create the same visual as above
with the following placement and projection?

For example:

void Draw_A_Rectangle()
{

glVertex2f(0.25, 0.25);
glVertex2f(0.25, 0.75);
glVertex2f(0.75, 0.75);
glVertex2f(0.75, 0.25);

glEnd();

Quote:}

void display()
{   ...
glRotatef(spin, 0.0, 0.0, 1.0);
....

Quote:}

void reshape(int w, int h)
{    ...
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
....

Quote:}

Note: I have also tried:
glRotatef(spin, 0.5, 0.5, 1.0);
and still it seems that the entire plane is rotating around (0,0).

Thank you in advance for any help with this.
Charles

### glOrtho, gluOrtho2D, and glRotate

Normally what you would do is maintain the object's coordinate system so
that it has the origin at it's centre. Then you can rotate the object to
whatever orientation you desire, before you translate it to the world
coordinates where you want to see it.

The red book gives some very intuitive examples on how to view the
combination of rotation and translation so it's worth persevering without
getting too stuck into early examples. Note that you will get a different
effect if you translate then rotate than you will by rotating then
translating.

Quote:> I am using the redbook in an effort to gain better understanding of
> glRotate and its effect with different Orthographic projections.

> Given this poly, Ortho, and glRotate, I am able to rotate the object
> as expected (counterclockwise).

> Note that the center of the poly and center of the Ortho are (0,0).

> void Draw_A_Rectangle()
> {

>     glVertex2f(-25, 25);
>     glVertex2f(25, 25);
>     glVertex2f(25, -25);
>     glVertex2f(-25, -25);

>     glEnd();
> }

> void display()
> {   ...
>     glRotatef(spin, 0.0, 0.0, 1.0);
>     ....
> }

> void reshape(int w, int h)
> {   ...
>     glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0;
>     ...
> }

> BUT, what if I want to rotate an object whose center is not origin of
> the Orthographic Projection?  What would be the correct glRotate
> command (assuming there is one) to create the same visual as above
> with the following placement and projection?

> For example:

> void Draw_A_Rectangle()
> {

>     glVertex2f(0.25, 0.25);
>     glVertex2f(0.25, 0.75);
>     glVertex2f(0.75, 0.75);
>     glVertex2f(0.75, 0.25);

>     glEnd();
> }

> void display()
> {   ...
>     glRotatef(spin, 0.0, 0.0, 1.0);
>     ....
> }

> void reshape(int w, int h)
> {    ...
>     glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
>     ....
> }

> Note: I have also tried:
>     glRotatef(spin, 0.5, 0.5, 1.0);
> and still it seems that the entire plane is rotating around (0,0).

> Thank you in advance for any help with this.
> Charles

Now that I'm using glOrtho, glRotate no longer works as I expect it to.

The following code snippet allows me to feed in scroll, zoom, and rotation
values, and the line on the screen performs exactly as I expect it to:

::glMatrixMode(GL_PROJECTION);
::gluPerspective( 80.0f, m_AspectRatio, zNear, zFar );
...
::glMatrixMode(GL_MODELVIEW);
glTranslated( theScroll->hScrollFactor, theScroll->vScrollFactor,
theZoom->zoomFactor);
::glRotatef( DEGREES, 0.0f, 0.0f, 1.0f );

Now I've added glOrtho, and the scroll and zoom still works fine. Rotation
also works fine with left/right and bottom/top in the -2.0 to 2.0 range.
When I set left/right and bottom/top in the 800 to 8000 range, any DEGREES
value other than zero causes the line on the screen disappear.

::glMatrixMode(GL_PROJECTION);
::gluPerspective( 80.0f, m_AspectRatio, zNear, zFar );
...
::glMatrixMode(GL_MODELVIEW);
::glOrtho(left, right, bottom, top, zNear, zFar);    //This is the added
line that causing my line to disappear with DEGREES != zero
glTranslated( theScroll->hScrollFactor, theScroll->vScrollFactor,
theZoom->zoomFactor);
::glRotatef( DEGREES, 0.0f, 0.0f, 1.0f );

I've tried a large range of values for the last parameter in glRotatef(). I
just can't seem to keep my line on the screen with a DEGREES value other
than zero.

Any ideas?

Thanks,
Randy Bone

10. gluOrtho2d

12. glRotate