Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

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

  1. #1
    Junior Member Regular Contributor
    Join Date
    Sep 2000
    Posts
    205

    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:

    Code :
    case MotionNotify:
     mouseAction(event.xmotion.x, event.xmotion.y);
     break;
    to this larger part in "int main()" which is this:

    Code :
     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\n");
                            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...\n");
                            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:

    Code :
    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).]

  2. #2
    Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Vancouver BC Canada
    Posts
    433

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

    Is the call to XWarpPointer necessary?

    Try it without.

    To make the cursor disappear:
    http://www.opengl.org/discussion_boa...ML/003653.html

  3. #3
    Junior Member Regular Contributor
    Join Date
    Sep 2000
    Posts
    205

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

    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.

  4. #4
    Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Vancouver BC Canada
    Posts
    433

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

    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.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Sep 2000
    Posts
    205

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

    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. :|

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

  6. #6
    Junior Member Newbie
    Join Date
    Oct 2001
    Posts
    16

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

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

    TIA

  7. #7
    Junior Member Newbie
    Join Date
    Dec 2001
    Location
    Paris, France
    Posts
    29

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

    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) &#0124; &#0124; (event.xmotion.y != 300))
    mouseAction(event.xmotion.x, event.xmotion.y);
    break;

  8. #8
    Member Regular Contributor Julien Cayzac's Avatar
    Join Date
    Aug 2001
    Location
    Yokohama, Japan
    Posts
    251

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

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

    Julien.

  9. #9
    Junior Member Newbie
    Join Date
    Oct 2001
    Posts
    16

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

    Thanks of the tip,

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

    Thanks in advace.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •