sp

03-12-2003, 07:29 AM

I have been trying to mimick the behaviour of gluPickMatrix() in order to achieve the "zoom to box" effect (I've seen this method suggested a few times on opengl newsgroups).

By zoom to box, I mean that I select a rectangular area in the window and everything subsequently rendered inside that area fills the entire window.

gluPickMatrix() implementation is simple (in the sgi reference implementation):

// implicit: glMatrixMode(GL_PROJECTION)

/* Translate and scale the picked region to the entire window */

glTranslate( (xb + w/2 - x)/(dx/2), (yb + h/2 - y)/(dy/2), 0);

glScale( w/dx, h/dy, 1);

where:

(xb, yb) = lower left corner of viewport

(w, h) = width and height of viewport

(x, y) = center of new "box"

(dx, dy) = width and height of new box

Now here's my question:

I understand that the translation in x should be

(xb + w/2) - x

i.e., the difference between the center of the original viewport and new one * but why the division by dx/2 * ?

I want to understand what is happening fully because I want to be able to any number of subsequent "zoom to box"es and so I need to

accumulate the translation and scaling amounts correctly.

Alternately, can anyone suggest a better/different method to do zoom-to-box (multiple times)?

Thanks much for any help,

Sandeep

P.S. I cannot use gluPickMatrix() directly because in my code, I accumulate any necessary translation and scaling and modify the projection matrix using these values elsewhere.

By zoom to box, I mean that I select a rectangular area in the window and everything subsequently rendered inside that area fills the entire window.

gluPickMatrix() implementation is simple (in the sgi reference implementation):

// implicit: glMatrixMode(GL_PROJECTION)

/* Translate and scale the picked region to the entire window */

glTranslate( (xb + w/2 - x)/(dx/2), (yb + h/2 - y)/(dy/2), 0);

glScale( w/dx, h/dy, 1);

where:

(xb, yb) = lower left corner of viewport

(w, h) = width and height of viewport

(x, y) = center of new "box"

(dx, dy) = width and height of new box

Now here's my question:

I understand that the translation in x should be

(xb + w/2) - x

i.e., the difference between the center of the original viewport and new one * but why the division by dx/2 * ?

I want to understand what is happening fully because I want to be able to any number of subsequent "zoom to box"es and so I need to

accumulate the translation and scaling amounts correctly.

Alternately, can anyone suggest a better/different method to do zoom-to-box (multiple times)?

Thanks much for any help,

Sandeep

P.S. I cannot use gluPickMatrix() directly because in my code, I accumulate any necessary translation and scaling and modify the projection matrix using these values elsewhere.