Page 1 of 1

draw3DLine bug ???

Posted: Fri Apr 20, 2007 12:07 am
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...

Posted: Fri Apr 20, 2007 12:32 am
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();

Posted: Fri Apr 20, 2007 12:37 am
by danut007ro
nope, I'm not using anything (yet)... everything is static

Posted: Fri Apr 20, 2007 1:05 am
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));

Posted: Fri Apr 20, 2007 3:01 am
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); 

Posted: Fri Apr 20, 2007 8:58 am
by danut007ro
thank you... it is ok now. it was SMaterial, but no problem seeing that