I have tried to implement an event reciever in my program, i used a lot of the code form the Mercior Irrlicht/Newton tutorial. But when i click the mouse or hit escape nothing happens, put in breakpoints and execution never reaches callback. Any ideas?
bool CGame::OnEvent(SEvent event)
{
printf("Newt~licht Event Recieved...");
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{
// make a cube where the camera is and set its velocity to follow the target
NewtonModel *tmp = MakeModel(cam->getPosition()/*, veloc*/);
if (!tmp) return false;
vector3df camvec = (cam->getTarget() - cam->getPosition()).normalize() * 500;
float newpos[3] = { camvec.X, camvec.Y, camvec.Z };
NewtonBodySetVelocity(tmp->body1, (float*)newpos);
}
else if(event.EventType == EET_GUI_EVENT)
{
//here put GUI STUFF
}
else if( event.EventType == EET_KEY_INPUT_EVENT)
{
bool key[KEY_KEY_CODES_COUNT];
key[event.KeyInput.Key] = event.KeyInput.PressedDown;
if(key[KEY_ESCAPE])
{
NewtonReleaseCollision(nWorld, floor->collision);
NewtonDestroy(nWorld);
device->drop();
}
}
return false;
}
DISCLAIMER: Having read this post & all information therein,you have entered into a legally binding contract.You are obliged to agree wholeheartedly with all opinions expressed within this post.Failure to comply will be deemed a breach of contract.
return true if you handle the event, return false if you don't.
For example, if you're using an FPS camera, and also trying to get input from other keys. You need to return false from your event receiver's OnEvent function if it gets the KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT. If you return true, it means you're handling the event and noone else should.
bool CGame::OnEvent(SEvent event)
{
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{
// make a cube where the camera is and set its velocity to follow the target
NewtonModel *tmp = MakeModel(cam->getPosition()/*, veloc*/);
if (!tmp) return false;
vector3df camvec = (cam->getTarget() - cam->getPosition()).normalize() * 500;
float newpos[3] = { camvec.X, camvec.Y, camvec.Z };
NewtonBodySetVelocity(tmp->body1, (float*)newpos);
return true; ///// IS THIS WHERE IT SOULD GO?
}
At the end of each reletive section, check with if statement, if valid do lines of code, return true. That how it goes?
DISCLAIMER: Having read this post & all information therein,you have entered into a legally binding contract.You are obliged to agree wholeheartedly with all opinions expressed within this post.Failure to comply will be deemed a breach of contract.
Do i put in the name of the event reciever or just specify that there is one and the program will pick up on it??
once again though, can anyone tell me WHERE i return true within my event reciever?
DISCLAIMER: Having read this post & all information therein,you have entered into a legally binding contract.You are obliged to agree wholeheartedly with all opinions expressed within this post.Failure to comply will be deemed a breach of contract.
Thanks a million jox, you have now achieved guru status in my books. Simple problems are always the hardest to solve without experts around!
Completely forgot the event reciever was even dealt with in createDevice. Threw in a 'this' at the end and everythin was hunky-dorey!!!! I now have poop flying out of my camera!!!!!!
DISCLAIMER: Having read this post & all information therein,you have entered into a legally binding contract.You are obliged to agree wholeheartedly with all opinions expressed within this post.Failure to comply will be deemed a breach of contract.