Before anything, I'll need to let you guys know that I DID research this topic. Found few links, none of which were useful (That I could find).
So, I know how to display 2D images (From the tutorial), but this DOESN'T include moving them around while you've got a 3D camera going on.
I tried making a second camera, then displaying smaller and in the top-left of the screen. But it had many problems and I eventually gave it, trying to use 2D images.
I've displayed the map texture on screen, giving a map sort of look. But I also made a 2D image of the player's head. I'm trying to move the 2D head to the location of the player (On the minimap). But I can't seem to figure out how to move the 2D image without using 3D Coordinants (3D makes me input a Z axis, and I'd have to be looking at a specific X and Y to even see it).
So, How would I go about displaying a 2D movable object on-screen using 2D cords and not 3D? (Note: position2d<s32> gives me errors, even tried results found online to no avail).
C++ Minimap
Re: C++ Minimap
I didn't understand most of what you wrote. But I understand you want to put a minimap on the screen which is probably about showing the player position on the map? It depends a lot on what you exactly need as there are (as usual) several different approaches.
IGUIImage is probably the one you tried first. In Irrlicht 1.8 you had only one choice when using that: A texture showing your complete map which is completely displayed. And then a second image on top of it for the player which could be moved around with setRelativePosition. If you also needed to show player direction you would have to use several images (one for each direction) and show the corresponding one. Not a super-solution - but the easiest one and works already sufficient for some games.
When you use Irrlicht svn trunk (the version which will become Irrlicht 1.9 some day) then you have an additional option with IGUIImage. It allows now to change the source-rectangle. Which means - you could have a larger map than the one you show and scroll around in it.
If that is not sufficient you will have to start working with primitives. You create a quad-mesh (aka 2 triangles) which is then rendered at the place of your minimap (check out stuff from people doing multi-stage rendering, for example XEffects, I think they need similar quads and might have the code for that). That quad will have a material with ZWriteEnable set to false, so when you render it last (after scene and gui rendering) it well be on top of everything else. Then you put a texture on that mesh. Now you can draw anything you want into that texture. For a minimap you could for example render the whole scene from a top-view camera into a render-target texture and then use that as texture for the minimap. But it's getting complicated by now, so maybe forget about that. Better use a previously drawn map of your scene. You can modify the texture-matrix of that texture - which allows to scale move and rotate your map.
For the player position you can do the exact same - you use another quad and draw it after the map (so it's on top of it). And then again you can use it with rotation,movement and so on. Or you use any kind of flat mesh and just draw that last (with ZWriteEnable set to false) then you might not need 2D textures at all.
I hope it helps.
IGUIImage is probably the one you tried first. In Irrlicht 1.8 you had only one choice when using that: A texture showing your complete map which is completely displayed. And then a second image on top of it for the player which could be moved around with setRelativePosition. If you also needed to show player direction you would have to use several images (one for each direction) and show the corresponding one. Not a super-solution - but the easiest one and works already sufficient for some games.
When you use Irrlicht svn trunk (the version which will become Irrlicht 1.9 some day) then you have an additional option with IGUIImage. It allows now to change the source-rectangle. Which means - you could have a larger map than the one you show and scroll around in it.
If that is not sufficient you will have to start working with primitives. You create a quad-mesh (aka 2 triangles) which is then rendered at the place of your minimap (check out stuff from people doing multi-stage rendering, for example XEffects, I think they need similar quads and might have the code for that). That quad will have a material with ZWriteEnable set to false, so when you render it last (after scene and gui rendering) it well be on top of everything else. Then you put a texture on that mesh. Now you can draw anything you want into that texture. For a minimap you could for example render the whole scene from a top-view camera into a render-target texture and then use that as texture for the minimap. But it's getting complicated by now, so maybe forget about that. Better use a previously drawn map of your scene. You can modify the texture-matrix of that texture - which allows to scale move and rotate your map.
For the player position you can do the exact same - you use another quad and draw it after the map (so it's on top of it). And then again you can use it with rotation,movement and so on. Or you use any kind of flat mesh and just draw that last (with ZWriteEnable set to false) then you might not need 2D textures at all.
I hope it helps.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 386
- Joined: Sun May 11, 2014 12:13 am
Re: C++ Minimap
I made a picture representation.
http://imgur.com/U2YTGnR
I'm trying to do what the Irrlicht Tutorial 6 is doing, but the image doesn't show up anywhere on the screen.
http://imgur.com/U2YTGnR
I'm trying to do what the Irrlicht Tutorial 6 is doing, but the image doesn't show up anywhere on the screen.
Re: C++ Minimap
You move the red dot with setRelativePosition (every IGUIElement has that function). Be careful that you create the images only once (so usually before your mainloop). And the order matters - the last gui-element added is drawn on top of that added before. Or add red-dot image as a child of the minimap image to ensure it's always on top of that.
If that doesn't work I would need to see your code to figure out what's going wrong.
If that doesn't work I would need to see your code to figure out what's going wrong.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 386
- Joined: Sun May 11, 2014 12:13 am
Re: C++ Minimap
How do I use IGUIElement? I'm looking at the Class List for it, but don't see anything about adding images.
Could you possibly give an example?
Could you possibly give an example?
Re: C++ Minimap
Ah, I thought example 06 would use that :-) I see - that draws directly - that is certainly also a solution. In that case you have to make sure you draw it after your 3D scene was rendered. And reset the driver transformation and maybe use driver->enableMaterial2D() (or set another material which disables light and ZWriteEnable). Stuff you draw later that way will be drawn on top of stuff that is drawn earlier.
For using IGUIImage check example 04 which uses that to draw the logo on top of the 3D scene.
For using IGUIImage check example 04 which uses that to draw the logo on top of the 3D scene.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 386
- Joined: Sun May 11, 2014 12:13 am
Re: C++ Minimap
Ohh okay sweet. I figured it used the same as Tutorial 06.
However, How do I trigger it in a loop to change position?
I tried doing the same.. But can't figure it out in the main loop.
I don't see any way I can change the 2d position of the image.
However, How do I trigger it in a loop to change position?
I tried doing the same.. But can't figure it out in the main loop.
Code: Select all
device->getGUIEnvironment()->addImage(
driver->getTexture("../../media/irrlichtlogoalpha2.tga"),
core::position2d<s32>(10,20));
Re: C++ Minimap
addImage returns an IGUIImage* which you can put in a variable and then modify with setRelativePosition.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm