[SOLVED] Quad vanishes as the camera moves towards it?

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.
pandoragami
Posts: 226
Joined: Wed Jan 26, 2011 5:37 pm
Contact:

Re: Quad vanishes as the camera moves towards it?

Post by pandoragami »

Thanks Alien

Here's the final version that works!

Code: Select all

 
#include <irrlicht.h>
#include <iostream>
 
using namespace irr;
 
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;
 
        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;
    }
 
private:
    // We use this array to store the current state of each key
    bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
 
MyEventReceiver receiver;
 
int main()
{
    IrrlichtDevice* device = 0;
    device = createDevice( video::EDT_OPENGL, core::dimension2d<u32>(640, 480), 16, false, false, false, &receiver);
 
    if (device == 0)
        return 1;
 
    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* smgr = device->getSceneManager();
    driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
 
    scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS( 0, 50.0f, 0.01f, -1, 0, 0, false, 0.0f, false, true);
    cam->setPosition(core::vector3df( 9, 12, 27));
    cam->setTarget(core::vector3df( 9, 11,5));
    device->getCursorControl()->setVisible(false);
 
    scene::SMesh *mesh = new scene::SMesh();
    scene::SMeshBuffer * meshbuf = new scene::SMeshBuffer();
 
    video::S3DVertex a(0,20, -50, 1,1,0, video::SColor(255,0,255,255), 0, 1);
    video::S3DVertex b(0,0, -50, 1,0,0, video::SColor(255,255,0,255), 1, 1);
    video::S3DVertex c(20,0,-50, 0,1,1, video::SColor(255,255,255,0), 1, 0);
    video::S3DVertex d(20,20, -50, 0,0,1, video::SColor(255,0,255,0), 0, 0);
 
    video::S3DVertex ver2[] = {a,b,c,d};
    u16 indices[] = {0, 1, 2, 2, 3, 0};
    mesh->addMeshBuffer(meshbuf);
    meshbuf->append((const void*)&ver2, 4, (u16*)&indices, 6);
    meshbuf->drop();
    mesh->recalculateBoundingBox();
 
    scene::IMeshSceneNode* Node = smgr->addMeshSceneNode(mesh);
    Node->setMaterialFlag(video::EMF_LIGHTING, false);
 
    int lastFPS = -1;
 
    while(device->run())
    {
        driver->beginScene(true, true, video::SColor(255,0,0,0));
        smgr->drawAll();
        driver->endScene();
        int fps = driver->getFPS();
 
        if (lastFPS != fps)
        {
            core::stringw str = L"[";
            str += " FPS:  ";
            str += fps;
            str += "]";
 
            device->setWindowCaption(str.c_str());
            lastFPS = fps;
        }
 
        device->sleep(50);
    }
 
    device->drop();
 
    return 0;
}
 
 
 
 
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [SOLVED] Quad vanishes as the camera moves towards it?

Post by CuteAlien »

Do also add the meshbuf->recalculateBoundingBox() after append and before drop. It works correct in this case, but might be wrong in other cases - so it's better to have that line as well (although we should probably rewrite append in Irrlicht to make this work always).
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: [SOLVED] Quad vanishes as the camera moves towards it?

Post by pandoragami »

CuteAlien wrote:Do also add the meshbuf->recalculateBoundingBox() after append and before drop. It works correct in this case, but might be wrong in other cases - so it's better to have that line as well (although we should probably rewrite append in Irrlicht to make this work always).
Sounds like a good idea although anyone using current versions of Irrlicht might be taken by it if this is changed. Anyways there's always a list of changes with every new distribution, must be mentioned in there then.
Post Reply