Results 1 to 2 of 2

Thread: How can I detect a surface on 3Dobject by mouse click?

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2002
    Posts
    2

    How can I detect a surface on 3Dobject by mouse click?

    I rendered a 3D object using OpenGL, e.g, a cube.
    Is there any method to detect which surface on the cube I choose by mouse click?
    thanks a lot...

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: How can I detect a surface on 3Dobject by mouse click?

    Hi !

    You use selection mode, something like this:
    glSelectBuffer( ...);
    glRenderMode( GL_SELECT);
    glInitNames();
    glPushName( 0);

    Then you render then scene again and before you render each face of the cube you use glLoadName( n); when n is a unique identifier, used to identify that surface.

    You then switch back with:
    glRenderMode( GL_RENDER);

    And get the result which is a list of id values of things that where hit.

    This is very oversimplified, you must also set the picking matrix and a few other things before it will work.

    You can find more info in the FAQ on this website, for examples on selection you can have a peek at the demo examples included with Mesa or GLUT.

    Mikael

Similar Threads

  1. Mouse Click to 3d
    By uniQQQ in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-28-2016, 06:23 AM
  2. Detect when mouse moves up and down
    By JORGEMAL in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-16-2015, 11:31 AM
  3. rotate on mouse click and drag in the direction of the mouse cursor
    By vamsee kanth in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-02-2005, 09:54 PM
  4. How I can detect each object my mouse click.
    By amstel in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-28-2002, 09:19 AM
  5. How can I detect a surface on 3D object by mouse click?
    By yin in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 01-24-2002, 07:21 PM

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