moving around a node with keyboard

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
Guest

moving around a node with keyboard

Post by Guest »

i have a model in a scene as a node called select
here is the code for calling select:

Code: Select all

    mesh = irrSceneMgr->getMesh("select3.3DS"); //low poly
    IAnimatedMeshSceneNode* nodeSel = 0;  
    if (mesh) {
       nodeSel = irrSceneMgr->addAnimatedMeshSceneNode(mesh);
       nodeSel->setPosition(vector3df(0,20,0));
       nodeSel->setMaterialTexture(0, irrDriver->getTexture("blue.bmp")); // set diffuse texture 
       nodeSel->addShadowVolumeSceneNode(-1, false);
       nodeSel->setMaterialFlag(EMF_LIGHTING, false); // disable dynamic lighting
       nodeSel->setMaterialFlag(EMF_GOURAUD_SHADING, false); // remove shading
    }
now i have my event reciever set up, what i want to do is move that node by 75 "units" in a direction depending on the input. for input i wanna use WSAD or arrow keys, either will work fine.

here is event reciever code atm:

Code: Select all

class irrEventReceiver : public IEventReceiver {
    public: virtual bool OnEvent(SEvent event) {
    		if (event.EventType == EET_GUI_EVENT) { //gui event (menu select)
    			/*
			theres some gui menu stuff here, but i dont think its important atm
			*/
            } // if (event.EventType == EET_GUI_EVENT)
        	if (nodeSel != 0 && event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown) { //key event (movement)
				int temp; // this is a temp var just to see if netin is happenin...
        			switch(event.KeyInput.Key) {
            			case KEY_KEY_W: temp = 1; break;
            			case KEY_KEY_S: temp = 2; break; 
            			case KEY_KEY_A: temp = 3; break;
            			case KEY_KEY_D: temp = 4; break;
   			        } // switch(event.KeyInput.Key)
        	} // else if (nodeSel != 0 && event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
   	} //public: virtual bool OnEvent(SEvent event)
   	
};    // class irrEventReceiver : public IEventReceiver
problem is no matter what i put in the case statement where it says temp = (somenumber) it will compile/build properly but when i run the binary and press a WSAD button it crashes the program...

as far as i can tell, to move my select node i would have to have code like this:

Code: Select all

vector3df v = nodeSel->getPosition(); //get current pos
v.X/Y/Z += -100.0f; //x/y/z and the amount to + or - from current x/y/z val
nodeSel->setPosition(v); //set new pos
but like i said, having anything in there just crashes the program

i know it DOES know what keys are being pressed cause it only crashes on WSAD, but, it just doesnt seem to wanna do anything after it figures out what button is pressed heh

im using devc++ and irrlicht 0.9 and opengl as the renderer (if that matters)
discreet
Posts: 17
Joined: Sat Jun 04, 2005 5:51 am

Post by discreet »

yeah the GUI menu stuff is important, It crashes if there is the smallest mistake in the GUI events... for some reason... atleast for me.
Post Reply