-
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!
-
WM_MOUSEMOVE
If you want to get mouse events no matter where the curson is, then use SetCapture().
gg
-
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;
}
-
Check out the SetCapture( ) link above. It actually sends the WM_CAPTURECHANGED message.
-
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!
-
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;