Mouse emulating joystick challenge

Blitz3D Forums/Blitz3D Programming/Mouse emulating joystick challenge

Cancerboy(Posted 2006) [#1]
Hey guys,

I am coding in B+ but this problem could be solved by B3D users just as easily I am sure. I am trying to come up with reliable code to get the mouse to emulate a digital 4-way joystick.

I have tried various methods to read the mouse speed with the MouseXSpeed/MouseYSpeed commands. This works okay until the mouse pointer hits the extent of the screen and then you can no longer move in that direction. Using a forced MoveMouse command to re-centre makes MouseSpeed think the user has quickly moved the mouse. and messes the control all up.

I challenge you to come up with a method to get solid digital movement with the mouse. If you do I will be forever greatful! Thanks.


Chroma(Posted 2006) [#2]
The CurveValue function in the archives is what you're after. I believe Halo wrote it a long time ago.


b32(Posted 2006) [#3]
The mousexspeed() and mouseyspeed() should be called only once a loop and after it, you can use MoveMouse 400, 300.
This will prevent the mouse from reaching the screen border.
What is it you want it to do exactly ? A joystick falls back into it's centre position when you let it go. The mouse cant detect that. You should either simulate this using the mousebutton or accept that the 'joystick' will stay in it's current position when you let it go.


Cancerboy(Posted 2006) [#4]
I am making a frogger game and I am trying to emulate joystick movement on the mouse. The reason for this is I am trying to make the basic 4 directional control work with head tracking software for people who aren't capable of using traditional control devices.

Here is what sort of works (without any sensitivity control added). Basically I am checking the current speed of X and Y and fidning out which is greater (to eliminate moving the joystick in 2 directions at once), then I am just checking to see if the mouse has moved in a direction. I reset all previous directions set before I do the new test. This works but needs sensitivity controls and if the mouse pointer hits the edge of the screen then it stops the control from working:

; check mouse
cur_mouse_x = MouseXSpeed()
cur_mouse_y = MouseYSpeed()

;reset previous directions
mouse_left = 0
mouse_right = 0
mouse_up = 0
mouse_down = 0

;check if up/down or side movement is greater
If Abs(cur_mouse_x) > Abs(cur_mouse_y)

If cur_mouse_x < -1 Then mouse_left = 1
If cur_mouse_x > 1 Then mouse_right = 1
Else

If cur_mouse_y < -1 Then mouse_up = 1
If cur_mouse_y > 1 Then mouse_down = 1

End If


b32(Posted 2006) [#5]
I still have trouble understanding what you want to do exactly, but I hope this code helps a bit:



Cancerboy(Posted 2006) [#6]
I am trying to use the mouse to emulate a joystick. If I move the mouse left then my character moves left etc.


b32(Posted 2006) [#7]
Ah, this then?



Chroma(Posted 2006) [#8]
Ribbit!


Cancerboy(Posted 2006) [#9]
Thanks for the code guys. Here is a version of my movement using bram32's technique.

http://www.crushpuppy.com/link/frog_mouse.zip

Works fairly reliable and definately solves the issues of the mouse pointer. Now I just need to figure out how to tame down how sensitive the mouse movement is. You can move the frog with the keyboard direction arrows, the d-pad (hat) on a gamepad or left analog stick on a gamepad. Moving the frog with the keyboard or gamepad should give you an idea of how the frog is intended to move.


b32(Posted 2006) [#10]
Divide dirX and dirY ie. by ten:
dirX = (MouseX() - 400) * 0.1
dirY = (MouseY() - 300) * 0.1


Cancerboy(Posted 2006) [#11]
Brilliant. Thank you. That is exactly what I was looking for.

To make it more or less sensitive I assume I would adjust 0.1 up or down a fraction? Thanks again!


b32(Posted 2006) [#12]
no problem! indeed: adjust the 0.1 for that


Cancerboy(Posted 2006) [#13]
Hey Bram,

Not sure if your listed email is active... I sent you an email at:

bramdenhond@...


b32(Posted 2006) [#14]
Okay didn't see it yet, but I've received it. I'm taking a look into it now and get back to you asap.


Cancerboy(Posted 2006) [#15]
Thanks!