[Solved] Mesh disappears

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
Willem
Posts: 8
Joined: Wed Apr 07, 2010 1:33 am
Location: New Zealand

[Solved] Mesh disappears

Post by Willem »

Apologies for the noise, after setting the camera's far and near values, all is good.

Hi,

I have a large mesh. It is only visible if the camera is positioned far away, and disappears as the camera moves closer. From other threads I gathered it could be that the bounding box of the mesh buffers and mesh itself need to be recalculated. I tried that without success. If I position the camera close to the mesh, it is not visible at all.
Any advice would be appreciated.

Thanks
Willem

Code: Select all

void recalc_bbox(SAnimatedMesh* m)
{
    u32 count = m->getMeshBufferCount();
    IMeshBuffer* b;

    for (u32 i = 0; i < count; i++) {
        b = m->getMeshBuffer(i);
        b->recalculateBoundingBox();
    }

    m->recalculateBoundingBox();
}

int main(void)
{
    float x = 0, y = 1.0f, z = 0;
    int lastfps = 0, fps = 0, count = 0;
    SAnimatedMesh smesh;

    IrrlichtDevice* device = createDevice(video::EDT_OPENGL,
            (core::dimension2d<u32>(640, 480)), 16,
            false, false, false, 0);

    if (!device)
        return 1;

    device->setWindowCaption(L"Hello world");

    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();
    ICameraSceneNode* cam = NULL;

    guienv->addStaticText(L"Hello world", rect<s32>(10, 10, 260,22));

    IAnimatedMesh* mesh = smgr->getMesh("data/irrlicht/mdl/road.irrmesh");
    if (!mesh) {
        return 1;
    }

    smesh.addMesh((IMesh*)mesh);

    IAnimatedMeshSceneNode* node =
        smgr->addAnimatedMeshSceneNode(mesh);

    if (node) {
        node->setMaterialFlag(EMF_LIGHTING, false);
        node->setMD2Animation(scene::EMAT_STAND);
        node->setMaterialTexture(0,
                driver->getTexture("data/gimp/tarsmooth_vert_512X512.bmp"));
        node->setPosition(vector3df(-4.970404, 0, -2.243534));
    }
cam = smgr->addCameraSceneNode(0,
            vector3df(0, y, 0), // camera pos
            vector3df(0, 0.009562, 0)); // lookat pos
    //smgr->addCameraSceneNodeFPS(0, 5.0f, 0.001f);

    while (device->run()) {

        driver->beginScene(true, true, SColor(255, 255, 255, 255));
        smgr->drawAll();
        guienv->drawAll();
        driver->endScene();
        cam->setPosition(vector3df(0, y, 0));
        y -= 0.001;
        usleep(50000);
        recalc_bbox(&smesh);

        fps = driver->getFPS();

        if (lastfps != fps) {
            stringw str = driver->getName();
            str += " Fps:";
            str += fps;
            device->setWindowCaption(str.c_str());
            lastfps = fps;
        }

        if ((count++ % 400) == 0) {
            //takeScreenshot(device);
        }


    }

    device->drop();


    return 0;
}
[/code]
blAaarg
Posts: 94
Joined: Tue Mar 02, 2010 9:11 pm
Location: SoCal

Post by blAaarg »

Your camera is pointed straight down and when you move it, it catches up to its target and flips around facing the other way, so your node is no longer in the view. If you're going to point your camera like that, be careful you don't get gimbal locked in that position. Cameras can behave funny when pointing straight up or down or close to it.

Also, you don't need to reset the bounding box since your mesh isn't changing. :)
"Computers don't make mistakes! What they do they do on purpose!!"

-Dale Gribble
Post Reply