Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to zoom in on an arbitrary rect within a screen-aligned quad

I've got a screen-aligned quad, and I'd like to zoom into an arbitrary rectangle within that quad, but I'm not getting my math right.

I think I've got the translate worked out, just not the scaling. Basically, my code is the following:

//
// render once zoomed in
glPushMatrix();
glTranslatef(offX, offY, 0);
glScalef(?wtf?, ?wtf?, 1.0f);

RenderQuad();

glPopMatrix();

//
// render PIP display
glPushMatrix();
glTranslatef(0.7f, 0.7f, 0);
glScalef(0.175f, 0.175f, 1.0f);

RenderQuad();

glPopMatrix();

Anyone have any tips? The user selects a rect area, and then those values are passed to my rendering object as [x, y, w, h], where those values are percentages of the viewport's width and height.

like image 403
moswald Avatar asked Nov 15 '22 10:11

moswald


1 Answers

Given that your values are passed as [x, y, w, h] I think you want to first translate in the negative direction to get the upper left hand corner at 0,0, then scale by 1/w and 1/h to fill it to the screen. Like this:

//
// render once zoomed in
glPushMatrix();
glTranslatef(-x, -y, 0);
glScalef(1.0/w, 1.0/h, 1.0f);

RenderQuad();

glPopMatrix();

Does this work?

like image 110
Rich Avatar answered Nov 17 '22 00:11

Rich