New Text Position

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
WhyMe
Posts: 10
Joined: Sat Jan 26, 2013 5:31 pm

New Text Position

Post by WhyMe »

Hello, I tried to move text in 2d scene mode, but it don't want change it own position.
Also I have a qustion - to show only text, for my code, I used ITextSceneNode - it is good idea ?

Code:

Code: Select all

 
#include <irrlicht.h>
#include <ctime>
#include <cstdlib>
 
using namespace irr;
 
#define WIDTH_DIMENSION 512
#define HEIGHT_DIMENSION 384
#define WIDTH_MARGIN 5
#define HEIGHT_MARGIN 5
 
int main()
{
    irr::core::stringw str [] =
    {
        L"a", L"b", L"c", L"d", L"e", L"f", L"g", L"h", L"i",
        L"j", L"k", L"l", L"1", L"2", L"3", L"4", L"5", L"6",
        L"A", L"B", L"C", L"D", L"E", L"F", L"G", L"H", L"I",
        L"m", L"n", L"o", L"p", L"r", L"s", L"t", L"u", L"w",
        L"7", L"8", L"9", L"!", L"@", L"#", L"$", L"&", L"J",
        L"K", L"L", L"M", L"N", L"O", L"P", L"R", L"S", L"T",
        L"x", L"y", L"z", L"U", L"W", L"X", L"Y", L"Z"
    }; //62
 
    std::srand(std::time(NULL));
 
    IrrlichtDevice *device = createDevice(video::EDT_DIRECT3D9,
        core::dimension2d<u32>(WIDTH_DIMENSION, HEIGHT_DIMENSION), 32, false, true, true);
 
    if (device == 0)
        return 1; // could not create selected driver.
 
    device->setWindowCaption(L"Irrlicht Engine - Matrix Banner");
 
    video::IVideoDriver* driver = device->getVideoDriver();
 
    scene::ISceneManager *smgr = device->getSceneManager();
 
    irr::scene::ICameraSceneNode *cam = smgr->addCameraSceneNode(0, core::vector3df(0,0,0), core::vector3df(0,0,0), 1000);
 
    gui::IGUIFont* font = device->getGUIEnvironment()->getBuiltInFont();
 
    bool width_end;
    bool height_end = false;
    f32 width = 0;
    f32 height = 0;
 
    /*while (height_end == false)
    {
        width_end = false;
        width = 0;
        while(width_end == false)
        {
            smgr->addTextSceneNode(font, str[(rand()%62)].c_str() ,
                    video::SColor(255,255,255,255), 0, irr::core::vector3df(width, height, 0));
            width += WIDTH_MARGIN;
            if(width > WIDTH_DIMENSION) width_end = true;
        }
 
        height += HEIGHT_MARGIN;
        if(height > HEIGHT_DIMENSION) height_end = true;
    }*/
 
    irr::scene::ITextSceneNode *sc = smgr->addTextSceneNode(font, str[(rand()%62)].c_str() ,
            video::SColor(255,255,255,255), 0, irr::core::vector3df(0, 0, 0));
 
    while(device->run() && driver)
    {
        if (device->isWindowActive())
         {
            driver->beginScene(true, true, video::SColor(255,0,0,0));
 
            // try to move camera
            irr::core::vector3df v = cam->getPosition();
            ++v.X;
            ++v.Y;
            cam->setPosition(v);
 
            //try to move ITextSceneNode
            v = sc->getPosition();
            ++v.X;
            ++v.Y;
            sc->setPosition(v);
 
            //find and move ITextSceneNode
            smgr->getSceneNodeFromId(1000)->setPosition(irr::core::vector3df(++width, ++height, 0));
 
            smgr->drawAll();
 
            driver->endScene();
        }
    }
 
    device->drop();
 
    return 0;
}
 
I would be pleased for any advices.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: New Text Position

Post by CuteAlien »

I don't know right now _why_ it looks like it doesn't move, but the bug is that the camera position and camera target are identical. Set for example:

Code: Select all

 
irr::scene::ICameraSceneNode *cam = smgr->addCameraSceneNode(0, core::vector3df(-100,0,0), core::vector3df(0,0,0), 1000);
 
Then you see that the node moves.
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
WhyMe
Posts: 10
Joined: Sat Jan 26, 2013 5:31 pm

Re: New Text Position

Post by WhyMe »

Ow You have right.
I needed to change cam coordinates, and now, camera and sc pointer is moving.
Even the change position of sc pointer when creating isn't affect for the moving.
I think, I need to understand better 3D system.

Thank You.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: New Text Position

Post by CuteAlien »

As camera is looking from x right now the change in x is just getting it closer/further to the camera, so the change is harder to see. Offset the camera to z instead then the x change of the text should be more visible.
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
Post Reply