draw3DLine bug ???

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
danut007ro
Posts: 16
Joined: Thu Apr 12, 2007 2:21 pm

draw3DLine bug ???

Post by danut007ro »

hello !

I'm developing a little physics simulation but I have some problems with draw3DLine() function.

I attached these two screenshots. In the first one, the image is ok, some spheres have lines between them... But in the second one, (the camera looks slighty up) the lines between the spheres are gone, but another lines appear at another location...
OK image :
Image
WRONG image :
Image

The code to draw those lines looks like this :

Code: Select all

        driver->draw2DLine(position2d<s32>(0, 0), position2d<s32>(100, 100), SColor(0, 255, 255, 255));
        for (int i = 0; i < 6 - 1; i++)
            for (int j = 0; j < 6; j++)
                for (int k = 0; k < 6; k++)
                    driver->draw3DLine(part[i][j][k]->getPosition(), part[i+1][j][k]->getPosition(), SColor(0, 255, 255, 255));
        for (int i = 0; i < 6; i++)
            for (int j = 0; j < 6 - 1; j++)
                for (int k = 0; k < 6; k++)
                    driver->draw3DLine(part[i][j][k]->getPosition(), part[i][j+1][k]->getPosition(), SColor(0, 255, 255, 255));
        for (int i = 0; i < 6; i++)
            for (int j = 0; j < 6; j++)
                for (int k = 0; k < 6 - 1; k++)
                    driver->draw3DLine(part[i][j][k]->getPosition(), part[i][j][k+1]->getPosition(), SColor(0, 255, 255, 255));
It is called in the while loop between smgr->drawAll() and guienv->drawAll().
As you can see there is an extra draw2DLine() before calling the draw3DLine() functions. That draw2DLine() doesn't appear on screen at all, but it I don't do it, the lines won't appear at all, but they will appear in the wrong state (2nd screenshot).

I'm using Codeblocks with mingw, downloaded the dll for 1.3 from somewhere from forum...

I can post the demo too if someone is interested...

Thanks...
zeno60
Posts: 342
Joined: Sun May 21, 2006 2:48 am
Location: NC, USA
Contact:

Post by zeno60 »

Are you using Newton for physics?

Seems to me like a transformation state problem, try setting the world transform before you draw the line.

I'm not at home otherwise i'd double check the code.

Code: Select all

matrix4 mat;
driver->setTransform(ETS_WORLD,mat);
driver->draw3dline();
Last edited by zeno60 on Fri Apr 20, 2007 12:41 am, edited 4 times in total.
danut007ro
Posts: 16
Joined: Thu Apr 12, 2007 2:21 pm

Post by danut007ro »

nope, I'm not using anything (yet)... everything is static
danut007ro
Posts: 16
Joined: Thu Apr 12, 2007 2:21 pm

Post by danut007ro »

just tested it and it happens with the default version of Irrlicht. tested with msvc 8.0.

I attached the demo, too... just press the first button, then move to the end of the big cube, get on the last cells from top and look up... you should see the effect...

ftp://216.75.41.174/program.zip

EDIT : with the code above is the same thing, just that the black lines are drawn over the white ones... in the demo, the first button is for drawing with draw2DLine() before drawing the 3D ones, and the second button is for drawing directly with draw3DLine()... you'll see what I mean.

The code now looks like this :

Code: Select all

        matrix4 mat;
        driver->setTransform(ETS_WORLD,mat);
        driver->draw2DLine(position2d<s32>(0, 0), position2d<s32>(100, 100), SColor(0, 255, 255, 255));
        for (int i = 0; i < 6 - 1; i++)
            for (int j = 0; j < 6; j++)
                for (int k = 0; k < 6; k++)
                    driver->draw3DLine(part[i][j][k]->getPosition(), part[i+1][j][k]->getPosition(), SColor(0, 255, 255, 255));
        for (int i = 0; i < 6; i++)
            for (int j = 0; j < 6 - 1; j++)
                for (int k = 0; k < 6; k++)
                    driver->draw3DLine(part[i][j][k]->getPosition(), part[i][j+1][k]->getPosition(), SColor(0, 255, 255, 255));
        for (int i = 0; i < 6; i++)
            for (int j = 0; j < 6; j++)
                for (int k = 0; k < 6 - 1; k++)
                    driver->draw3DLine(part[i][j][k]->getPosition(), part[i][j][k+1]->getPosition(), SColor(0, 255, 255, 255));
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You should really set the material before you go drawing stuff. You should also be passing 255 as the alpha value to the SColor constructor.

Code: Select all

core::matrix4 mat;
driver->setTransform(video::ETS_WORLD, mat);

video::SColor mtl;
mtl.Lighting = false;
driver->setMaterial(mtl);

video::SColor color(255, 255, 255, 255);

driver->draw2DLine(position2d<s32>(0, 0), position2d<s32>(100, 100), color); 
for (int i = 0; i < 6 - 1; i++) 
  for (int j = 0; j < 6; j++) 
    for (int k = 0; k < 6; k++) 
      driver->draw3DLine(part[i][j][k]->getPosition(), part[i+1][j][k]->getPosition(), color); 
for (int i = 0; i < 6; i++) 
  for (int j = 0; j < 6 - 1; j++) 
    for (int k = 0; k < 6; k++) 
      driver->draw3DLine(part[i][j][k]->getPosition(), part[i][j+1][k]->getPosition(), color); 
for (int i = 0; i < 6; i++) 
  for (int j = 0; j < 6; j++) 
    for (int k = 0; k < 6 - 1; k++) 
      driver->draw3DLine(part[i][j][k]->getPosition(), part[i][j][k+1]->getPosition(), color); 
danut007ro
Posts: 16
Joined: Thu Apr 12, 2007 2:21 pm

Post by danut007ro »

thank you... it is ok now. it was SMaterial, but no problem seeing that
Post Reply