Mouse 'control' prob in OpenGL

This is a discussion on Mouse 'control' prob in OpenGL within the Game Programming forums, part of the General Programming Boards category; Hey, Im currently trying to add some mouse control support for my 3rd person camera system. I have used glutPassiveMotionFunc ...

  1. #1
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72

    Mouse 'control' prob in OpenGL

    Hey, Im currently trying to add some mouse control support for my 3rd person camera system. I have used glutPassiveMotionFunc to get the position and when it move it left or right it rotates the view as required. How, its a bit jumpy because it only seems to pickup on the position of the mouse when its moved. Its also hard to control. Its kinda hard to explain...

    anyway, I was wondering if there is like a set cursor position function or a similar method to capture the mouse so that it gets set to the middle all the time to improve the control of the mouse. No DirectX though please. Just OpenGL stuff. Thankyou.

  2. #2
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    #define SCREEN_WIDTH 1024
    #define SCREEN_HEIGHT 768

    static float MiddleX = SCREEN_WIDTH / 2;
    static float MiddleY = SCREEN_HEIGHT / 2;
    POINT MousePos;
    GetCursorPos(&MousePos); //get current position
    SetCursorPos(MiddleX, MiddleY); //put back to middle

  3. #3
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72
    it won't let my scene load when i use that. I get a blank screen with my mouse stuck. However, i will have a play and see what i can do. Thank you

  4. #4
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    #include <windows.h>

    EDIT:
    Post some source I can look at

  5. #5
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72
    I have windows.h included. But i still have problems.

    Hers some code for the glutPassiveFunc call back function

    Code:
    void mouse(int iX, int iY)
    {
    if(iX<(SCREEN_WIDTH/2))
    	iX=-((SCREEN_WIDTH/2)-iX);
    else
    	iX=(iX-(SCREEN_WIDTH/2)); // used to convert from top left origin to middle
    
    cCamera.MouseAngleX=180.0*iX/SCREEN_WIDTH;
    
    MouseMoveView();
    
    glutPostRedisplay();
    }
    and the camera function
    Code:
    void MouseMoveView(void)
    {
    float fMouseX=cCamera.MouseAngleX, fAngleY=0.0f;
    int iMidPointX=SCREEN_WIDTH/2, iMidPointY=SCREEN_HEIGHT/2;	
    	
    if(fMouseX==iMidPointX)
    	return;
    
    // GetCursorPos(&MousePos); //get current position. not currently needed as cCamera.MouseAngleX gets it
    SetCursorPos(iMidPointX, iMidPointY); 
    cCamera.MouseAngleX=iMidPointX;	// Set the mouse to the middle						
    
    if(fMouseX>cCamera.MouseAngleX)	// Get the direction from the mouse
    	fAngleY=-(fMouseX-iMidPointX)/1000;
    if(fMouseX<=cCamera.MouseAngleX)
    	fAngleY=(fMouseX-iMidPointX)/1000;
    
    //printf("\n%.2f %.2f", fAngleY, fMouseX);
    
    RotateView(&cCamera.vView, fAngleY, 0, 1, 0);
    }

  6. #6
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    I'm not sure what is wrong with your code, it seems messy to me. I'm just going to tell you the order I did things, as I don't feel like debugging right now.

    1) get the amount the mouse position moved in X and y directions
    2) set back to middle
    3) convert to radians
    4) rotate vectors radians number of degrees about Y and Strafe

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. resizing OpenGL picture control in MFC window
    By stanlvw in forum Windows Programming
    Replies: 1
    Last Post: 03-19-2009, 04:21 PM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  4. opengl question. mouse location vs gluperspective
    By revelation437 in forum Game Programming
    Replies: 1
    Last Post: 10-19-2004, 08:18 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21