如何使用Jogl拾取对象? [英] How to pick objects using jogl?

查看:119
本文介绍了如何使用Jogl拾取对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一些关于慢跑采摘的问题.我需要选择每个点并对其进行处理,但是我总是得到0命中(什么都没选择).有人可以帮我吗?

I met some problems about jogl picking. I need to pick each single point and process it, but I always get 0 hit (nothing is picked). Can anyone help me with this?

display函数可以正确获取光标周围的2x2窗口.

the display function can correctly get the 2x2 window around the cursor.

public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    switch(cmd){
        case UPDATE:
            gl.glPushMatrix();
            gl.glMultMatrixf(rot_matrix, 0);
            buildPoints(gl);
            buildAxes(gl);
            gl.glPopMatrix();
            break;

        case SELECT:
            int buffsize = 512;
            double x = mouseX, y = mouseY;
            int[] viewPort = new int[4];
            IntBuffer selectBuffer = Buffers.newDirectIntBuffer(buffsize);
            int hits = 0;

            gl.glGetIntegerv(GL2.GL_VIEWPORT, viewPort, 0);
            gl.glSelectBuffer(buffsize, selectBuffer);
            gl.glRenderMode(GL2.GL_SELECT);

            gl.glMatrixMode(GL2.GL_PROJECTION);
            gl.glPushMatrix();
            gl.glLoadIdentity();

            glu.gluPickMatrix(x, (double) viewPort[3] - y, 2.0d, 2.0d, viewPort, 0);

            //draw graph
            gl.glPushMatrix();
            gl.glMultMatrixf(rot_matrix, 0);
            buildPoints(gl);
            buildAxes(gl);
            gl.glPopMatrix();

            gl.glMatrixMode(GL2.GL_PROJECTION);
            gl.glPopMatrix();
            gl.glMatrixMode(GL2.GL_MODELVIEW);
            gl.glFlush();

            hits = gl.glRenderMode(GL2.GL_RENDER);
            processHits(hits, selectBuffer);
            cmd = UPDATE;
            break;
    }
}

所以我想也许the drawing graph进行拣选的部分不正确.这是buildPoints函数的代码.

so I guess maybe the drawing graph part for picking is not correct. Here is the code of buildPoints function.

public void buildPoints(GL2 gl) {
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glPointSize((float) radius / 2);

    int pointName = 0;
    gl.glBegin(GL.GL_POINTS);
    for (point p : pointsList) {
        if(cmd == SELECT) gl.glLoadName(pointName);
        gl.glPushMatrix();
        gl.glTranslatef(p.getX(), p.getY(), p.getZ());
        gl.glColor3f(0.95f, 0.207f, 0.031f);
        gl.glVertex3f((float) (p.getX() * scaleFactor),
                (float) (p.getY() * scaleFactor),
                (float) (p.getZ() * scaleFactor));
        gl.glPopMatrix();
        pointName++;
    }
    gl.glEnd();
}

推荐答案

我建议您查看此主题中.

I advise you to look at this example of picking using JOGL 2. However, OpenGL build-in picking is deprecated and shouldn't be used. We discussed a lot about it on our official forum, especially in this thread.

这篇关于如何使用Jogl拾取对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