[no bug] Draw3DLine don't draw at given positions

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
radical-dev
Posts: 45
Joined: Thu Apr 24, 2008 7:54 pm
Location: Wickede, Germany

[no bug] Draw3DLine don't draw at given positions

Post by radical-dev »

Hi all!

I don't know if this is a bug or if i just misunderstood the function. So here's my test code:

Code: Select all

#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

IrrlichtDevice* device;
IVideoDriver* driver;
ISceneManager* smgr;
IGUIEnvironment* guienv;
ISceneNode* node;

class MyEventReceiver:public IEventReceiver
{
    public:
    MyEventReceiver() { LastNode = 0; }

    virtual bool    OnEvent(const SEvent& event)
    {
        switch(event.EventType)
        {
            case EET_KEY_INPUT_EVENT:
            {
                switch(event.KeyInput.Key)
                {
                    case KEY_ESCAPE:
                    {
                        device->closeDevice();
                        return true;
                    }
                }
            }

            case EET_MOUSE_INPUT_EVENT:
            {
                case EMIE_MOUSE_MOVED:
                {
                    s32 xPos, yPos;
                    ISceneNode* TestNode;

                    xPos = event.MouseInput.X;
                    yPos = event.MouseInput.Y;
                    TestNode = smgr->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(position2d<s32>(xPos, yPos));

                    if( TestNode != 0 && LastNode == 0 )
                    {
                        LastNode = TestNode;
                        LastNode->setScale(vector3df(1.1f,1.1f,1.1f));
                        switch (LastNode->getID())
                        {
                            case 100:
                            {
                                smgr->getSceneNodeFromId(101)->setVisible(true);
                            }
                            break;
                            case 102:
                            {
                                smgr->getSceneNodeFromId(103)->setVisible(true);
                            }
                            break;
                            case 104:
                            {
                                smgr->getSceneNodeFromId(105)->setVisible(true);
                            }
                            break;
                        }
                    }
                    else if( TestNode != 0 && LastNode != 0 )
                    {
                        LastNode->setScale(vector3df(1.0f,1.0f,1.0f));
                        switch (LastNode->getID())
                        {
                            case 100:
                            {
                                smgr->getSceneNodeFromId(101)->setVisible(false);
                            }
                            break;
                            case 102:
                            {
                                smgr->getSceneNodeFromId(103)->setVisible(false);
                            }
                            break;

                            case 104:
                            {
                                smgr->getSceneNodeFromId(105)->setVisible(false);
                            }
                            break;
                        }
                        LastNode = TestNode;
                        LastNode->setScale(vector3df(1.1f,1.1f,1.1f));
                         switch (LastNode->getID())
                        {
                            case 100:
                            {
                                smgr->getSceneNodeFromId(101)->setVisible(true);
                            }
                            break;
                            case 102:
                            {
                                smgr->getSceneNodeFromId(103)->setVisible(true);
                            }
                            break;
                            case 104:
                            {
                                smgr->getSceneNodeFromId(105)->setVisible(true);
                            }
                            break;
                        }
                   }
                    return true;
                }
            }
        }

        return false;
    }

    private:
    ISceneNode*     LastNode;
};

int main(int argc, char** argv)
{
    MyEventReceiver receiver;

    device = createDevice(EDT_OPENGL, dimension2d<s32>(640, 480), 32, false, false, false, &receiver);
    device->setWindowCaption(L"Irrlicht Engine Test");

    driver = device->getVideoDriver();
    smgr = device->getSceneManager();
    guienv = device->getGUIEnvironment();

    node = smgr->addSphereSceneNode(1.0f, 64, 0, 100, vector3df(0,5,0));
    smgr->addTextSceneNode(guienv->getBuiltInFont(), L"Planet 1", SColor(255,255,255,255), node, vector3df(1.5f,1.5f,0.0f), 101);
    node->setMaterialFlag(EMF_LIGHTING, false);
    node = smgr->addSphereSceneNode(1.0f, 64, 0, 102, vector3df(5,0,0));
    smgr->addTextSceneNode(guienv->getBuiltInFont(), L"Planet 2", SColor(255,255,255,255), node, vector3df(1.5f,1.5f,0.0f), 103);
    node->setMaterialFlag(EMF_LIGHTING, false);
    node = smgr->addSphereSceneNode(1.0f, 64, 0, 104, vector3df(-5,-5,0));
    smgr->addTextSceneNode(guienv->getBuiltInFont(), L"Planet 3", SColor(255,255,255,255), node, vector3df(1.5f,1.5f,0.0f), 105);
    node->setMaterialFlag(EMF_LIGHTING, false);

    smgr->getSceneNodeFromId(101)->setVisible(false);
    smgr->getSceneNodeFromId(103)->setVisible(false);
    smgr->getSceneNodeFromId(105)->setVisible(false);

    smgr->addCameraSceneNode(0, vector3df(0,0,-25), vector3df(0,0,0));

    device->getCursorControl()->setVisible(true);

    while(device->run())
    {
        driver->beginScene(true, true, SColor(0,0,0,0));

        smgr->drawAll();
        guienv->drawAll();
        driver->draw3DLine(vector3df(0,5,0), vector3df(5,0,0), SColor(255,255,255,0));

        driver->endScene();
    }

    device->drop();

    return 0;
}
Short explanation: I add 3 Spherenodes at (0,5,0)/(5,0,0)/(-5,-5,0) and attach 3 Textnodes as child at (1.5,1.5,1.5). So long so good.

But within the Renderfunction i tried to draw a 2dline from Sphere 1 (0,5,0) to Sphere 2 (5,0,0). The result looks like this:

OpenGL: the line draws away from the desired location and "jumps" if i go over one sphere (if one sphere is hit by mouse it scales to 1.1f and shows the Textnode).

Direct3D: same as OpenGL beside the location, but if i hit one sphere the line completely disappears

Depends this on my code? I don't know.

greetings

radical

EDIT: Compiled with Code::Blocks @ XP and MSVC at Win7 RC - API v1.5.1
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

This isn't a bug, though maybe the docs could be more clear. You have to call setTransform and setMaterial before using the driver's draw3d functions.
See the custom scene node tutorial for an example.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Don't know how much clearer one can get
Note that the line is drawn using the current transformation
matrix and material. So if you need to draw the 3D line
independently of the current transformation, use
\code
driver->setMaterial(unlitMaterial);
driver->setTransform(video::ETS_WORLD, core::matrix4());
\endcode
for some properly set up material before drawing the line.
radical-dev
Posts: 45
Joined: Thu Apr 24, 2008 7:54 pm
Location: Wickede, Germany

Post by radical-dev »

Uiuiui...shame on me :oops:

Basics of 3D-maths...going back to the books ;-)

Sorry
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Shame on me too, I didn't check either :oops:
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Post Reply