Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT OpenGL object selection
Forum Updated to NodeBB v4.3 + New Features

QT OpenGL object selection

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 2 Posters 2.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BPrasad
    wrote on last edited by
    #1

    Hi,

    I am currently working on Graphics Application which uses QT OpenGL (QOpenGLWidget class) . Actually I have implemented object selection by converting to world coordinates and finding that coordinates within the bounding box. Object is getting selected. Problem is when I click inside the rectangle object, the rectangle object is getting selected. But I want object gets selected only if i click on its edges not inside the rectangle box. How to go about this problem in QT OpenGL ? Please suggest me .

    Thanks in advance

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Since you already have the code to find whether the mouse is within the geometry of the object, why not use that information and test the edges of that rectangle.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • B Offline
        B Offline
        BPrasad
        wrote on last edited by
        #3

        Hi,

        Thanks SGaist. How to find the edges? can I get some code sample in QT OpenGL?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          How are you doing it currently ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          B 1 Reply Last reply
          0
          • SGaistS SGaist

            How are you doing it currently ?

            B Offline
            B Offline
            BPrasad
            wrote on last edited by
            #5

            @SGaist

            I am using the below code to find the World Coordinates

            QVector3D cameraPos = QVector3D(0.0f, 2.0f, 4.0f);
            QVector3D cameraFront = QVector3D(0.0f, 0.0f, 0.0f);
            QVector3D cameraUp = QVector3D(0.0f, 1.0f, 0.0f);

            	QMatrix4x4 viewMatrix;
            	viewMatrix.setToIdentity();
            	viewMatrix.lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
            
            	QMatrix4x4 projection;
            	projection.setToIdentity();
            	projection.perspective(45.0f, 1.0f * _scrWidth / _scrHeight, 0.1f, 100.0f);
            	qDebug() << _scrWidth << _scrHeight;
            
                    float posZ;
                    float posY = _scrHeight - pickBox.pnt1().y - 1.0f;
                        		
               	glReadPixels((int)pickBox.pnt1().x, (int)posY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &posZ);
                        
                        		qDebug() << 2.0f * posZ - 1.0f;
                       QVector4D clickedPointOnScreen(pickBox.pnt1().x, posY, 0.961635, 1.0f);
                     	qDebug() << clickedPointOnScreen;
            

            worldPosition = QVector3D(pickBox.pnt1().x, _scrHeight- pickBox.pnt1().y,posZ).unproject(viewMatrix, projection, QRect(0, 0, _scrWidth,_scrHeight));

            qDebug() << worldPosition.x() << worldPosition.y();

            From this World Position I am finding out the object.

            Can u suggest me how to go about finding the edge of an object?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Sorry I thought you where using Qt3D which may have better tools to do that.

              Can you describe how you are handling your objects ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              B 1 Reply Last reply
              0
              • SGaistS SGaist

                Sorry I thought you where using Qt3D which may have better tools to do that.

                Can you describe how you are handling your objects ?

                B Offline
                B Offline
                BPrasad
                wrote on last edited by
                #7

                Sorry for the delay. We are in the process of Migrating the Old OpenGL to Modern OpenGL. The Old openGL code is below. How to replace this selection api glRenderMode(GL_SELECT) in QT OpenGL. Is there any api ? Because the old OpenGL API was giving me the number of hits on the object selected. Based on that we were deciding weather object is getting selected or not. Any idea How to replace this api in QT?

                             glSelectBuffer(_maxBuff, _pickBufferP);
                	**(void) glRenderMode(GL_SELECT);**
                	glInitNames();
                	glPushName(0)
                	glMatrixMode(GL_PROJECTION);
                	glPushMatrix();
                	glLoadIdentity();
                	glOrtho(box.left(), box.right(), box.bottom(), box.top(),
                		-10000, 10000);
                	
                	glMatrixMode(GL_MODELVIEW);
                	glPushMatrix();
                	glLoadIdentity();
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  What is wrong with using this method now ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    BPrasad
                    wrote on last edited by
                    #9

                    Because glRenderMode(GL_SELECT) method is deprecated. It is not working in OpenGL 4.2. So I am looking is there any similar method in OpenGL QT?

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      The Qt OpenGL module does not re-invent the wheel. It makes using OpenGL easier and cross-platform.

                      Depending on what you are doing, you might want to check Qt3D.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved