0
\$\begingroup\$

I am new to game development and I am trying to get the game input working. I have successfully got all the movement keys for walking/running/looking around working; however, I am having a terrible time with the mouse lol.

Basically, I am trying to move the camera with the mouse when the user holds the right mouse button down and drags. I want to rotate the camera in that direction. So dragging to the right rotates right, dragging right/down will rotate right/down, etc.. I do not want the cursor to stay in the middle of the screen (this is not a FPS). I want the cursor to stay in the location it was in when the user first right clicked.

I am guessing this is probably not nearly as complicated as I am making it but I cant seem to find anything that has helped thus far. I have found several tutorials/excerpts on it but I havent got mine working yet. Below is my code for the MouseMove event (C# - I am using SharpDX framework).

            if (Input.Mouse.IsRightMouseDown &&
                Input.Mouse.PositionHasChanged(new Vector2(mouseEventArgs.X, mouseEventArgs.Y)))
            {
                var deltaY = mouseEventArgs.Y - Input.Mouse.OriginalRightMousePosition.Y;
                var deltaX = mouseEventArgs.X - Input.Mouse.OriginalRightMousePosition.X;
                var angle = (float)Math.Atan2(deltaY, deltaX);

                Camera.RotationY -= (float)Math.Sin(angle) * Global.MouseRotationSpeed;
                Camera.RotationX -= (float)Math.Cos(angle) * Global.MouseRotationSpeed;

                Input.Mouse.ResetMousePositionToOriginal();
            }

I would appreciate any help/advice I can get!! :)

Thanks in advance!!!

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Is it otherwise working, but your cursor is the problem? The cursor is usually just a HUD overlay centered on the screen, so it may not know anything about your camera.

One solution might be to make the cursor an actual 3d object in the scene.

[EDIT] the targeting reticule is the correct term for the object in question.

A more complex solution would be to calculate the position of the reticule from your view frustum.

\$\endgroup\$
2
  • \$\begingroup\$ It was working except it was moving in unexpected directions.. I figured it out, my Sin/Cos were backwards. Needed to do Cos on RotationY and Sin on RotationX. Its working now, thank you for all your help!! Thanks for the help! \$\endgroup\$
    – spyter
    Commented Feb 7, 2014 at 20:27
  • \$\begingroup\$ No worries. If you have shooting linked to the reticule, you will want to check that it firing at the position expected. \$\endgroup\$
    – karmington
    Commented Feb 7, 2014 at 20:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .