Smoother mouse-controlled rotation, or at least get rid of the pointer :)

I’ve been trying to make a quake3-like control interface for my programs without using glut. I took the glx NEHE tutorial #10 (the one where you move around in the room that has the face texture all over the walls.) and modified it so that the mouse makes you rotate about the up axis.

The problem is that its choppy. I suspect its the method I’m using for getting the mouse events. all i added to the tutorial was:

case MotionNotify:
mouseAction(event.xmotion.x, event.xmotion.y);
break;

to this larger part in “int main()” which is this:

 while (!done)
    {
        /* handle the events in the queue */
        while (XPending(GLWin.dpy) > 0)
        {
            XNextEvent(GLWin.dpy, &event);
            switch (event.type)
            {
                case Expose:
                 if (event.xexpose.count != 0)
                     break;
                    drawGLScene();
                    break;
                case ConfigureNotify:
                /* call resizeGLScene only if our window-size changed */
                    if ((event.xconfigure.width != GLWin.width) | |
                        (event.xconfigure.height != GLWin.height))
                    {
                        GLWin.width = event.xconfigure.width;
                        GLWin.height = event.xconfigure.height;
                        printf("Resize event
");
                        resizeGLScene(event.xconfigure.width,
                            event.xconfigure.height);
                    }
                    break;
                /* exit in case of a mouse button press */
                case ButtonPress:
                    done = True;
                    break;
  case MotionNotify:
      mouseAction(event.xmotion.x, event.xmotion.y);
      break;
                case KeyPress:
                    keys[event.xkey.keycode] = True;
                    break;
                case KeyRelease:
                    keys[event.xkey.keycode] = False;
                    break;
                case ClientMessage:    
                    if (*XGetAtomName(GLWin.dpy, event.xclient.message_type) ==
                        *"WM_PROTOCOLS")
                    {
                        printf("Exiting sanely...
");
                        done = True;
                    }
                    break;
                default:
                    break;
            }
        }

the mouseAction function is simple; the if() basically keeps it from doing a 100 degree rotation in one frame. The if() only makes a difference when you move the mouse fast. Performace is still choppy at low speeds with or without it:

void mouseAction(int x, int y)
{
if((x-300 > -7)| |(x-300<7))
rotY -= (x-300)/7.0;
else
rotY -=1.0;

XWarpPointer(GLWin.dpy, None, GLWin.win, 0, 0, 0, 0, 300, 300);
}

If you know of some better way to get mouse info for doing a rotation please tell me. thanks. if you want my complete modified version of the lesson10.c so you can compile it and see for yourself what i’m talking about, I’ll post it.

[EDIT]: Let me explain what i mean by choppy. I’ve played around with the thing for a while now and i’m sure its not the angle i’m rotating through or anything like that. It’s choppy as in it looks like its running at 10 fps. But its not that because i can press the arrow button and it rotates as smoothly as possible. Its as if I only get a pointer motion event every now and then, and not whenever the mouse moves.


One more thing how do i make the pointer disapear?

[This message has been edited by grady (edited 06-08-2001).]

[This message has been edited by grady (edited 06-08-2001).]

Is the call to XWarpPointer necessary?

Try it without.

To make the cursor disappear:
http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/003653.html

The call to warp pointer puts the pointer back at 300,300 because thats the reference point. if that isn’t there then the part about rotY = (x-300)/7.0 doesn’t work write.

each time the pointer goes back then you move it and the program calculates how far it went from 300, 300. Thats how it decides the angle. Then it puts the pointer back at 300, 300 to do the whole process over again.

Heh, silly me, I didn’t see the 300, 300 on the end. Never mind.

I don’t think there’s enough info here to figure out what’s going wrong. If you could post or e-mail your project, I’d be happy to lend a second pair of eyeballs.

Thanks for looking into it rts. .

ughh, I think I have another lead as to how to fix this. I think in between the every-so-often MotionNotify signals, the mouse movements gets stored in a buffer that I can read with XGetMotionEvents(). I’m trying to use it know but its troublesome (segmentation faults everywhere) . Once I get to the brink of insanity I’ll post again for help. :expressionless:

[This message has been edited by grady (edited 06-09-2001).]

I am having this same problem,
does anyone know the solution?

TIA

I guess you’re encoutering the famous ‘I’m used to Win32 messaging behaviour’

XWarpPointer moves the pointer, and it generates a MotionNotify event. Your code actually generates an infinite recursion in the event loop, and the choppy effect comes from the overloaded X event stack that keeps growing.
The fastest trick (maybe not the cleanest) is to filter the events triggered by your implicit call to XWarpPointer. Replace :

case MotionNotify:
mouseAction(event.xmotion.x, event.xmotion.y);
break;

by :

case MotionNotify:
if ((event.xmotion.x != 300) | | (event.xmotion.y != 300))
mouseAction(event.xmotion.x, event.xmotion.y);
break;

X11 events just suck for a descent mouse handling. Use the dga extension to get direct access to the mouse…

Julien.

Thanks of the tip,

you would have any examples of how to do this?
Or any sites to look at?

Thanks in advace.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.