| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 
 |  
public void mouseWheelMoved(MouseWheelEvent arg0) {
        if(arg0.getWheelRotation()==1)
            zoom*=2;
        else
            zoom*=0.5f;
        this.mw.refresh();
    }
 
public void reshape(GLAutoDrawable arg0, int x, int y, int w, int h) {
        this.gl = arg0.getGL();
        GLU glu = new GLU();
        gl.glViewport(0, 0, w, h);
        gl.glMatrixMode(gl.GL_PROJECTION);
        gl.glLoadIdentity();
        System.out.println("reshape zoom="+this.zoom);
        gl.glOrtho(-5f*zoom, 5f*zoom, -5f*zoom, 5f*zoom, -5f*zoom, 5f*zoom);
        glu.gluPerspective(30, this.height/this.width, -5f, 5f);
        gl.glMatrixMode(gl.GL_MODELVIEW);
        gl.glLoadIdentity();
    }
 
private void pickPoint(GL gl) {
        GLU glu = new GLU();
        int selectBuf[] = new int[BUFSIZE];
        IntBuffer selectBuffer = BufferUtil.newIntBuffer(BUFSIZE);
        int hits;
        int viewport[] = new int[4];
 
        gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
 
        gl.glSelectBuffer(BUFSIZE, selectBuffer);
        gl.glRenderMode(GL.GL_SELECT);
 
        gl.glInitNames();
        gl.glPushName(0);
 
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glPushMatrix();
        gl.glLoadIdentity();
        glu.gluPickMatrix((double) this.point.x,
                (double) (viewport[3] - this.point.y),//
                5.0, 5.0, viewport, 0);
        System.out.println("pickPoint zoom="+this.zoom);
        gl.glOrtho(-5f*zoom, 5f*zoom, -5f*zoom, 5f*zoom, -5f*zoom, 5f*zoom);
        drawWorld(gl, GL.GL_SELECT);
 
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glPopMatrix();
        gl.glFlush();
 
        hits = gl.glRenderMode(GL.GL_RENDER);
        selectBuffer.get(selectBuf);
        processHits(hits, selectBuf);
    }
 
    private void processHits(int hits, int buffer[]) {
        int names, ptr = 0;
        if (hits > 0) {
            names = buffer[ptr] - 1;
            selected = names;
        } else {
            selected = -1;
        }
    } | 
Partager