3d lines help

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
peeves91
Posts: 8
Joined: Wed Jul 24, 2013 2:39 pm

3d lines help

Post by peeves91 »

I'm really struggling with drawing a 3d line and looking at it with a camera. Here's my code so far:

Code: Select all

#include <irrlicht.h>
#include <iostream>
#include <cstdlib>
#include <conio.h>
#include <cmath>
 
using namespace std;
using namespace irr;
using namespace core;
using namespace video;
using namespace gui;
using namespace scene;
 
class MyEventReceiver : public IEventReceiver
{
public:
    // This is the one method that we have to implement
    virtual bool OnEvent(const SEvent& event)
    {
        // Remember whether each key is down or up
        if (event.EventType == irr::EET_KEY_INPUT_EVENT)
            KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
 
        // Remember the mouse state
        if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
        {
            switch(event.MouseInput.Event)
            {
            case EMIE_LMOUSE_PRESSED_DOWN:
                MouseState.LeftButtonDown = true;
                break;
 
            case EMIE_LMOUSE_LEFT_UP:
                MouseState.LeftButtonDown = false;
                break;
 
            case EMIE_MOUSE_MOVED:
                MouseState.Position.X = event.MouseInput.X;
                MouseState.Position.Y = event.MouseInput.Y;
                break;
 
            default:
                // We won't use the wheel
                break;
            }
        }
 
        return false;
    }
 
    // This is used to check whether a key is being held down
    virtual bool IsKeyDown(EKEY_CODE keyCode) const
    {
        return KeyIsDown[keyCode];
    }
    
    MyEventReceiver()
    {
        for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
            KeyIsDown[i] = false;
    }
 
    // We'll create a struct to record info on the mouse state
    struct SMouseState
    {
        core::position2di Position;
        bool LeftButtonDown;
        SMouseState() : LeftButtonDown(false) { }
    } MouseState;
 
    const SMouseState & GetMouseState(void) const
    {
        return MouseState;
    }
 
private:
    // We use this array to store the current state of each key
    bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
 
int main()
{
    MyEventReceiver receiver;
    IrrlichtDevice *device = createDevice(video::EDT_SOFTWARE, dimension2d<u32>(640, 480), 16, false, false, false, &receiver);
    IVideoDriver *driver = device->getVideoDriver();
    ISceneManager *smgr = device->getSceneManager();
    SMaterial material;
    material.Lighting = false;
    driver->setMaterial(material);
    driver->setTransform(video::ETS_WORLD, core::matrix4());
 
    vector3df position = vector3df(0, -40, 0);
    ICameraSceneNode *camera = smgr->addCameraSceneNode(0, position, vector3df(0, 0, 0));
 
    while (device->run())
    {
        driver->beginScene(true, true, SColor(255, 0, 0, 0));
 
        if (receiver.IsKeyDown(irr::KEY_KEY_A))
            position.X--;
        if (receiver.IsKeyDown(irr::KEY_KEY_D))
            position.X++;
        if (receiver.IsKeyDown(irr::KEY_KEY_W))
            position.Z--;
        if (receiver.IsKeyDown(irr::KEY_KEY_S))
            position.Z++;
        u16 index[] = {0, 1};
        camera->setPosition(position);
        printf("x: %f y: %f z: %f\n", position.X, position.Y, position.Z);
        driver->draw3DLine(vector3df(-100, 0, 0), vector3df(100, 0, 0), SColor(255, 255, 255, 255));
        smgr->drawAll();
        driver->endScene();
    }
}
 
When I can see the line, it's comprised of dots, and never is solid. Also, I believe I'm always looning at it, but can almost never see it. What am I doing wrong?
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: 3d lines help

Post by randomMesh »

You have to

Code: Select all

 
    driver->setMaterial(material);
    driver->setTransform(video::ETS_WORLD, core::matrix4());
 
every time you draw the line. Move the two lines just right before

Code: Select all

 
driver->draw3DLine(vector3df(-100, 0, 0), vector3df(100, 0, 0), SColor(255, 255, 255, 255));
 
"Whoops..."
Post Reply