Billboards 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
azerty69
Posts: 11
Joined: Tue Jun 11, 2013 1:33 pm

Billboards position

Post by azerty69 »

Hello,

I'm encoutering a problem with position of billboards. They are not displayed at the correct position
that is defined randomly. Insteed, the points are displayed following a diagonal...
Can you tell me what I'm missing?

I initialize the arrays with the following code:

Code: Select all

 
//
//  Starfield
//
#define NBR_STARS               500
ITexture *image;
IBillboardSceneNode *star;
array<IBillboardSceneNode*>stars(NBR_STARS);
array<vector3df>starPos(NBR_STARS)
 
void initLevel()
{
    srand((unsigned int) time(NULL));
 
    for (int i = 0; i < NBR_STARS; ++i)
    {
        f32 n = -.5f + (f32(rand()) / RAND_MAX);
        starPos[i].X = n * 40.f;
        starPos[i].Y = n * 30.f;
        starPos[i].Z = -50.f + n * 25.f;
    }
 
    star = smgr->addBillboardSceneNode();
    image = driver->getTexture("data\\particle.png");
    star->setMaterialTexture(0, image);
    star->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
    star->setMaterialFlag(EMF_LIGHTING, false);
    star->setMaterialFlag(EMF_ZBUFFER, false);
 
    for (int i = 0; i < NBR_STARS; ++i)
    {
        stars[i] = (IBillboardSceneNode*) star->clone();
        stars[i]->setPosition(starPos[i]);
        stars[i]->updateAbsolutePosition();
    }
}
 
The main loop is:

Code: Select all

 
(...)
    //  Create Scene Manager.
    smgr = device->getSceneManager();
 
    //  Create main camera.
    camera = smgr->addCameraSceneNode(0, camPos, camDir);
 
    //  Initialize the level.
    initLevel();
 
    //  Main loop.
    while (device->run())
    {
        driver->beginScene();
            smgr->drawAll();
        driver->endScene();
 
        updateFPS();
    }
(...)
 
CuteAlien
Admin
Posts: 9647
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Billboards position

Post by CuteAlien »

Your x,y,z are not using independent random values but are always a multiple of n. So you get random points on a diagonal.
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
azerty69
Posts: 11
Joined: Tue Jun 11, 2013 1:33 pm

Re: Billboards position

Post by azerty69 »

Hi,

Thank you for your help. I've modified the code and it works perfectly.

Code: Select all

 
    srand((unsigned int) time(NULL));
 
    for (int i = 0; i < NBR_STARS; ++i)
    {
        f32 x = -.5f + f32(rand()) / RAND_MAX;
        starPos[i].X = x * 50.f;;
 
        f32 y = -.5f + f32(rand()) / RAND_MAX;
        starPos[i].Y = y * 50.f;
 
        f32 z = -.5f + f32(rand()) / RAND_MAX;
        starPos[i].Z = -50.f + z * 50.f;
    }
 
Post Reply