It is currently Sun Jul 23, 2017 2:49 am



 [ 3 posts ] 
 Help with code for centering aim with psmove 
Author Message
One Eyed Hopeful

Joined: Tue Jul 11, 2017 1:49 pm
Posts: 7
[EDIT: G0 TO THIRD POST]

I have found a code here to use the psmove as some sort of gun controller (it basically just controls the mouse) I'm using it for doom 3 fully possessed, it only uses the gyroscope, and it works pretty well. It does only activate when you hold the trigger button though, which is a good thing, since you have to repostion your gun now and then to get some good aiming going on.

My only problem is that I would want it to activate it when I click the trigger button not when holding it. So basically it would have to be some sort of toggle command.

this is the code

def update():
#define globals

#define constants
mag = 1000
dz = 0.005
i=0
j=0

#bind left mouse to cross button
#Right mouse to circle button
#Middle mouse to move
mouse.leftButton = joystick[j].getDown(14)
mouse.rightButton = joystick[j].getDown(13)
mouse.middleButton = joystick[j].getDown(19)

#Mouse movement using Gryoscope
# Only moves when the trigger is held down
mdX = -1 * filters.deadband(filters.delta(freePieIO[i].yaw),dz) * mag
mdY = -1 * filters.deadband(filters.delta(freePieIO[i].pitch),dz) * mag
if joystick[j].getDown(20):
mouse.deltaX = mdX
mouse.deltaY = mdY


if starting:
freePieIO[0].update += update

Now it does say joystick[j].getdown(20) for the trigger, but it does use the same command to activate the leftmouse button as well. The trigger (joystick[j].getdown(20)) uses some sort of 'if' statement here but I can't seem to figure out. As you can see i'm not a programmer but I do understand some basic principles though and I'm not an idiot, so if you could point in me the right direction I would be very happy.


Last edited by Commander89 on Thu Jul 13, 2017 3:37 pm, edited 3 times in total.



Tue Jul 11, 2017 2:06 pm
One Eyed Hopeful

Joined: Tue Jul 11, 2017 1:49 pm
Posts: 7
I figured it out, if anyone is interested here it is. Now it uses the move button to activate the move controller as the mouse and it's also a toggle button now.


def update():
#define globals

#define constants
mag = 1000
dz = 0.005
i=0
j=0

#bind left mouse to trigger button
#Right mouse to circle button
#Middle mouse to cross
#U key to move button and toggles move controller
mouse.leftButton = joystick[j].getDown(20)
mouse.rightButton = joystick[j].getDown(13)
mouse.middleButton = joystick[j].getDown(14)
keyboard.setKey(Key.U, joystick[j].getDown(19))

#Mouse movement using Gryoscope
# move button toggles move controller
mdX = -1 * filters.deadband(filters.delta(freePieIO[i].yaw),dz) * mag
mdY = -1 * filters.deadband(filters.delta(freePieIO[i].pitch),dz) * mag
if (enabled):
mouse.deltaX = mdX
mouse.deltaY = mdY


if starting:
enabled = False
freePieIO[0].update += update

toggle = keyboard.getPressed(Key.U)

if toggle:
enabled = not enabled


Tue Jul 11, 2017 4:36 pm
One Eyed Hopeful

Joined: Tue Jul 11, 2017 1:49 pm
Posts: 7
ok so this mouse aiming by psmove doesn't work as well as I hoped but then I thought of this.


When you aim at something you always look in that direction, you're not going to aim while just looking with your eyeballs, you're going to turn your head in the exact direction of the enemy, it's only the finer precision afterwards that you do with your eyeballs.

So I thought , if I could have a button that centers the crosshair/lasersight in the middle of my screen, this method could work quite well. The problem is that I cannot find a way to center the aim. I know how to center the mouse pointer with the setcursor command in freepie, but in doesn't pick up in the game, it does work in windows though.


I have looked into the command sendinput and also posted on the doom 3 fully possessed github if there wasn't any in game command that could center the aim. I'm not sure if this is actually possible, so any help would be very welcome.

This is the code I have now


def update():
#define globals

#define constants
mag = 1000
dz = 0.005
i=0
j=0

#bind left mouse to trigger button
#Right mouse to circle
#Middle mouse to triangle
#up arrow key to square
#down arrow key to cross
#B Key to ps button
#N key to select button
#Esc key to start button

mouse.leftButton = joystick[j].getDown(20)
mouse.rightButton = joystick[j].getDown(13)
mouse.middleButton = joystick[j].getDown(12)
keyboard.setKey(Key.UpArrow, joystick[j].getDown(15))
keyboard.setKey(Key.DownArrow, joystick[j].getDown(14))
keyboard.setKey(Key.B, joystick[j].getDown(16))
keyboard.setKey(Key.N, joystick[j].getDown(0))
keyboard.setKey(Key.Escape, joystick[j].getDown(3))

#Mouse movement using Gryoscope
# move button centers mouse cursor
mdX = -1 * filters.deadband(filters.delta(freePieIO[i].yaw),dz) * mag
mdY = -1 * filters.deadband(filters.delta(freePieIO[i].pitch),dz) * mag
mouse.deltaX = mdX
mouse.deltaY = mdY

if joystick[j].getDown(19):
import ctypes

ctypes.windll.user32.SetCursorPos(1000, 500)

if starting:
freePieIO[0].update += update


Wed Jul 12, 2017 8:45 pm
Display posts from previous:  Sort by  
   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by STSoftware.