Results 1 to 11 of 11

Thread: Making 3D controls in QT, implementing a game loop in QT

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Making 3D controls in QT, implementing a game loop in QT

    No no no... no multiple inheritance here. If you want custom buttons, you should either subclass the buttons themselves or just create a new QStyle. It depends what you want to achieve.

  2. #2
    Join Date
    Apr 2006
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Making 3D controls in QT, implementing a game loop in QT

    What I want to do is have a 3D (OpenGL) object represented within a GL window that functions like a QPushbutton.

    You can mouse over the 3D object and click it and it functions just like a QPushbutton. Basically, buttons in 3D rather than in 2D.

    When you move the camera, move the object, rotate the object, etc. you can still click on it if it is still on screen and it will function appropriately.

    I figure that if I can somehow use the QT classes for controls, I can have 3D objects that function like those controls just by using the QT code with some overridden functions here and there.

    So, I need to know what functions to override, if that is possible.
    Last edited by smurrish; 25th April 2006 at 10:55.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Making 3D controls in QT, implementing a game loop in QT

    I would implement everything in a single QGLWidget here and emit signals to notify outside world about actions that are to be taken.

  4. #4
    Join Date
    Apr 2006
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Making 3D controls in QT, implementing a game loop in QT

    So, you're saying put all my objects inside

    class GLScreen : public QGLWidget
    {

    ... game objects...

    }

    and put the game loop code inside of the paint function I'll override in GLScreen's implementation?

    I suppose I could handle the 3D button thing by having two objects for the button. One could be a QGLWidget to show it and the other could be a QPushbutton with a transparent picture so it won't be seen. I could have the QGLWidget signal the button when it's moused over and clicked. However, the button itself will have a position somewhere and it may think its been clicked when the mouse is clicked in that location on the screen. I would have to somehow disable it from getting mouse messages while still receiving messages from its associated QGLWidget.

    I was hoping I could just use one object, however, by building my own button from QAbstractButton and just adding code to have it render an OpenGL textured mesh and use modified code to determine when it's been moused over and clicked.
    Last edited by smurrish; 25th April 2006 at 11:27.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Making 3D controls in QT, implementing a game loop in QT

    Quote Originally Posted by smurrish
    So, you're saying put all my objects inside
    Yes.

    and put the game loop code inside of the paint function I'll override in GLScreen's implementation?
    No. You have Qt event loop for that. paint function should just do painting.

    I suppose I could handle the 3D button thing by having two objects for the button. One could be a QGLWidget to show it and the other could be a QPushbutton with a transparent picture so it won't be seen. I could have the QGLWidget signal the button when it's moused over and clicked.
    What do you need the QPushButton for?


    Qt Code:
    1. class GLScreen : public QGLWidget {
    2. //...
    3. signals:
    4. void startClicked();
    5. void stopClicked();
    6. void someOtherButtonClicked();
    7. // ...
    8. };
    9. //...
    10. GLScreen *glscr = new GLScreen(...);
    11. //...
    12. connect(glscr, SIGNAL(startClicked()), this, SLOT(startWasClickedSlot()));
    13. //...
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to wysota for this useful post:

    smurrish (25th April 2006)

  7. #6
    Join Date
    Apr 2006
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Making 3D controls in QT, implementing a game loop in QT

    Well, I could do it that way, with individual functions in that one class all scanning for clicks in various areas and against various objects.

    I just thought it would be nice for each object to figure out when it has been clicked itself and have code for handling each case in the implementation of the code for the class of that object. Also, I might want a slider for music and effects volume, and figured it would be nice to be able to use the code already implemented for that... just with a few changes to it to handle the 3D situation.

    The QPushButton has all the nice stuff for being pressed, been released, only setting clicked when the mouse button was pushed and released and code for being checked or not. I would like to be able to use all that.

    If I can get one of the controls classes to work, then getting all the rest to work would be very easy. Sliders, buttons, radio buttons, edit boxes, you name it. It'd be just so much better if I could make implementations of the abstract classes so each work in 3D.

    I prefer having the modularity that comes with each individual class being able to handle its own domain of responsibilities, rather than having one big honking giant class having its tentacles digging into and manipulating everything.

    I will look into the QEventloop class. Thank you for that.
    Last edited by smurrish; 25th April 2006 at 12:33.

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Making 3D controls in QT, implementing a game loop in QT

    Quote Originally Posted by smurrish
    Well, I could do it that way, with individual functions in that one class all scanning for clicks in various areas and against various objects.
    What do you mean by scanning for clicks? You just have to emit proper signals from within mousePressEvent of the GLWidget where you'll be checking for collisions of the mouse with various objects.

    I just thought it would be nice for each object to figure out when it has been clicked itself and have code for handling each case in the implementation of the code for the class of that object.
    What if the object has to operate on some data which is external to it? For example different buttons that turn the music on and off. You can't "embed" the music in both of them -- it has to be in an outside object, so it's better to emit a signal and handle the event in the music "handler" object.

    Also, I might want a slider for music and effects volume, and figured it would be nice to be able to use the code already implemented for that... just with a few changes to it to handle the 3D situation.
    You'll have to handle checking the value of the slider yourself anyway, so all that is left to do is to emit a signal with the slider value. You won't be able to reuse much of the code of Qt slider classes.

    The QPushButton has all the nice stuff for being pressed, been released, only setting clicked when the mouse button was pushed and released and code for being checked or not. I would like to be able to use all that.
    But you'll have to check all that yourself anyway. And then you just need to emit proper signals.

    If I can get one of the controls classes to work, then getting all the rest to work would be very easy. Sliders, buttons, radio buttons, edit boxes, you name it. It'd be just so much better if I could make implementations of the abstract classes so each work in 3D.
    The point is that they are implemented in 2D and are very dependent on that. Most of their functionality involves checking the coordinates and handling events. And you won't be able to reuse any of those. The overhead will be much greater than the gain.

    I prefer having the modularity that comes with each individual class being able to handle its own domain of responsibilities, rather than having one big honking giant class having its tentacles digging into and manipulating everything.
    You can implement your own set of "3D widgets" inside the "big honking giant" QGLWidget class, just like it's done with QWidget and widgets or QCanvas and canvas items.

  9. The following user says thank you to wysota for this useful post:

    smurrish (26th April 2006)

  10. #8
    Join Date
    Apr 2006
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Making 3D controls in QT, implementing a game loop in QT

    Alright. I get you.

    It'll feel more natural to me, I think, when I get used to programming Qt-style.

    I appreciate your patience and time. Thank you.

Similar Threads

  1. QT debug confusion
    By swistak in forum Installation and Deployment
    Replies: 2
    Last Post: 24th September 2008, 19:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.