2d zoom

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
2ant
Posts: 8
Joined: Mon Jul 14, 2014 7:06 pm

2d zoom

Post by 2ant »

Hello everyone,
i'm trying to display only part of something and i want it to fit the entire windows/screen.I also want to be able to move what i see, like a 2d strategy game camera.

Here is my code:

Code: Select all

#include <IRR/irrlicht.h>
 
using namespace irr;
 
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
stringw text(L"Irrlicht - cursor position = ");
 
int main(void)
{
    IrrlichtDevice *device = createDevice (EDT_OPENGL,dimension2d<irr::u32>(1280,720),32,false,true,true,0);
        IVideoDriver* driver = device->getVideoDriver ();
        ISceneManager *sceneManager = device->getSceneManager ();
 
        ITexture* images = driver->getTexture("test2.png");
        ITexture* images1 = driver->getTexture("archer2.png");
        ITexture* images3 = driver->getTexture("archer3.png");
        ITexture* images2 = driver->getTexture("64.png");
        driver->makeColorKeyTexture(images1, core::position2d<s32>(0,0));
        driver->makeColorKeyTexture(images3, core::position2d<s32>(0,0));
 
        IGUIEnvironment *gui = device->getGUIEnvironment();
 
 
    while (device->run ())
        {
 
            stringw text(L"Irrlicht - cursor position = ");
            text += device->getCursorControl ()-> getPosition().X;
            text += L" ";
            text += device->getCursorControl ()-> getPosition().Y;
 
            driver->beginScene(true, true,SColor(255,128,225,255));
 
            driver->draw2DImage(images,position2d<s32>(0,0),
                rect<s32>(0,0,640,320), 0,
                SColor(255,255,255,255), true);
 
            driver->draw2DImage(images1,position2d<s32>(224,96),
                rect<s32>(0,0,64,64), 0,
                SColor(255,255,255,255), true);
 
            driver->draw2DImage(images2,position2d<s32>(64,32),
                rect<s32>(0,0,64,64), 0,
                SColor(255,255,255,255), true);
 
            driver->draw2DImage(images3,position2d<s32>(288,96),
                rect<s32>(0,0,64,64), 0,
                SColor(255,255,255,255), true);
 
 
            device->setWindowCaption(text.c_str());
            sceneManager->drawAll();
            gui->drawAll();
            driver->endScene();
        }
           device->drop ();
    return 0;
}
 
1st image:what i have
2nd image: what i want to display
3rd image: what i would like to have as a result

Image

If someone can point me in the right direction that would be great. Also if someone know an easier library than irrlicht to do a 2d tactics game i'm interested.
Please forgive any spelling mistake i could have done , this is my 2nd language.
danielmccarthy
Posts: 51
Joined: Fri May 30, 2014 12:55 am

Re: 2d zoom

Post by danielmccarthy »

Maybe use billboards then you can just reposition the 3d camera.

Another way would be to resize the textures some how based on the zoom level. You would need quite large images then though as if they are originally small they will reduce in quality as they are stretched.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: 2d zoom

Post by CuteAlien »

Billboards probably wouldn't work as he wants to look from some angle on it (billboards are always perpendicular to the camera). But putting those textures on any kind of plane should work. For a start you could create a plane mesh in blender and then put your texture on that. Thought you will likely want a more advanced solution to be able to change the tiles. Using one large plane with vertices at each corner of each tile would allow you to work with one large texture for your tile-graphics and swap tiles by chaning uv-coordinates. Be careful you need then 4 vertices for each corner as each tile needs it's own uv's. Or you could create one meshbuffer per tile (give each tile a different material in your modeling tool) - that makes changing the tiles easier as you can then set any texture for each tile. I would probably code a custom scenenode for such a game to allow for dynamic width/height. Otherwise you have to create different planes in your modeling tool each time when you want to change the level-size.

If the above makes no sense please ask again - I don't know how much experience you already have with graphics programming so I only described it rather hi-level.
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
2ant
Posts: 8
Joined: Mon Jul 14, 2014 7:06 pm

Re: 2d zoom

Post by 2ant »

I realise that i didn't describe my problem properly.I want to make a 2d tactical rpg (final fantasy tactics advance,tactics ogre,...).
As i am a beginner with c++ i wanted to start simple : a 2d image as a map/background,2d sprites for characters and a camera who follow the action.
I turn to irrlicht because i already did some little 3d stuff with it, but i wanted to do it strictly 2d.

ff tactics on psx is 3d with some 2d(chara and ui)
Image

Tactics ogre is entirely 2d and i like the general look of it more.
Image

I found a solution while searching for a more 2d oriented library :SFML.

I looked a the offical tutorials and i found exactly what i needed :

2d rendering on a texture-> see off screen drawing
http://sfml-dev.org/tutorials/2.1/graphics-draw.php

2d camera control with view
http://sfml-dev.org/tutorials/2.1/graphics-view.php

It is perfect for what i need to do.

Cute alien: i understand what you said and it is going to be useful to me later .

The map is made with "tiled map editor". It's a free and easy tile map editor with lot of functions.
http://www.mapeditor.org/

I'm still interested if someone know a way to do what i mentioned in the 2 links above with irrlicht.
Please forgive any spelling mistake i could have done , this is my 2nd language.
Post Reply