Scene node collision with terrain

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
hammeraxe
Posts: 9
Joined: Sun Nov 04, 2007 4:51 pm
Location: LV

Scene node collision with terrain

Post by hammeraxe »

ive created a terrain and a scene node. ive set up the triangle selector. ive set up an event receiver to move the node.
when i move the node around the terrain it slides up the mountains but when i move away from the hills it doesnt fall down unless i release the movement key. when i release the key it falls down as it should... but why doesnt it fall down in the first place???
oldskoolPunk
Posts: 199
Joined: Wed Nov 29, 2006 4:07 am

Post by oldskoolPunk »

Hi there
Posting your code will greatly increase your chances of getting help. :)
Signature? I ain't signin nuthin!
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

sounds like a portal effect you just accidentally coded.

the cake is a lie!

;-)
Image
hammeraxe
Posts: 9
Joined: Sun Nov 04, 2007 4:51 pm
Location: LV

Post by hammeraxe »

Ok, im posting the code... hope it helps

Code: Select all

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

 using namespace irr;
 using namespace core;
 using namespace scene;
 using namespace video;
 using namespace io;
 using namespace gui;
 using namespace std;
 
IrrlichtDevice *device =0; 
bool keys[irr::KEY_KEY_CODES_COUNT]; 
bool mouse[EMIE_COUNT];


