draw line between 2 points

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.

draw line between 2 points

Postby asi » Fri Feb 03, 2012 12:33 pm

Could you please tell me how to draw very simple picture.
I have coordinates of two 3d points.
I just want to draw line between that points?
Could you please tell me which functions I should use.
asi
 
Posts: 4
Joined: Fri Feb 03, 2012 5:41 am

Re: draw line between 2 points

Postby CuteAlien » Fri Feb 03, 2012 1:07 pm

You can use IVideoDriver::draw3DLine: http://irrlicht.sourceforge.net/docu/cl ... 3a4eebb5e6
Note that you have to do this inside your render-loop and so you have to first reset the worldtransformation and set a material.
For example:
cpp Code: Select all
 
irr::core::line3df line; // put your values in here
irr::video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setTransform(irr::video::ETS_WORLD, irr::core::IdentityMatrix);
irr::video::SMaterial material;
material.Lighting = false;
material.BackfaceCulling = false;      
material.ZBuffer = irr::video::ECFN_ALWAYS;
driver->setMaterial(material);
driver->draw3DLine( line.start, line.end, irr::video::SColor(255, 200, 50, 50) );
 
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5358
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: draw line between 2 points

Postby asi » Fri Feb 03, 2012 2:04 pm

Many thanks for your answer.
That code should be modified a little because there is few compile error arising.

Could you please check this code. Is it ok? Why I don't see line? Just scene with gray background can be seen.

cpp Code: Select all
irr::IrrlichtDevice *device = irr::createDevice(irr::video::EDT_OPENGL, irr::core::dimension2d< u32 >(640,480) ,16, false);
    irr::video::IVideoDriver* driver = device->getVideoDriver();
    irr::scene::ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();
 
    irr::core::line3df line(10, 50, 10, 300, 100, 400); // put your values in here
 
    irr::video::SMaterial material;
    material.Lighting = false;
    material.BackfaceCulling = false;
    material.ZBuffer = irr::video::ECFN_ALWAYS;
    driver->setMaterial(material);
 
    device->setWindowCaption(L"test");
    while(device->run())
    {
        driver->setTransform(irr::video::ETS_WORLD, irr::core::IdentityMatrix);
        driver->beginScene(true,true, video::SColor(255,200,200,200));
        driver->draw3DLine( line.start, line.end, irr::video::SColor(255, 20, 20, 100) );
        smgr->drawAll();
        guienv->drawAll();
        driver->endScene();
    }
 
   device->drop();
asi
 
Posts: 4
Joined: Fri Feb 03, 2012 5:41 am

Re: draw line between 2 points

Postby CuteAlien » Fri Feb 03, 2012 2:14 pm

The lines to set the transform and material have to be in front of the draw3DLine - otherwise any other materials or transformations in the scene will mess it up.
And you need a camera or you can't see anything.

Incidentally I just posted some code a few days ago using draw3DLine + Camera: viewtopic.php?f=7&t=45732
Just ignore all the code about test (if you comment out testGetIntersectionWithLine you probably can kick all functions except main) and look at the main function there (also note I use the matrix4 constructor there instead of identity - but it's identical as the matrix is initialized with the identity matrix).
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5358
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany


Return to Beginners Help

Who is online

Users browsing this forum: Mauin and 1 guest