[英]How to pick objects using jogl?
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).
我需要选择每个点并对其进行处理,但是我总是得到0命中(什么都没选择)。 Can anyone help me with this?
谁能帮我这个?
the display
function can correctly get the 2x2 window around the cursor. display
功能可以正确获取光标周围的2x2窗口。
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;
}
}
so I guess maybe the drawing graph
part for picking is not correct. 所以我猜可能用于拾取的
the drawing graph
部分不正确。 Here is the code of buildPoints
function. 这是
buildPoints
函数的代码。
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 . 我建议您看一下使用JOGL 2进行拣货的示例 。 However, OpenGL build-in picking is deprecated and shouldn't be used.
但是,不建议使用OpenGL内置选择。 We discussed a lot about it on our official forum, especially in this thread .
我们在官方论坛上对此进行了很多讨论,尤其是在本主题中 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.