class MyEventReceiver : public IEventReceiver
{
 public:
   bool OnEvent(const SEvent& event) 
   {
     if(event.EventType == irr::EET_KEY_INPUT_EVENT)
     {
       keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
       return false;
     }
     return false; 
};
 
 
void move(irr::scene::ISceneNode *node, 
            irr::core::vector3df vel) 
{
    irr::core::matrix4 m;
    m.setRotationDegrees(node->getRotation());
    m.transformVect(vel);
    node->setPosition(node->getPosition() + vel);
    node->updateAbsolutePosition();
}

 
 int main()
 {
     
     video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9;
     printf("Izveeleeties draiveri:\n"   " 1) Direct3D 9.0c\n 2) Direct3D 8.1\n 3) OpenGL 1.5\n"    " 4) Software Renderer\n 5) NullDevice\n\n");
     char i;
     cin >> i;
     switch(i){   
                  case '1': driverType = video::EDT_DIRECT3D9;break;   
                  case '2': driverType = video::EDT_DIRECT3D8;break;   
                  case '3': driverType = video::EDT_OPENGL;   break;   
                  case '4': driverType = video::EDT_SOFTWARE; break;   
                  case '5': driverType = video::EDT_NULL;break;   
                  default: return 1;
                  }	
                  
     printf("Izveeleeties izskirtspeeju:\n"   " 1) 320*240\n 2) 640*480\n 3) 800*600\n" );
     cin >> i;
     int x,y;
     switch(i){   
                  case '1': x=320;y=240;break;   
                  case '2': x=640;y=480;break;   
                  case '3': x=800;y=600;break;   
                  default: return 1;
                  }	
                  cout<<"Uzstaadiitaa izskirtspeeja: "<<x<<"*"<<y<<"\n";
                  cin.ignore();
        // start up the engine
        MyEventReceiver rv;
        IrrlichtDevice *device =   createDevice(driverType,core::dimension2d<s32>(x,y),32,false,false,false,0);
        if (device == 0)   return 1;
        video::IVideoDriver* driver = device->getVideoDriver();
        scene::ISceneManager* scenemgr = device->getSceneManager();
        
         device->setEventReceiver(&rv);
       for(int q=0; q<irr::KEY_KEY_CODES_COUNT; q++) keys[q] = false; 
       for(int q=0; q<EMIE_COUNT; q++)  mouse[q]=false; 
       
        device->setWindowCaption(L"Izmeeginaajums");

        ISceneNode* SkyBox = scenemgr->addSkyBoxSceneNode(
        driver->getTexture("irrlicht2_up.jpg"),
        driver->getTexture("irrlicht2_dn.jpg"),
        driver->getTexture("irrlicht2_ft.jpg"),
        driver->getTexture("irrlicht2_bk.jpg"),
        driver->getTexture("irrlicht2_lf.jpg"),
        driver->getTexture("irrlicht2_rt.jpg"));      
 
 
        scene::ITerrainSceneNode* terrain = scenemgr->addTerrainSceneNode( 
      "terrain-heightmap.bmp");
      terrain->setPosition(vector3df(0,-500,0));
      terrain->setScale(core::vector3df(40, 4.4f, 40));
      terrain->setMaterialFlag(video::EMF_LIGHTING, false);

      terrain->setMaterialTexture(0, driver->getTexture(
      "terrain-texture.jpg"));
       terrain->setMaterialTexture(1, driver->getTexture(
       "detailmap3.jpg"));
	
       terrain->setMaterialType(video::EMT_DETAIL_MAP);
       terrain->scaleTexture(1.0f, 20.0f);

       scene::ITriangleSelector* selector =
       scenemgr->createTerrainTriangleSelector(terrain, 0);
       terrain->setTriangleSelector(selector);
       selector->drop();

       ISceneNode* dummy=scenemgr->addCubeSceneNode();
        dummy->setVisible(true);
        
        scene::ISceneNodeAnimator* camCollision =
        scenemgr->createCollisionResponseAnimator(
		selector, dummy, core::vector3df(30,50,30),
		core::vector3df(0,-3,0),
		core::vector3df(0,50,0));
		
		dummy->addAnimator(camCollision);
        
        ICameraSceneNode* camera=scenemgr->addCameraSceneNode();
        camera->setPosition(vector3df(-100,300,0));

        int lastFPS = -1;
        float CamAngle=0;
        int CamZoom=300;
        while(device->run() && driver)
        {
               if(keys[KEY_KEY_W]) {
                move(dummy,vector3df(-5,0,0));
                                    }       
                if(keys[KEY_KEY_S]) {
                move(dummy,vector3df(5,0,0));
                                    } 
                if(keys[KEY_KEY_A]) {
                move(dummy,vector3df(0,0,-5));
                                    }      
                if(keys[KEY_KEY_D]) {
                move(dummy,vector3df(0,0,5));
                                    } 
                                    
                if(keys[KEY_KEY_Q]) {
                CamAngle+=1*(3.14/180);
                dummy->setRotation(dummy->getRotation()-vector3df(0,1,0));
                                    }    
                 if(keys[KEY_KEY_E]) {
                CamAngle+=-1*(3.14/180);
                dummy->setRotation(dummy->getRotation()-vector3df(0,-1,0));
                                    } 
                 if(keys[KEY_KEY_R]) {
                CamZoom+=10;
                                    }    
                 if(keys[KEY_KEY_F]) {
                CamZoom+=-10;
                                    }                      
                                                                          
                                      
                driver->beginScene(true, true, video::SColor(255,0,0,255));
                scenemgr->drawAll();
                
                driver->endScene();
                
                camera->setTarget(dummy->getPosition()); 
                camera->setPosition(dummy->getPosition()+vector3df(CamZoom*cos(CamAngle),CamZoom,CamZoom*sin(CamAngle)));         
                
                
                int fps = driver->getFPS();
                if (lastFPS != fps)
                 {

     core::stringw str = L"Izmeeginaajums (Draiveris: ";
     str+=driver->getName();
     str+=" Izskirtspeeja: ";
     str+=x;
     str+="*";
     str+=y;
     str+=" Kadri sekundee: ";
     str+=fps;
     str+=")";        
     device->setWindowCaption(str.c_str());     
     lastFPS = fps;

               }


        }

        // delete device
        device->drop();
        cout<<"Beigas...";
        return 0;
 }
 
          
hammeraxe
Posts: 9
Joined: Sun Nov 04, 2007 4:51 pm
Location: LV

Post by hammeraxe »

anyone...?
Post Reply