Game Development Community

Mouse input and rotating about mouse cursor

by DavidFfrench · in Torque X 2D · 03/14/2007 (12:30 pm) · 11 replies

First off i would like to say that i am new to c#.

There is 3 things that i am trying to get done. They are:
(1) getting input from the mouse.
(2) Showing the mouse pointer as an aim.
(3) My charcter to always face where the mouse is pointed.

(1) mouse input
I understand how the keyboard in put works and i assumed that the mouse input would work the same but i can't seem to get it working. For the keyboard it is just "Keys.Left", so for mouse i assumed it would be "Mouse.LeftButton" but this doesnt work.

(2)showing mouse pointer
I am not sure how to do this at all

(3) Always facing the pointer
I dont know how to do this wither, this is the most important.


Thanks in advance for the help,
David.

About the author

Recent Threads

  • Networking

  • #1
    03/14/2007 (1:46 pm)
    1) there is mouse support in the input manager which would be something along the lines of mouse.leftbutton and such. You said it didn't work, but it is there. I'll look tonight at the exact code needed to do this.

    2) this.IsMouseVisible = true; this.cursor = Cursors.WaitCursor;

    3) www.riemers.net/eng/Tutorials/XNA/Csharp/Series4/Mouse_camera.php

    There probably is a way to attach the TX camera to the mouse movement fairly easily, and I'll try to take a look over the next day or two unless someone else can answer you first.

    www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

    www.mmogamedev.info/images/imgdc_ad1.gif
    #2
    03/14/2007 (4:34 pm)
    Thanks for the reply, much appreciated.

    For the mouse input, on the msdn website, it has a list of the keys that can be used.
    msdn2.microsoft.com/en-us/library/microsoft.xna.framework.input.keys.aspx
    But for the mouse page they dont have a list.
    msdn2.microsoft.com/en-us/library/system.windows.input.mouse.getposition.aspx

    For my 3rd question, is it that the camera is attached to the character and by the camera moving the character will move aswell? My game is just a basic top down view shooter. Im looking at the tuorial link now. Thanks for that.
    #3
    03/14/2007 (9:46 pm)
    Here's how you do mouse assignments using input manager in TX:

    int mouseID = InputManager.Instance.FindDevice("mouse");
                inputMap.BindMove(mouseID, (int)XMouseDevice.MouseObjects.LeftButton, 0);

    Use XMouseDevice.MouseObjects.Whatever for the various options.

    www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

    www.mmogamedev.info/images/imgdc_ad1.gif
    #4
    03/15/2007 (9:26 am)
    As a slight clarification, that allows you to receive mouse input as Moves the same way as keyboard and gamepad. I.e. if you move the mouse left, then move.Sticks[0].X will be negative. So, it doesn't automatically give you (x,y)-coordinates of the mouse cursor, but you'll have to keep track of that yourself. For example if you want to have own cursor:

    mouseCursorBitmap.Position += new Vector2(move.Sticks[0].X, move.Sticks[0].Y) * _mouseMoveSpeed;

    ...And for question 3), you can (assuming the idea was to rotate your character to point towards that mouse cursor):

    yourCharacter.Rotation = T2DVectorUtil.AngleFromTarget(yourCharacter.Position, mouseCursorBitmap.Position);
    #5
    03/15/2007 (9:58 am)
    Quote:
    For my 3rd question, is it that the camera is attached to the character and by the camera moving the character will move aswell?

    Not by default, but it's relatively trivial. Personally, I did this in the _onRegister() of my movement component assigned to my player object, but it can be done elsewhere--just align the object castings appropriately:

    (T2DSceneGraph.Instance.Camera as T2DSceneCamera).Mount((this.Owner as T2DSceneObject), "", false);

    Where in my specific example, "this" was my movement component.
    #6
    03/15/2007 (10:35 am)
    Hmm.. After having actually tried it, I have to say that way is probably not usable :( It works in theory, but has two major drawbacks:

    - move.Sticks[N].X/Y only gets values -1,0,1, which results in axle/diagonal movement (might be a "beta feature")
    - doesn't actually capture the mouse, i.e. the real windows mouse moves independently. While in windowed mode, pressing the buttons easily causes focus to change to other applications.

    But you can still use the XNA mouse methods like in the tutorial link. You'll just have convert between screen and world coordinates. It might also be wise to wait and see if mouse support will be enhanced in the 1.0 release.
    #7
    03/15/2007 (12:11 pm)
    Thanks for the input guys. That is exactly what i want to do matias. Will your roatating code still work if i use the mouse input that jonathon posted?

    Any idea when 1.0 is released? my deadline is in a month though.
    #8
    03/15/2007 (1:02 pm)
    What I posted is simply for binding movements to mouse movements. You can also use BindCommand and BindAction in place of BindMove.

    www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

    www.mmogamedev.info/images/imgdc_ad1.gif
    #9
    03/16/2007 (12:11 am)
    I'm not sure if I understood your comments correctly, but the problem that I had was that binding the mouse to TorqueX input management doesn't capture the Windows mouse. The result is that when the Windows mouse cursor reaches side of the screen, it stops generating the move events from that direction.

    In my mind, there would be two options:
    a) Use windows mouse in "the standard way" with XNA/.NET-libraries. You'll have to solve how you convert between screen and world coordinates (depends on whether you have static/moving/multiple cameras).
    b) Capture/disable windows mouse and handle the mouse cursor your self (similarly as in my example). You'll probably need to capture TorqueMouseEvent (there's an example in the TorqueX overview-documentation).

    With your schedule waiting for 1.0 might be risky. It should be "real soon now", but I'm guessing it's more important for GG to get most of the bugs worked out than lose a couple of weeks :)

    Matias
    #10
    03/16/2007 (6:10 am)
    Let me get this straight. When you are in windowed mode using the TX mouse events and you get to the side of the TX screen, the events stop firing? This sounds like the way it should be, not a flaw. If I'm in windowed mode, I want my windows mouse to return as soon as I 'leave' the windowed game.

    www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

    www.mmogamedev.info/images/imgdc_ad1.gif
    #11
    03/16/2007 (2:57 pm)
    Actually the mouse cursor/events are not tied to TX screen, but the whole desktop. Whether this is a flaw or not kind of depends on how you want to use a mouse. You can think of it as a pointer device positioned over a single screen pixel. Or you can think of it as a sensor about user hand movements (think trackball-devices). In the former case you're just interested about the position of the cursor (over your application). In the latter case you would expect to get move events whenever the user moves the mouse (like in FPS-games). For me the TX inputMap and Stick.X/Y would be closer to the latter, but I guess it always depends on the application.

    But the moves being always digital -1,0,1 even though mapped as an analog input is kind of a flaw. Though it might just be a problem with keyvalues of the input device.