Second CGUIManager like CSceneManager

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
realmsinthemists
Posts: 28
Joined: Mon Mar 27, 2017 7:29 am

Second CGUIManager like CSceneManager

Post by realmsinthemists »

Goal: Creating multiple interactive textures for a user to manipulate within the scenery, i.e. an inworld GUI.
Application: Let the GUIEnvironment draw text, objects, images and whatever the GUI needs. Seperate code needed to handle 'events'.

How can one create a second CGUIEnvironment object like one can with a CSceneManager?

r,
For my end result I am working on:
- Volume Voxel System
- Simple light weight physics engine
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Second CGUIManager like CSceneManager

Post by CuteAlien »

You generally have 2 problems. Making sure to show/hide elements together. And handling events in different places. I tend to create a dialog class to handle that stuff. All elements used together are in that dialog. And that dialog then has some function to show/hide all elements. One way is that the dialog has an array with all it's childs and hides/shows all of them when dialog show/hide is called. Or another is that it has some parent element as background (might be invisible or an extra element like I described here: http://irrlicht.sourceforge.net/forum/v ... =1&t=31247) so I can simply hide/show that one. Each dialog used in your game then derives from that dialog-class.

For extra event-receivers - remember that you can call any function you want from your main event-receiver. Including an infinite number of other element-receivers. So for example a simply solution would be to give your dialog-class a event-receiver function and then call that from your main event-receiver. Maybe only for the visible dialogs. Or maybe you have only one active dialog and call it only for that one. Or dialogs can register/remove themself if they want to receive events.

One (slightly complicated) example can be seen in my racer game (https://bitbucket.org/mzeilfelder/trunk_hc1)
In src/gui.cpp/.h there is a function AddGuiEventFunctor. Functor is a special structure which can be used to call member-functions of other classes. All dialogs (base class src/gui_dialog.cpp/.h and lots of implementations in gui_dialogs sub-folder) use that one (with some nice wrapper in dialog-class) like: ADD_EVENT_HANDLER( "id_continue", GuiMenuChampionship, OnButtonContinue ); (that one said - handle button wid_continue by calling GuiMenuChampionship::OnButtonContinue).
And the event-reciver in gui.cpp thenn goes through all handler functors and calls the correct one. Could be further optimized (by only going through functors of active dialog for example - in this game I really check all of them for all gui-events).

I know other people did go even one step further and coded signal/slot mechanisms to handle events (like Qt has). I have no example for that yet unfortunately.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
realmsinthemists
Posts: 28
Joined: Mon Mar 27, 2017 7:29 am

Re: Second CGUIManager like CSceneManager

Post by realmsinthemists »

Think I was not clear.

The textures are meant to be used on a mesh were the user can interact on that so called screen.

The RTT Example will take care of the ever changing visuals. Just as the key input in the EventHandler for key input. Already have a register/unregister method for this in the main class.

Show/hide elements will do to, which will eliminate the need of a second Environment.

So basically my question is answered.

However I take this oppertunity to ask about how to handle mouse events, the screen will have buttons. Obviously mouse overs and clicks can't be detected 'as is'. There is a need for a ray to check for UV coords. But I am unable to find how to get the UV coord of a mesh that has been 'mouse downed'. The Collision Example only gives information of a triangle.

r,
For my end result I am working on:
- Volume Voxel System
- Simple light weight physics engine
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Second CGUIManager like CSceneManager

Post by CuteAlien »

Sorry, not sure I understand the mouse-question. You want uv-coordinates of the point which was clicked in a mesh?
Never did that and it's not trivial as the triangle-selectors don't have uv-information but only geometry.
You get the triangle. And I think you can also get the exact collision point. But I'm not certain how to get back to the exact vertices used for that triangle. You could search the vertex-list of the meshbuffer, but there can be more than one vertex on the same position (if an adjacent triangle has different uv's). Once you have those vertices you could interpolate the UV of the clicked point. Only idea I have right now for this is to write your own modified triangle-selector which keeps the complete S3DVertex information intact for each vertex of all triangles (or keeps the index to the original vertex-array).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Second CGUIManager like CSceneManager

Post by hendu »

Render the mesh to a RTT with a shader that draws UVs in the red and green channels. Fetch that pixel from that texture, and you have the UV.
Post Reply