Mouse Move Delta

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
kklouzal
Posts: 343
Joined: Sun Mar 28, 2010 8:14 pm
Location: USA - Arizona

Mouse Move Delta

Post by kklouzal »

Hey guys I'm trying to calculate the mouse move delta so I can apply it to a node's rotation, I'm using the EMIE_MOUSE_MOVED event inside an event receiver and the issue is when the mouse is reset to the center of the screen that too fires the event. I've been trying to think of a way to compensate for this but I'm drawing a blank. Here's what I've got going on so far, I removed all code not related to the issue:

Code: Select all

class MyEventReceiver : public irr::IEventReceiver
{
public:
 
    struct SMouseState
    {
    public:
        SMouseState()
        {
            Position.X = 0;
            Position.Y = 0;
            LastPosition = Position;
        }
 
        void UpdateMousePosition(irr::s32 XPos, irr::s32 YPos)
        {
            LastPosition = Position;
            Position = irr::core::position2di(XPos, YPos);
            MoveDelta = LastPosition - Position;
            std::cout << (int)MoveDelta.X << " " << (int)MoveDelta.Y << std::endl;
        }
 
        irr::core::position2di GetMoveDelta()
        {
            return MoveDelta;
        }
    private:
        irr::core::position2di Position;
        irr::core::position2di LastPosition;
        irr::core::position2di MoveDelta;
    } MouseState;
 
    MyEventReceiver()
    {}
 
    bool OnEvent(const irr::SEvent& event)
    {
        if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
        {
            if (event.MouseInput.Event == irr::EMIE_MOUSE_MOVED)
            {
                MouseState.UpdateMousePosition(event.MouseInput.X, event.MouseInput.Y);
            }
        }
 
        return false;
    }
};
When the mouse is moved the delta is displayed in console but then when the mouse snaps back to the center of the screen that delta is displayed in console also which in turn negates the movement.

I appreciate any insight into this issue, I appreciate your time.
Dream Big Or Go Home.
Help Me Help You.
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Mouse Move Delta

Post by thanhle »

First you might need the mouse down event to get the last pos.
While the button is down and mouse move calculate relative delta.

Regards
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Mouse Move Delta

Post by CuteAlien »

Do you reset the mouse or are you using the fps-animator?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
kklouzal
Posts: 343
Joined: Sun Mar 28, 2010 8:14 pm
Location: USA - Arizona

Re: Mouse Move Delta

Post by kklouzal »

Using addCameraSceneNodeFPS() or via device->getCursorControl()->setPosition(irr::core::position2di(400, 300)) both fire the event receiver when the mouse is repositioned in the center of the screen. However I would rather not opt to use addCameraSceneNodeFPS since I'm parenting the camera to a scene node rotating the node in the left and right and the camera in the up and down.

EDIT: Is there another way to physically set the mouse position that doesn't involve irr::gui? I plan to compile Irrlicht without GUI in the future.
Dream Big Or Go Home.
Help Me Help You.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Mouse Move Delta

Post by CuteAlien »

The reason I asked is that when you set it yourself you know when the cursor is reset and you can correspondingly reset the variables in your mouse-move event. With the FPS animator it's probably not possible.

And it seems ICursorControl will stay in even if you don't compile with the gui despite it's namespace. As far as I can see that define only affects gui elements.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
kklouzal
Posts: 343
Joined: Sun Mar 28, 2010 8:14 pm
Location: USA - Arizona

Re: Mouse Move Delta

Post by kklouzal »

Okay thank you very much CuteAlien, it's good to know ICursorControl will stay. I was trying with just the regular ICameraSceneNode but that's when I was running into the issue of the event firing again when I reset the mouse position. I'll take another crack at it. Thank you very much for your time helping here :)
Dream Big Or Go Home.
Help Me Help You.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Mouse Move Delta

Post by CuteAlien »

Yeah - the event still fires. But you know now _when_ it fires. So you can save the old position before and the new afterwards and disregard that change.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply