draw3DLine bug or Why this code has an invalid behaviour?

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
Magnet
Posts: 101
Joined: Wed Sep 27, 2006 7:32 pm

draw3DLine bug or Why this code has an invalid behaviour?

Post by Magnet »

I write this code:

If I comment one line of code this code is correct, but if I uncomment code line lines draws incorrect!

Code: Select all

int main()
{
	IrrlichtDevice* device =
		createDevice( video::EDT_DIRECT3D9, dimension2d<s32>(640, 480), 32,
		false, true, false, 0);
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	smgr->addCameraSceneNodeFPS();

        //[b]THIS LINE[/b]
	//[b]smgr->addCubeSceneNode()->setPosition(vector3df(0,200,200));[/b]

	vector3df vec1(0,0,0);
	vector3df vec2(0,100,0);
	vector3df vec3(0,0,100);
	smgr->addCubeSceneNode()->setPosition(vec1);
	smgr->addCubeSceneNode()->setPosition(vec2);
	smgr->addCubeSceneNode()->setPosition(vec3);
	while(device->run())
	{
		driver->beginScene(true, true, SColor(255,100,101,140));

		driver->draw3DLine(vec1, vec2, SColor(255,0,255,0));
		driver->draw3DLine(vec2, vec3, SColor(255,0,255,0));

		smgr->drawAll();

		driver->endScene();
	}
	device->drop();
	return 0;
}
Screen with line uncommented:
Image

Screen with line commented:
Image
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Because you need to set the world transform before you render your lines.

Code: Select all

      driver->setTransform(video::ETS_WORLD, core::matrix4());
      driver->draw3DLine(vec1, vec2, SColor(255,0,255,0)); 
      driver->draw3DLine(vec2, vec3, SColor(255,0,255,0)); 
Post Reply