Mouse moving

This is a discussion on Mouse moving within the Windows Programming forums, part of the Platform Specific Boards category; Ok, I have this game, and I want the camera to be controlled by the mouse. The problem is that ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    27

    Mouse moving

    Ok, I have this game, and I want the camera to be controlled by the mouse. The problem is that the cursor can only move so far... and when it hits the end of the screen, the user can't turn any more.

    How do I get around this problem, so I can turn in one direction as much as I want, irrespective of the position of the Windows cursor?

    Thanks!

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,652
    WM_MOUSEMOVE
    If you want to get mouse events no matter where the curson is, then use SetCapture().

    gg

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    27
    Doesn't seem to work....
    Code:
    int InitGL(GLvoid)										// All Setup For OpenGL Goes Here
    {
    	if (!LoadGLTextures())								// Jump To Texture Loading Routine
    	{
    		return FALSE;									// If Texture Didn't Load Return FALSE
    	}
    
    	glEnable(GL_TEXTURE_2D);							// Enable Texture Mapping
    	glShadeModel(GL_SMOOTH);							// Enable Smooth Shading
    	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);				// Black Background
    	glClearDepth(1.0f);									// Depth Buffer Setup
    	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing
    	glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do
    	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations
    
    	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);		// Setup The Ambient Light
    	glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);		// Setup The Diffuse Light
    	glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);	// Position The Light
    	glEnable(GL_LIGHT1);								// Enable Light One
    	BuildFont();
    	SetCapture(hWnd);
    	cam.Y=2.5f;
    	return TRUE;										// Initialization Went OK
    }
    Code:
    		case WM_MOUSEMOVE:
    		{
    			
    				mousePoints = MAKEPOINTS(lParam);
    				currentCam->rotY=(float)((mousePoints.x)/3);   //GET X AND Y MOUSE POSITIONS
    				if((mousePoints.y/3) < -90.0f)
    					currentCam->rotX=-89.0f;
    				else if((mousePoints.y/3) > 30.0f)
    					currentCam->rotX=29.0f;
    				else
    					currentCam->rotX= (float)((mousePoints.y)/3); //						
    
    			break;
    		}

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Check out the SetCapture( ) link above. It actually sends the WM_CAPTURECHANGED message.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Registered User
    Join Date
    Sep 2003
    Posts
    27
    Sorry, I'm not sure that I understand how this works. Could you explain it to me or give me some pseudo-code to work off of?

    Thanks so much!

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I looked up some sample code and found this:

    GetCursorPos(&mpos); // Get mouse position
    SetCursorPos(320,240); // Reset mouse position to centre so it never reaches the edge.

    // Use mouse position...
    heading += (float)(320 - mpos.x)/100 * 5;
    yrot = heading;
    lookupdown -= (float)(240 - mpos.y)/100 * 5;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving objects with mouse in 3D.
    By psychopath in forum Game Programming
    Replies: 15
    Last Post: 07-10-2011, 04:20 PM
  2. Moving mouse
    By Bill83 in forum Windows Programming
    Replies: 1
    Last Post: 04-02-2006, 08:58 AM
  3. mouse click coords and moving a rect
    By techrolla in forum Windows Programming
    Replies: 1
    Last Post: 03-07-2004, 08:49 PM
  4. Mouse moving
    By Sharky in forum Windows Programming
    Replies: 1
    Last Post: 08-28-2003, 05:46 AM
  5. Moving Mouse Pointer
    By loobian in forum Windows Programming
    Replies: 8
    Last Post: 10-16-2001, 03:45 PM

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