Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Rubber-band zoom problem

fcoutelfcoutel Member Posts: 2
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 :
[code]
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);
}
[/code]

and here is the method that is called straight after the rectangle is drawn with the mouse :
[code]
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();
}
[/code]
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!
Sign In or Register to comment.