Quick and Easy Map Window for Terrain Scenemanager (4 lines)

Tubez

13-10-2005 23:06:51

I got this trick working the other day and I thought it was too neat to keep to myself. It's not special, or complex, but it can give your app that little extra je-ne-sais-quoi.

Sometimes you want to embed a little "map window" in your application that shows the player his whereabouts. This can be a map specially prepared for this use, or even a render-to-texture from above. However, if you are using the terrain manager you already have a map you can use: the terrain texture itself.

First we are goign to need a panel in an overlay to display it, and an associated material:


Pathman/MainOverlay
{
zorder 300

container Panel(Pathman/MapPanel)
{
metrics_mode pixels
horz_align right
vert_align top
top 15
left -165
width 150
height 150
material Pathman/Map
}
}

material Pathman/Map
{
technique
{
pass
{
lighting off
scene_blend alpha_blend
depth_check off

texture_unit
{
tex_address_mode clamp
texture pathlevelTexture.png
}
}
}
}


Then we want to center the texture map on the player camera and zoom in. You will find that PanelOverlayElement does not have functions to manipulate the texture cordinates directly, just tiling. So we need to get the material and modify scroll and scale:


element = ogre.OverlayManager.getSingleton().getOverlayElement('Pathman/MapPanel', False)
texstate = element.material.get().getTechnique(0).getPass(0).getTextureUnitState(0)
texstate.setTextureScroll((self.camera.position.x/500.0-0.5),(self.camera.position.z/500.0-0.5))
texstate.setTextureScale(2.0,2.0)



That is, assuming your terrain is 500.0 by 500.0 and you want to zoom in 2x.

If you allow the player to get close to the edge of the terrain, you may wish to make a two-pixel border black to prevent smearing when clamping.

This is the minimap in action in a prototype of my FPS pacman clone. For a more professional look you might want to use a borderpanel.
Everything written here can be done in regular Ogre too of course, but posting in the main forums would require me to look up the exact C++ syntax :D


Clay

19-10-2005 18:41:11

This is very cool by the way. =)

I love how pyogre is finally getting to the point where it doesn't require any fix to wrappings in order to do stuff like this. =)