animated image on billboard

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
Howker
Posts: 51
Joined: Thu Jan 22, 2009 4:40 pm

animated image on billboard

Post by Howker »

Hello!
I know how to make a billboard with a material and a texture. But how do I put an animated image on that billboard?
It's not an animated gif. It looks like this:
Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: animated image on billboard

Post by hybrid »

You have to use a texture animator to somehow move the tex coords. Easiest is to define a texture matrix animator, which moves the actual subtexture window along the full texture. I think we don't have such an animator in the engine, yet, but it should be fairly easy to implement. Should also work on a billboard. One more note: It might be worth adding some more spacing to the texture to blow it up to 512x512 pixel. This avoids problems with several gfx cards that don't properly support npot textures.
Howker
Posts: 51
Joined: Thu Jan 22, 2009 4:40 pm

Re: animated image on billboard

Post by Howker »

Anyone else good ideas?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: animated image on billboard

Post by hendu »

You can do it in a shader instead, if you prefer.
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: animated image on billboard

Post by smso »

You may animate the image by changing the texture coordinates by hybrid or hendu's method. Below is some hacky code to show how this is done:

Code: Select all

int main()
{
    //...
    billboard->setMaterialTexture(0, driver->getTexture("sample_animation_5x5.jpg"));
 
    core::vector2df translate(0.0f);    
    std::vector<core::vector2df> ts;
    for (f32 m=0.0f; m<5.0f; m+=1.0f)
    {
        for (f32 n=0.0f; n<5.0f; n+=1.0f)
        {
            //printf("(m,n)=(%f,%f)\n", m, n);
            translate = core::vector2df(n, m) * 0.2f;
            ts.push_back(translate);
        }
    }
 
    while (device->run())
    if (device->isWindowActive())
    {
        ////////////////////////////////////////////////////////////////////////
        static int texindex = 0;
        core::vector2df translate = ts[texindex];
        core::matrix4 mat;
        mat.buildTextureTransform(0.0f, core::vector2df(0.0f), translate, core::vector2df(0.2f));
        billboard->getMaterial(0).setTextureMatrix(0, mat);
  
       ++texindex;
        if (texindex > int(ts.size()-1))
            texindex = 0;
        ////////////////////////////////////////////////////////////////////////
        driver->beginScene(true, true, 0);
        smgr->drawAll();
        driver->endScene();
    }
    else { device->yield(); }
 
    if (device)
        device->drop();
    return 0;
}

Regards
smso
Post Reply