Error with event...

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
Soranne
Posts: 7
Joined: Thu Sep 30, 2010 10:17 am

Error with event...

Post by Soranne »

Hello everyone,

I've began to program a small FPS based on irrlicht but when I want my character to shoot with his gun (by clicking with the mouse) I have a little problem : sometimes the mouse can go away form the window and I can't control anymore the FPS camera... I'm using last irrLicht with Ubuntu 10.04

Here is my code :

main.cpp

Code: Select all

#include <irrlicht/irrlicht.h>
#include <irrklang/irrKlang.h>

#include "constantes.h"
#include "CEventReceiver.h"

using namespace irr;
using namespace irrklang;


int main(void)
{

//creating device driver scene manager and loading scene...
           ....

//On cree le capteur d'event et on l'associe au device.
    CEventReceiver receiver(i);
    device->setEventReceiver(&receiver);
    
    irr::scene::ISceneNode* nodeVise; 
    bool tire = false;
    core::vector2d<irr::s32> curseur;
    curseur.X= LARGEUR_FENETRE/2;  
    curseur.Y= HAUTEUR_FENETRE/2;
	
	
    while (device->run())
    {
        
        if(receiver.Tir())
        {
			if(tire == false)
			{
				nodeVise = sceneManager->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(curseur ,  0,false);
				if(nodeVise != NULL &&  meshNode != nodeVise)
				{
			
					nodeVise->setVisible(false);
					
				}
				tire = true;
			}
		}
		else
			tire = false;

		
        
        driver->beginScene(true, true, irr::video::SColor(0,255,255,255));
        
        sceneManager->drawAll ();
        driver->endScene ();
    }
 
    device->drop ();
    return 0;
}
CEventReceiver.h

Code: Select all

#include <irrlicht/irrlicht.h>
 
class CEventReceiver : public irr::IEventReceiver
{
 
public :
 
    //Le constructeur.
    CEventReceiver(int i );
    //Capte automatiquement les events.
    virtual bool OnEvent(const irr::SEvent &event);
    //Met a jour la position du mesh.
    bool Tir();
 
 
private :
 
    bool pressee;
    
};
CEventReceiver.cpp

Code: Select all

#include "CEventReceiver.h"

using namespace irr;

 
CEventReceiver::CEventReceiver(int i)
{     
    pressee = false;
}
 
 
bool CEventReceiver::OnEvent(const irr::SEvent& event)
{
    
    if(event.EventType == irr::EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == irr::EMIE_LMOUSE_PRESSED_DOWN)
    {
      
        pressee = true;
        return true;
    }
    else
    {
		pressee = false;
		
	}
    //Si on arrive la, c'est qu'on a pas traite l'event
    return false;
}

 
 
bool CEventReceiver::Tir()
{
    return pressee;
}



What's wrong with it?
i have another small question, if you have some meshes moving in your scene, do you have to recalculate the scenator for each frame (for collisions with the FPS camera), or would it take too much time?

Thanks a lot!
By the way
XFactor
Posts: 39
Joined: Fri Jun 03, 2005 5:30 am

Post by XFactor »

Try rendering only when the window is active?
IRRLICHT ROCKS!!!!
Post Reply