Relative Mouse Movement

Problems building or running the engine, queries about how to use features etc.

Relative Mouse Movement

Postby Aluthreney » Fri Dec 21, 2012 7:44 am

Hello once again.

I'm working on an FPS demo and I want the weapon's rotation to be dictated, in part, by the mouse's relative movement. I searched through the API documentation, but I didn't find any function that returns relative movement. My question(s):

Does Gameplay have functions that return the mouse's relative xy movement?

if (!question_above)
Where is the source code that capture's the mouse's xy position on screen so I can add those functions? I've also searched through the API documentation for this, but have not found it.

Alu :D
Aluthreney
 
Posts: 15
Joined: Fri Nov 09, 2012 6:41 am

Re: Relative Mouse Movement

Postby dgough » Fri Dec 21, 2012 12:34 pm

The game class has methods for turning on mouse capture and hiding the cursor.

User avatar
dgough
 
Posts: 213
Joined: Fri Jul 27, 2012 2:11 pm

Re: Relative Mouse Movement

Postby Aluthreney » Sat Dec 22, 2012 3:40 pm

Thats not what I'm looking for.

I'm looking for a function that tells me the mouse's relative movement, ei.: If the mouse moves, this function will return what axis the mouse moved on and the distance, in pixels, between it's last position to it's new position. I have been unable to find this function within Gameplay. If it does not exist I'd like to know how Gameplay gets a mouse's xy position on screen so I can add that function.

Alu :D
Aluthreney
 
Posts: 15
Joined: Fri Nov 09, 2012 6:41 am

Re: Relative Mouse Movement

Postby MasterOfBinary » Sat Dec 22, 2012 4:34 pm

Use mouse events, they'll give you the absolute position of the mouse - you can store them and every frame subtract the previous position from the current position to get the relative movement. There's information on events in the documentation under Input and sensors.

Link here: http://blackberry.github.com/GamePlay/d ... c337574576
User avatar
MasterOfBinary
 
Posts: 64
Joined: Mon Oct 01, 2012 11:43 pm
Location: Saskatoon, Canada

Re: Relative Mouse Movement

Postby Aluthreney » Wed Dec 26, 2012 11:44 am

dgough wrote:The game class has methods for turning on mouse capture and hiding the cursor.


I was able to pin down the relative mouse movement, but when I tried these two functions they didn't do anything, ei:

In my project cpp file, in the Initialize() function: setMouseCaptured(true);

That's all I did. It seemed like that was all I had to do, but nothing happened. Didn't get any errors or warnings either.
Aluthreney
 
Posts: 15
Joined: Fri Nov 09, 2012 6:41 am

Re: Relative Mouse Movement

Postby sgrenier » Wed Dec 26, 2012 3:17 pm

Aluthreney wrote:In my project cpp file, in the Initialize() function: setMouseCaptured(true);

That's all I did. It seemed like that was all I had to do, but nothing happened. Didn't get any errors or warnings either.


What platform are you using? I just tested this on Windows and it works fine for me. If it's not windows, it's very likely that it's not yet implemented on that platform and it's something we should fix.
User avatar
sgrenier
 
Posts: 351
Joined: Mon Jul 30, 2012 10:10 pm

Re: Relative Mouse Movement

Postby Aluthreney » Wed Dec 26, 2012 4:30 pm

Yea I started looking at the files and figured it out. I'm using ubuntu. I'm trying to define the function now.
Aluthreney
 
Posts: 15
Joined: Fri Nov 09, 2012 6:41 am

Re: Relative Mouse Movement

Postby Aluthreney » Wed Jan 02, 2013 7:40 am

I've been tinkering with x11 code while using PlatformWindows.cpp as reference and finally got the mouse to stick to the center of the screen. Unfortunately when I move the mouse pointer the screen vibrates as it moves. As far as I can tell, the XWarpPointer function seems to be affecting the movement of the mouse. I'm not really sure how to explain it, but here's the code:

definition of the setMouseCaptured()
Code: Select all
void Platform::setMouseCaptured(bool captured)
{
    if(captured!=__mouseCaptured)
    {
        if(captured)
        {
            p.x=getDisplayWidth()/2;
            p.y=getDisplayHeight()/2;

            // Hide cursor - function goes here......
            XWarpPointer(__display, None, __window, 0, 0, 0, 0, p.x, p.y);
        }

        else
        {
            XWarpPointer(__display, None, __window, 0, 0, 0, 0, p.x, p.y);
            // Unhide cursor - function goes here...
        }
        __mouseCaptured=captured;
    }
}


...and the relevant code in enterMessagePump()
Code: Select all
case MotionNotify:
                {
                    int x=evt.xmotion.x;
                    int y=evt.xmotion.y;
                   
                    if(__mouseCaptured)
                    {
                        if(x==p.x && y==p.y)
                            break;

                        x-=p.x;
                        y-=p.y;

                        XWarpPointer(__display, None, __window, 0, 0, 0, 0, p.x, p.y);
                    }

                    if (!gameplay::Platform::mouseEventInternal(gameplay::Mouse::MOUSE_MOVE, x, y, 0))
                    {
                        if (evt.xmotion.state & Button1Mask)
                        {
                            gameplay::Platform::touchEventInternal(gameplay::Touch::TOUCH_MOVE, x, y, 0);
                        }
                        else if (evt.xmotion.state & Button3Mask)
                        {
                            // Update the pitch and roll by adding the scaled deltas.
                            __roll += (float)(x - lx) * ACCELEROMETER_X_FACTOR;
                            __pitch += -(float)(y - ly) * ACCELEROMETER_Y_FACTOR;

                            // Clamp the values to the valid range.
                            __roll = max(min(__roll, 90.0f), -90.0f);
                            __pitch = max(min(__pitch, 90.0f), -90.0f);

                            // Update the last X/Y values.
                            lx = x;//evt.xbutton.x;
                            ly = y;//evt.xbutton.y;
                        }
                    }


Like I said before, I've been using PlatformWindows.cpp as a reference so the code structure/organization is practically the same. Since I have no real knowledge regarding x11 or windows api, I'm not really sure what I'm missing. If someone could look at the code and test it out and give me some feedback I'd be really thankful.
Aluthreney
 
Posts: 15
Joined: Fri Nov 09, 2012 6:41 am

Re: Relative Mouse Movement

Postby Aluthreney » Fri Jan 04, 2013 10:08 am

Ok, the problem is solved :D
Apparently the problem wasn't with x11. I went to revisit some older code I had inside the overridden mouseEvent() function and found that it was conflicting with the setMouseCaptured() function. So the code I posted above should work fine. The only thing missing now is turning the cursor invisible.
Aluthreney
 
Posts: 15
Joined: Fri Nov 09, 2012 6:41 am


Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest