[SOLVED] Drawing a colored line between two 3d 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.
Post Reply
pandoragami
Posts: 226
Joined: Wed Jan 26, 2011 5:37 pm
Contact:

[SOLVED] Drawing a colored line between two 3d points?

Post by pandoragami »

In the following code I draw a line between two points in 3 dimensions and I wanted to draw a green line. Any suggestions?

EDIT I tried this line with changing the scolor but that made no difference...

Code: Select all

driver->draw3DLine(core::vector3df(x1, y1, z1), core::vector3df(x2, y2, z2), video::SColor(255,255,255,255));

Code: Select all

 
#include <irrlicht.h>
#include "driverChoice.h"
 
using namespace irr;
 
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
 
int main()
{
    // ask user for driver
    video::E_DRIVER_TYPE driverType=driverChoiceConsole();
    if (driverType==video::EDT_COUNT)
        return 1;
 
    // create device
 
    IrrlichtDevice *device = createDevice(driverType,
            core::dimension2d<u32>(640, 480), 16, false);
 
    if (device == 0)
        return 1; // could not create selected driver.
 
    // create engine and camera
 
    device->setWindowCaption(L"Custom Scene Node - Irrlicht Engine Demo");
 
    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* smgr = device->getSceneManager();
 
    smgr->addCameraSceneNode(0, core::vector3df(0,-40,0), core::vector3df(0,0,0));
 
    int x1, y1, z1, x2, y2, z2;
 
    x1 = 0;
    x2 = 1;
    y1 = 0;
    y2 = 1;
    z1 = 0;
    z2 = 1;
 
    while(device->run())
    {
        driver->beginScene(true, true, video::SColor(0,100,100,100));
        driver->draw3DLine(core::vector3df(x1, y1, z1), core::vector3df(x2, y2, z2));
        smgr->drawAll();
 
        driver->endScene();
    }
 
    device->drop();
 
    return 0;
}
 
Last edited by pandoragami on Mon Sep 09, 2013 8:58 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9716
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Drawing a colored line between two 3d points?

Post by CuteAlien »

Color should be fine, but check the documentation - you have to set the transformation and the material first when working directly with the driver functions.
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
pandoragami
Posts: 226
Joined: Wed Jan 26, 2011 5:37 pm
Contact:

Re: Drawing a colored line between two 3d points?

Post by pandoragami »

CuteAlien wrote:Color should be fine, but check the documentation - you have to set the transformation and the material first when working directly with the driver functions.
I ended up creating an

Code: Select all

irr::video::SMaterial line_material; 
right before the 'gameloop' and then I used this.

Code: Select all

driver->beginScene(true, true, video::SColor(0,0,0,0));
    line_material.BackfaceCulling = false;
        line_material.Wireframe = true;
        line_material.Lighting = false;
        driver->setMaterial(line_material);
        driver->draw3DLine(core::vector3df(x1, y1, z1), core::vector3df(x2, y2, z2), video::SColor(255,0,255,0));
    smgr->drawAll();
 
    driver->endScene();

thanks, works fine!
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: [SOLVED] Drawing a colored line between two 3d points?

Post by Seven »

no need to set the material properties each frame. Set them once, then use the material each frame. The material will remember the settings.

Code: Select all

 
// somewhere else before first call to render()
        material line_material;
        line_material.BackfaceCulling = false;
        line_material.Wireframe = true;
        line_material.Lighting = false;
 
void render()
{
        driver->beginScene(true, true, video::SColor(0,0,0,0));
        driver->setMaterial(line_material);
        driver->draw3DLine(core::vector3df(x1, y1, z1), core::vector3df(x2, y2, z2), video::SColor(255,0,255,0));
        smgr->drawAll();
        driver->endScene();
}
 
Post Reply