Jump to content
  • Advertisement
Sign in to follow this  
fcoutel

Rubber-band zoom problem

This topic is 4043 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I am working on an app which displays some data as texture and wiggles in 2D. I would like to implement a rubber-band zoom. I managed the Drawing the rectangle and getting mouse position part without problem, my problem is to redraw my scene for the rectangle (zoomed part) selected. Here is my current reshape method :
    public void reshape(GLAutoDrawable drawable,int xstart,int ystart,int width,int height) {
        
        GL gl = drawable.getGL();
        height = (height == 0) ? 1 : height;
        
        gl.glViewport(0, 0, width, height);
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluOrtho2D(0.0, width, 0.0,height);
        // mover the origin from the bottom left corner
        // to the upper left corner
        gl.glScalef(1, -1, 1);
        gl.glTranslatef(0, -height, 0);
        
        // select modelview matrix and clear it out
        gl.glMatrixMode(gl.GL_MODELVIEW);
}

and here is the method that is called straight after the rectangle is drawn with the mouse
   public void zoomIn(GL gl, int xstart,int ystart,int width,int height) {
        int[] vp = new int[4];
        //Initialise projection mode,...
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        //...get viewport details,...
        gl.glGetIntegerv(GL.GL_VIEWPORT, vp,0);
        int[] zoomport = new int[4];
        zoomport[0] = xstart;
        zoomport[1] = ystart;
        zoomport[2] = width;
        zoomport[3] = height;
        //Then use pickmatrix to zoom in on this part of the scene...
        glu.gluPickMatrix(zoomport[0]+zoomport[2]/2, zoomport[1]+zoomport[3]/2, zoomport[2], zoomport[3], vp,0);
        glu.gluOrtho2D(xstart, width, ystart,height);
        
        // select modelview matrix and clear it out
        gl.glMatrixMode(gl.GL_MODELVIEW);
        this.repaint();
    }

xstart,ystart,width,height being the parameters representing the coordinates/extents rectangle itself The problem is that I dont get the right stuff displayed: a different region displays!! I read somewhere that using glyPickMatrix for zooming worked fine but it does not seem to be for me. I've tried using simply gluOrtho2D but in that case the result is a window of the size of my rectangle and black elsewhere. Can somebody pls tell me what I am doing wrong, or if I should be using a different method. Many thanks!

Share this post


Link to post
Share on other sites
Advertisement
The reason that some part of the screen is black is most likely the viewport change. A viewport defines the region in the window where to render so if you change the viewport to match your rectangle only the rectangle's region will be used for rendering.

I'd suggest you leave out that viewport change. Keep in mind that viewport and projection matrix don't need to have the same size.

Another problem could be this:

in your reshape function you call:

glu.gluOrtho2D(0.0, width, 0.0,height);
// mover the origin from the bottom left corner
// to the upper left corner
gl.glScalef(1, -1, 1);
gl.glTranslatef(0, -height, 0); //here you move the whole projection so it might get out of range

in your zoomIn function on the other hand you call:

glu.gluOrtho2D(xstart, width, ystart,height); //here you have the origin still at the bottom left corner which might produce inconsistencies

Share this post


Link to post
Share on other sites
The reason that some part of the screen is black is most likely the viewport change. A viewport defines the region in the window where to render so if you change the viewport to match your rectangle only the rectangle's region will be used for rendering.

I'd suggest you leave out that viewport change. Keep in mind that viewport and projection matrix don't need to have the same size.

Another problem could be this:

in your reshape function you call:

glu.gluOrtho2D(0.0, width, 0.0,height);
// mover the origin from the bottom left corner
// to the upper left corner
gl.glScalef(1, -1, 1);
gl.glTranslatef(0, -height, 0); //here you move the whole projection so it might get out of range

in your zoomIn function on the other hand you call:

glu.gluOrtho2D(xstart, width, ystart,height); //here you have the origin still at the bottom left corner which might produce inconsistencies

Share this post


Link to post
Share on other sites
Hi!

Thanks for your reply. By removing the viewport change you mean just calling glu.gluOrtho2D(0.0, width, 0.0,height);? If I do that then I get no zoom at all.
Also If I add the glScalef & gltranslate the result is all black :(

Any other suggestions?

Thanks

Share this post


Link to post
Share on other sites
Adding glScale and glTranslate could cause the scene to get "out of view" and thus the backround is shown.

To achieve a zoom just use gluOrtho2D(startX, startX + width, startY, startY - height ) without changing the initial viewport. This should suffice. Keep in mind that gluOrtho2D takes the parameters left, right, top and bottom not origin + dimensions.

Share this post


Link to post
Share on other sites
thanks for your suggestion Lord_evil: we are getting close but not quite there.

if in zoomin method I only put:

glu.gluOrtho2D(xstart, xstart + width, ystart,ystart -height);


// select modelview matrix and clear it out
gl.glMatrixMode(gl.GL_MODELVIEW);
this.repaint();



then nothing displays

2) if I replace the gluOrtho2D call with gluOrtho2D(xstart, xstart + width, ystart,ystart -height); then it does zoom in but not the area I expected (vertical shift I think)



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!