Results 1 to 11 of 11

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

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

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

    I would like to be able to have 3D objects utilize the functionality of QT controls (buttons, sliders, etc.).

    I see two problems to overcome here:

    1) I need to tell QT whether or not an object has been moused over, because what QT thinks is an object's position and collision rect will not be correct and objects will cover other objects

    2) I need to render the object in 3D myself and not allow QT to render the object to the screen with its default code

    I was thinking of making my own classes inheriting from the abstract control classes and overriding the various functions that need to be overridden in order to achieve my goals. But, the thing is I do not know which function to override in terms of the mouseover. Which function in which class tells a control that its been moused over? Can this function be overridden? If not, can I somehow disable QT's mouseover information and put in my own some other way?

    Also: I am going to need to have functions called every frame, is there some common way to do this... aside from using a draw, paint, or render function as a place to put this code (because those functions are always called once per frame per object). I need a place for a basic game loop to be executed every frame and am unfamiliar with QTs control flow. It looks like everything gets hijacked by QT in app.exec().

    Thank you.

    Stephen

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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

    Did you have a look at QGLWidget and examples associated with it?

  3. #3
    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

    Yes, I have looked at that. I figured that I would use that widget as my screen.

    What I want to do is use the functionality of the QAbstractButton and other control classes. Are you suggesting that I use multiple inheritance in this case? Something like:

    class MyGLButton : public QGLWidget, public QAbstractButton
    {
    ...
    }

    ?? If I do so, won't I still have the problems with the mouse? I have seen no examples that make a GL button or anything similar enough to give me a direction. Will the button part know that the QGLWidget position and rect (I am assuming that's what QT tests against to determine mouseover) are the ones to use? I've seen cases where people just place QT buttons over the QGLWidget, but this is not what I want to do.

    In the case of QGLWidgets in front of QGLWidgets, a mouse click on top of one will probably shoot through and go to all the others. It looks to me like overriding functions in the controls classes is the best solution here, I just need to know which functions and if it's possible to override them.

    I guess what I am after is the easiest way to keep the functionality of the QT controls with minimal recoding. They've already got the wheel invented. I just need to find a way to make the controls work in 3D.

    I could also place the game loop code inside of the main window (QGLWidget that is the "screen") paint function, but I figure that maybe there is a better place for it that someone knows about.
    Last edited by smurrish; 25th April 2006 at 10:24.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.

  5. #5
    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.

  7. #7
    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.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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 

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

    smurrish (25th April 2006)

  10. #9
    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.

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.

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

    smurrish (26th April 2006)

  13. #11
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.