Results 1 to 2 of 2

Thread: OpenGl - selection

  1. #1
    Member Newbie
    Join Date
    Mar 2011
    Posts
    48

    OpenGl - selection

    Hi guys trying to get picking to work basically just rendering a pyramid to test the picking and i'm getting hits = 0 each time.

    Any help would be greatly appreciated as i've never tried to do picking before and have just been reading the theroy so i could have something completely wrong.

    Thanks!

    Code :
    public int pickOBJ(double eyeX, double eyeY, double eyeZ, double cenX, double cenY, double cenZ, int x, int y)
            {
                Gl.glRenderMode(Gl.GL_SELECT); 
                Gl.glInitNames();  
                Gl.glPushName(0);
                int selectedId = -1;
                int[] selectBuffer = new int[512];
                int[] viewport = new int[4];
                Gl.glGetIntegerv(Gl.GL_VIEWPORT, viewport);
                Gl.glSelectBuffer(512, selectBuffer);
                Gl.glMatrixMode(Gl.GL_PROJECTION);
                Gl.glPushMatrix();
                Gl.glLoadIdentity();
     
                Glu.gluPickMatrix(x, y, 0.01f, 0.01f, viewport);
                Glu.gluLookAt(eyeX, eyeY, eyeZ, cenX, cenY, cenZ, 0, 1, 0);	
                Gl.glTranslatef(0, 0, 0);
                Gl.glMatrixMode(Gl.GL_MODELVIEW);
                DrawPri(0, 0, 0);
                Gl.glFlush();
                int hits = Gl.glRenderMode(Gl.GL_RENDER);
                uint closest = uint.MaxValue;
     
                for (int i = 0; i < hits; i++)
                {
                    uint distance = (uint)selectBuffer[i * 4 + 1];
     
                    if (closest >= distance)
                    {
                        closest = distance;
                        selectedId = (int)selectBuffer[i * 4 + 3];
                    }
                }
                return selectedId;
            }

  2. #2
    Member Newbie
    Join Date
    Mar 2011
    Posts
    48

    Re: OpenGl - selection

    I figured it out it had to do with how i was setting it up at the start.

Similar Threads

  1. OpenGL Lighting Selection
    By SecurityCop in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 11-04-2011, 03:38 PM
  2. selection the 3d objects OpenGL ES 1.1
    By pcersltda in forum OpenGL ES
    Replies: 1
    Last Post: 07-23-2010, 10:51 AM
  3. Help on OpenGL selection ???
    By jun wang in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 06-17-2010, 03:52 PM
  4. Selection / Picking in OpenGL 3.2
    By Kip Warner in forum OpenGL: Basic Coding
    Replies: 17
    Last Post: 12-15-2009, 04:37 AM
  5. Is using selection buffer for selection or picking slow?
    By mohsin in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 04-11-2001, 03:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean