Terrain dissapears

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
onesixtyfourth
Posts: 21
Joined: Mon Nov 03, 2008 10:18 am

Terrain dissapears

Post by onesixtyfourth »

I have been following tutorial number 15 for loading a file and then adding fps camera to it so I can walk around the scene. I have used the terrain.irr file that comes with irrlicht and I can successfully load it and run the program. As soon as I use the controls to move the camera the whole scene dissapears and doesn't ever come back. It doesn't look as though the position of hte camera has changed just not rendering the scene any more.

I tried searching for this but didn't find anything that seemed to be relevant so I am posting to see if anyone knows what could be causing this problem. I have just upgraded to version 1.5 if that helps.
Glasys
Noli illegitimi carborundum
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Any chance you could post your source?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
onesixtyfourth
Posts: 21
Joined: Mon Nov 03, 2008 10:18 am

Post by onesixtyfourth »

Ok but it is pretty much the code of tutorial 15.

Code: Select all

#include <iostream>
#include <irrlicht.h>

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

int main(int argc, char** argv)
{
    // ask user for driver
    video::E_DRIVER_TYPE driverType;

    printf("Please select the driver you want for this example:\n"\
            " (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
            " (d) Software Renderer\n (e) Burning's Software Renderer\n"\
            " (f) NullDevice\n (otherKey) exit\n\n");

    char i;
    std::cin >> i;

    switch(i)
    {
            case 'a': driverType = video::EDT_DIRECT3D9;break;
            case 'b': driverType = video::EDT_DIRECT3D8;break;
            case 'c': driverType = video::EDT_OPENGL;   break;
            case 'd': driverType = video::EDT_SOFTWARE; break;
            case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
            case 'f': driverType = video::EDT_NULL;     break;
            default: return 1;
    }

    IrrlichtDevice *device = createDevice(driverType, dimension2d<s32>(800, 600),
                                                        32, false, false, false);

    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();



    // load the scene
    smgr->loadScene("scene/terrain.irr");

 // add a first person shooter style user controlled camera
    SKeyMap keyMap[8];
             keyMap[0].Action = EKA_MOVE_FORWARD;
             keyMap[0].KeyCode = KEY_UP;
             keyMap[1].Action = EKA_MOVE_FORWARD;
             keyMap[1].KeyCode = KEY_KEY_W;

             keyMap[2].Action = EKA_MOVE_BACKWARD;
             keyMap[2].KeyCode = KEY_DOWN;
             keyMap[3].Action = EKA_MOVE_BACKWARD;
             keyMap[3].KeyCode = KEY_KEY_S;

             keyMap[4].Action = EKA_STRAFE_LEFT;
             keyMap[4].KeyCode = KEY_LEFT;
             keyMap[5].Action = EKA_STRAFE_LEFT;
             keyMap[5].KeyCode = KEY_KEY_A;

             keyMap[6].Action = EKA_STRAFE_RIGHT;
             keyMap[6].KeyCode = KEY_RIGHT;
             keyMap[7].Action = EKA_STRAFE_RIGHT;
             keyMap[7].KeyCode = KEY_KEY_D;

    scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(
                                    0, 100, 300, -1, keyMap, 8, true, 3);


    // Create a meta triangle selector to hold several triangle selectors.
    scene::IMetaTriangleSelector * meta = smgr->createMetaTriangleSelector();

    core::array<scene::ISceneNode *> nodes;
    smgr->getSceneNodesFromType(scene::ESNT_ANY, nodes); // Find all nodes

    for (u32 i=0; i < nodes.size(); ++i)
    {
        scene::ISceneNode * node = nodes[i];
        scene::ITriangleSelector * selector = 0;

        switch(node->getType())
        {
        case scene::ESNT_CUBE:
        case scene::ESNT_ANIMATED_MESH:
                // Because the selector won't animate with the mesh,
                // and is only being used for camera collision, we'll just use an approximate
                // bounding box instead of ((scene::IAnimatedMeshSceneNode*)node)->getMesh(0)
                selector = smgr->createTriangleSelectorFromBoundingBox(node);
        break;

        case scene::ESNT_MESH:
        case scene::ESNT_SPHERE: // Derived from IMeshSceneNode
                selector = smgr->createTriangleSelector(((
                            scene::IMeshSceneNode*)node)->getMesh(), node);
                break;

        case scene::ESNT_TERRAIN:
                selector = smgr->createTerrainTriangleSelector((
                                            scene::ITerrainSceneNode*)node);
                break;

        case scene::ESNT_OCT_TREE:
                selector = smgr->createOctTreeTriangleSelector(((
                                scene::IMeshSceneNode*)node)->getMesh(), node);
                break;

        default:
                // Don't create a selector for this node type
                break;
        }

        if(selector)
        {
                // Add it to the meta selector, which will take a reference to it
                meta->addTriangleSelector(selector);
                // And drop my reference to it, so that the meta selector owns it.
                selector->drop();
        }
    }


    scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
                                                meta, camera, core::vector3df(5,5,5),
                                                                core::vector3df(0,0,0));
    meta->drop(); // I'm done with the meta selector now

    camera->addAnimator(anim);
    anim->drop(); // I'm done with the animator now


    // And set the camera position so that it doesn't start off stuck in the geometry
    camera->setPosition(core::vector3df(0.f, 50.f, 150.0f));


    //get rid of the cursor
    device->getCursorControl()->setVisible(false);

    int lastFPS = -1;

    while(device->run())
    {
        driver->beginScene(true, true, video::SColor(0,200,200,200));
        smgr->drawAll();
        driver->endScene();

        int fps = driver->getFPS();

        if (lastFPS != fps)
        {
            core::stringw str = L"Load Irrlicht File example - Irrlicht Engine [";
            str += driver->getName();
            str += "] FPS:";
            str += fps;

            device->setWindowCaption(str.c_str());
            lastFPS = fps;
        }
    }

    device->drop();

    return 0;
}
Glasys
Noli illegitimi carborundum
psychophoniac
Posts: 101
Joined: Wed Dec 03, 2008 5:33 pm
Location: ger

Post by psychophoniac »

i had this problem too, the terrain doesn't disappear, its just out of the cameras FarValue ^^
change the cameras speed (when calling smgr->addCameraSceneNodeFPS(...)), it is too high in this example, i think you have to set it around 0.5f somewhere since irrlicht V 1.5.
speed is the 3rd value, but i dont know exactly, look at the source.
i love skateboarding!
onesixtyfourth
Posts: 21
Joined: Mon Nov 03, 2008 10:18 am

Post by onesixtyfourth »

That was it thanks.
Glasys
Noli illegitimi carborundum
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

^^^ What he said.
onesixtyfourth wrote:Ok but it is pretty much the code of tutorial 15.
Indeed, which is why we needed to see the difference. ;)
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply