Maus bei First Person Camera



  • Hi 🙂
    ich möchte eine First Person Camera wie man sie aus Ego Shootern kennt programmieren. Das eigentliche Problem liegt an der Rotation der Kamera, wenn man die Maus bewegt.
    Hier ist mein WM_MOUSEMOVE:

    case WM_MOUSEMOVE:
    		 if(shooty.currentGS == GS_GAME)
    		 {
    			 xMouse = GET_X_LPARAM(lParam); 
    			 yMouse = GET_Y_LPARAM(lParam); 
    
    			 if(xMouse - oldxMouse < 0)
    				 camera->Yaw(-cameraRotationSpeed);
    			 else if(xMouse - oldxMouse > 0)
    				 camera->Yaw(cameraRotationSpeed);
    			 if(yMouse - oldyMouse < 0)
    				 camera->Pitch(-cameraRotationSpeed);
    			 else if(yMouse - oldyMouse > 0)
    				 camera->Pitch(cameraRotationSpeed);
    
    			 oldxMouse = xMouse;
    			 oldyMouse = yMouse;
    			 POINT pt;
    			 pt.x = configDialog.GetResolutionX() / 2;
    			 pt.y = configDialog.GetResolutionY() / 2;
    			 ClientToScreen(hwnd, &pt);
    			 SetCursorPos(pt.x, pt.y);
    		 }
    		 return 0;
    

    Ohne SetCursorPos klappt es zwar ganz gut, aber natürlich nur so lange, wie die Maus noch im Fenster ist. Also muss ich die Maus immer im Fenster bzw. in der Mitte behalten. Das habe ich auch versucht mit SetCursorPos, aber leider funktioniert das ganze nicht mehr mit SetCursorPos. Das liegt wohl daran, dass SetCursorPos auch MOUSEMOVE Nachrichten abschickt und dann die Rotation nicht mehr klappt. Bin mir aber nicht ganz sicher. Weiß es jemand?



  • Servus,

    wieso kompliziert, wenn es auch einfach geht 🙂

    setzte doch die Maus als erstes in die Mitte und lege deinen Point als Variable, die sich in der Klasse befindet, ab. Ändert sich die Fenstergröße / -position --> Änderung des Points.

    In den if-Abfragen prüfst du, ob die Koordinaten kleiner / größer als der Point sind. Danach wieder die Maus auf den Mittelpunkt setzen.

    Zu deiner Frage. Ich würde stark davon ausgehen, dass SetCursorPos ein Move-Event auslösst. Achja, Events werden ohne Kontrolle gefeuert!



  • Meinst du so?

    SetCursorPos(shooty.pt.x, shooty.pt.y);
    			 xMouse = GET_X_LPARAM(lParam); 
    			 yMouse = GET_Y_LPARAM(lParam); 
    
    			 if(xMouse - oldxMouse < 0)
    				 camera->Yaw(-cameraRotationSpeed);
    			 else if(xMouse - oldxMouse > 0)
    				 camera->Yaw(cameraRotationSpeed);
    			 if(yMouse - oldyMouse < 0)
    				 camera->Pitch(-cameraRotationSpeed);
    			 else if(yMouse - oldyMouse > 0)
    				 camera->Pitch(cameraRotationSpeed);
    
    			 oldxMouse = xMouse;
    			 oldyMouse = yMouse;
    			 shooty.pt.x = configDialog.GetResolutionX() / 2;
    			 shooty.pt.y = configDialog.GetResolutionY() / 2;
    			 ClientToScreen(hwnd, &shooty.pt);
    

    das geht leider auch nicht


Anmelden zum Antworten