Minimap !!

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
st0ph
Posts: 27
Joined: Sat Aug 04, 2012 3:00 pm

Minimap !!

Post by st0ph »

Hi !
I have been looking for a code snipet on how to make a minimap that displays the terrain and the position of the player on it, but all in vain
So if you have any idea or anything that could help me, I would be very grateful :roll:
netpipe
Posts: 669
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Re: Minimap !!

Post by netpipe »

i typed mipmap into the search and it came up with pages of stuff....
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Minimap !!

Post by greenya »

Here was asked about minimap not mipmap :)

st0ph,
obvious and most slow method would be create render target texture, add camera above the player, attach it to the player, make it look strait down and render every frame additional frame into that texture from that camera and display that texture as minimap.
dialNforNinja
Posts: 26
Joined: Wed Oct 10, 2012 1:28 am

Re: Minimap !!

Post by dialNforNinja »

While rendering the full scene twice per frame to get a minimap may be prohibitive, what about rendering a proxy scene? Slap your ground texture, or a prerendered image of all static geometry, or an image created with a single render-to-texture call when the map cell the player is in changes, onto a simple 2 poly square in a separate render space. Then use some kind of marker pips (single polygon acute triangles could work fine, showing direction as well) and move them according to the things tracked.
st0ph
Posts: 27
Joined: Sat Aug 04, 2012 3:00 pm

Re: Minimap !!

Post by st0ph »

Using the this example :http://irrlicht.sourceforge.net/docu/example013.html I created this class

Code: Select all

#pragma once
#include <iostream>
 
namespace irr
{
    class IrrlichtDevice;
    namespace scene
    {
        class ICameraSceneNode;
        class IAnimatedMeshSceneNode;
    
    }
    namespace video
    {
        class ITexture;
    }
}
class Minimap
{
public:
    Minimap(irr::IrrlichtDevice *device);
    ~Minimap(void);
    void setCamera(irr::scene::ICameraSceneNode* camera);
    void createMap();
    void displayMap();
 
 
 
private:
    irr::IrrlichtDevice* device;
    irr::video::ITexture* tMap;
    irr::scene::ICameraSceneNode* camera1;
    irr::scene::ICameraSceneNode* camera2;
    
};
 
 

and the implementation :

Code: Select all

 
#include "Minimap.h"
#include <IrrlichtDevice.h>
#include <ITexture.h>
#include <ISceneManager.h>
 
Minimap::Minimap(irr::IrrlichtDevice *device)
{
    this->device = device;
    camera1 = device->getSceneManager()->getActiveCamera();
 
    if (device->getVideoDriver()->queryFeature(irr::video::EVDF_RENDER_TO_TARGET))
    {
        tMap = device->getVideoDriver()->addRenderTargetTexture(irr::core::dimension2d<irr::u32>(200,200), "RTT1");
 
        // add fixed camera
        camera2 = device->getSceneManager()->addCameraSceneNode(0, irr::core::vector3df(10,10,-80),
            irr::core::vector3df(-10,10,-100));
 
        //device->getSceneManager()->setActiveCamera(camera1);
    }
    else
    {
    }
}
 
 
Minimap::~Minimap(void)
{
}
 
void Minimap::setCamera(irr::scene::ICameraSceneNode* camera)
{
    camera2 = camera;
}
void Minimap::createMap()
{
    // draw scene into render target
 
    // set render target texture
    device->getVideoDriver()->setRenderTarget(tMap);
 
    device->getSceneManager()->setActiveCamera(camera2);
 
    // draw whole scene into render buffer
    device->getSceneManager()->drawAll();
 
    // set back old render target
    // The buffer might have been distorted, so clear it
    device->getVideoDriver()->setRenderTarget(0, true, true, 0);
 
    device->getSceneManager()->setActiveCamera(camera1);
}
 
void Minimap::displayMap()
{
    device->getVideoDriver()->draw2DImage(tMap, irr::core::position2d<irr::s32>(50,50), //position to draw the minimap on screen
    irr::core::rect<irr::s32>(0,0,200,200), 0,
    irr::video::SColor(255,255,255,255), true);
}
but when I run the app, it renders very slowly :x why ?
zprg
Competition winner
Posts: 30
Joined: Tue Jul 31, 2012 12:29 pm
Location: Germany

Re: Minimap !!

Post by zprg »

have you seen my thread about minimap with Render to Texture?
http://irrlicht.sourceforge.net/forum/v ... =9&t=46759
st0ph
Posts: 27
Joined: Sat Aug 04, 2012 3:00 pm

Re: Minimap !!

Post by st0ph »

@zprg that exactly what I've used, but as I said it's realy slow :(
Post Reply