-
Notifications
You must be signed in to change notification settings - Fork 20
Joysticks, PPJoy, and Kinect
Joysticks, Game pads, Steering Wheels, and most other Direct Input devices that aren’t keyboards or mice, are considered to be Joysticks by GlovePIE.
If you want to read from a joystick you can use the Joystick object, but if you want to write to it, you need to use the PPJoy object.
Most fields of the Joystick are read-only, but the two joystick fields which you can set are the Vibration1 and Vibration2 fields. These are the force feedback on the two axes, and can be set to any value between -1 and 1. 0 is no effect. In this case the Joystick is acting as an output device. On a Gamepad, Vibration1 will be rumble, and Vibration2 will be buzz. On a real Joystick they will push the stick in a direction (I think).
The Joystick buttons are numbered 1 to 128. Most joysticks won’t have that many buttons though. You can read them with:
Joystick.Button1 to Joystick.Button128
You can tell how many axes the joystick has with the Joystick.NumberOfAxes value.
Each joystick axis has a value between -1 and 1.
The joystick axes are referred to as follows:
x = sideways position. -1 = left, 0 = centre, 1 = right y = forwards/backwards position -1 = forwards, 1 = backwards z = Right Analog stick forwards/backwards -1 = forwards, 1 = backwards roll = joystick twist, or right analog stick left/right -1 = left, 1 = right pitch = not usually used yaw = not usually used slider = throttle rudder control, -1 = forwards (full speed), 1 = backwards (no speed) dial = some other dial
vx, vy, vz, vroll, vpitch, vyaw, vslider, vdial = Extra axes which DirectInput supports, supposedly for velocity (which seems kind of redundant), but could be anything. Not normally used. They don’t tell you the velocity on a normal joystick.
You can also read the axes as a vector:
Pos = [x, y, z]
Pos2d = [x, y]
Pos2d2 = [roll, z]
(right-analog stick)
Velocity = [vx, vy, vz]
These are either those little hat switches you get on the top of some joysticks, or they are the D-Pad on a Game Pad with analog sticks when it is in analog mode.
There can be up to 4 POV Hats per joystick, numbered Pov1, Pov2, Pov3 and Pov4.
The number of POV hats the joystick has is given by Joystick.NumberOfPOVs.
POV Hats can be either centred, or they can be pushed out in some direction. You can’t tell how far in that direction they are pushed. Analog POV hats can be pushed in any angle. Digital ones only support 8 different angles.
To tell in PIE whether Pov1 is centred, read: Joystick.Pov1Center. It will be either true or false. If it is true then you can read Joystick.Pov1 and it will be the angle in degrees (or you can convert it to other units if you want). If it is centred then Joystick.Pov1 will be -1.
Another way of reading the POV hat is to use the values Pov1Up, Pov1Down, Pov1Left and Pov1Right. For example if the joystick is pushed to the front-left corner then Pov1Up and Pov1Left will both be true and the others will be false. For analog POV hats it only has to be closer to that direction than to any other.
The final way of reading the POV hat is to use the values Pov1x and Pov1y. They work just like the x and y values of the joystick, except the values it can return are more restrictive (either both values are 0, or one of them is on the edge).
There are other joystick fields with information about the joystick. You can look most of them up in the DirectInput documentation. They are:
Alias: true or false Attached: true or false Deadband: true or false DeviceType: number DeviceSubType: number Emulated: true or false FFAttack FFDriverVersion FFFade FFSamplePeriod FirmwareRevision ForceFeedback ForceFeedbackGuid HardwareRevision HID Hidden HidUsage, HidUsagePage InstanceGuid IsFirstPerson, IsFlight, IsGamePad, IsJoystick, IsLimited, IsVirtualJoystick, IsWheel Name: The name of that individual joystick Phantom: true or false PolledDataFormat PolledDevice PosNegCoefficients PosNegSaturation PPJoyNumber ProductGuid ProductName: The brand of the joystick Saturation StartDelay
By default “Joy” or “Joystick” refers to “Joystick1”. You can also specify a joystick by number, eg. “Joystick1” or “Joystick2”.
But you can also specify joysticks by type. Note that that only works if the joystick reports its type correctly, which lots of them don’t. My Game Pad reports itself as a joystick for example.
Joystick.GamePad1 refers to the first gamepad. Joystick.GamePad2 refers to the second gamepad.
Joystick.Joystick1 refers to the first joystick that actually is a joystick.
Joystick.Wheel1 refers to the first wheel.
Joystick.Flight1 refers to the first flight stick.
Joystick.FirstPerson1 refers to the first Virtual Reality DirectInput device (p5 gloves don’t count as DirectInput devices).
Joystick.PPJoy1 refers to PPJoy virtual joystick 1.
Joystick.NotPPJoy1 or Joystick.Real1 refers to the first joystick that is NOT a PPJoy Virtual Joystick.
The number after the type is optional. You then put the item after, like this:
debug = joystick.gamepad1.x
or like this:
debug = joystick.wheel.x
This is useful if you have different types of joysticks (that report their type correctly).
(Note from Ravbug: Xbox 360 and One controllers are supported in most programs nowadays via XInput or DirectInput. You probably don't need PPJoy. Also, a lot of this information is outdated)
If you want to emulate a joystick (except for Xbox 360 controllers) with GlovePIE, you need to download and install PPJoy, preferably version 0.83 or later.
Version 0.83 and below are clean, but there have been (possibly false) reports of a Trojan in version 0.84. I haven’t been able to determine whether it is clean or not.
Installing PPJoy 0.83 on Vista is possible, but I think you need to run the PPJoy control panel as administrator by right clicking on it.
After installing, you then need to configure PPJoy to add a virtual joystick or two. Go to “Parallel Port Joysticks” in Control Panel (or the CP-Settings menu of GlovePIE), and choose “Add”. Then under “Parallel Port” choose “Virtual joystick” and under “Controller Number” choose a number between 1 and 16, which will be the number of the Virtual Joystick. It’s best to start with 1.
Then you need to create a custom mapping for the virtual joystick. Choose the number of Axes (I recommend 8), the number of buttons (I recommend 32), and the number of POV hats (I recommend 2). Then you need to set which axes you want the 8 available axes to be. Then click next and choose which analog axes you want to correspond to those axes. The analog values are how you set that axis in PIE, just choose any numbers here, but remember them later. I recommend using analog 0 to analog 7. Then click next.
Then choose which digital values you want to correspond to the first 16 buttons. I recommend 0 to 15. Then click next and set the next 16. Then set the two POV hats.
Once you have a Virtual Joystick set up in PPJoy, you can set its analog and digital values with PIE:
PPJoy1.analog0 = 0.5
PPJoy1.digital0 = true
Analog values can be between -1 and 1. Digital values can be either true or false.
If you want to set “PPJoy Virtual Joystick 2” then set the values for PPJoy2.
“PPJoy” by itself without a number refers to “PPJoy Virtual Joystick 1”.
If the analog corresponds to an axis, then 0 is centred and -1 and 1 are the two extremes.
But if the analog corresponds to a a POV hat switch, then -1 corresponds to pushed at an angle of 0 degrees (forwards). -0.5 corresponds to 90 degrees (right). 0 corresponds to 180 degrees (backwards), 0.5 corresponds to 270 degrees (left) and 1 corresponds to centred.
Games which let you choose which joystick you use will need to be set to the appropriate PPJoy Virtual Joystick in the game. Other games which just use the default Joystick will require you to go to the Control Panel joystick settings (Use GlovePIE’s CP-Settings menu to get there quickly), and change the default joystick there.
If you want to control the game with a real joystick and just add some scripted actions to it, you will set the game or control panel to the virtual joystick and assign values from the real joystick to the PPJoy fields.
(Note from Ravbug: Only the Xbox 360 Kinect sensor is supported. Carl Kenner stopped working on this program before the Xbox One was released.)
GlovePIE now supports the Microsoft Kinect (formerly known as Project Natal). You need to buy the standalone Kinect, not the Kinect+Xbox bundle. If you buy the Kinect in a bundle, you will not receive the power cord/USB adapter that you need to plug it in to your computer. If you bought the Kinect in a bundle, you will need to buy a Kinect adapter separately from Microsoft.
Currently there are four different unofficial drivers available for Kinect on Windows:
- Official Microsoft Kinect for Windows SDK, from http://kinectforwindows.org/
- Libusb-win32 based drivers for OpenKinect’s “open source” (actually closed to people such as me) “libfreenect”, from http://www.openkinect.org
- CLNUI drivers by the man who made the (not free) Playstation Eye drivers, from http://codelaboratories.com/nui/
- OpenNI drivers by the fascist Israeli company that made the depth sensor chip used in Kinect, from http://www.openni.org
The drivers are completely incompatible with each other, and software must be written for a specific Kinect driver. Some programs require one driver, others require a different driver.
GlovePIE currently only works with the Kinect for Windows SDK.
While the Kinect is plugged in, you will need to use Device Manager to manually uninstall any other Kinect drivers (eg. “Xbox NUI …”), and choose the option to delete the driver files.
Then you will need to install the Kinect for Windows SDK.
GlovePIE supports multiple Kinects, but Kinect1 is the only one used for skeleton tracking. The other Kinects can really only read and set the Kinect.SmoothPitch (to move the camera) and read Kinect.y to get the height of the kinect's camera above the floor in metres. Kinect.SmoothPitch only returns correct angles between -60 and 60 degrees, it works like other SmoothPitch values in GlovePIE in that it is relative to gravity and treats all accelerations as though they were rotations. The Kinect has accelerometers but they can't be read in any other way with the Kinect for Windows SDK. Setting SmoothPitch can only move the camera to the base's angle +/- 27 degrees, so it may not be able to reach the desired angle. You can also read Kinect.Exists, Kinect.name, and Kinect.count.
One Kinect can support up to 6 players. In GlovePIE you refer to a player as player1.whatever, player2.whatever, etc. Or just player.whatever for the default player. Full skeleton tracking only works for players 1 and 2 though.
Skeleton calibration happens automatically in the Kinect for Windows SDK. You don't need the Psi Pose.
Before the Kinect has been calibrated, it tries to separate the depth map into blobs, with one blob for each player. You need to move around a bit at the start, so it can tell you are not part of the background. Sometimes it makes a mistake and assigns a blob to an inanimate object.
player.exists
: true if the Kinect has recognised someone as this blob yet. If this is false, it means either you need to move around some more, or you are actually assigned to player2 or player3 by mistake.
player.count
: number of players that are currently being tracked
player.userid
: which internal SDK user number (1-6) is assigned to this player
player.trackingid
: which internal SDK tracking ID is assigned to this player, guaranteed to change whenever a different human becomes assigned to that player, (or the user goes out of view and comes back).
The following values are available even before skeleton calibration:
player.x
: how far to the right (in metres) this player is relative to the center of the Kinect’s camera.
player.y
: how high up (in metres) this player is relative to the center of the Kinect’s camera.
player.z
: how far away (in metres) this player is relative to the center of the Kinect’s camera.
player.pos
, player.COM: the above information but as a vector
If Kinect can see, and has recognised the floor, then the following values will work, even before skeleton calibration:
player.floor.confidence
: 0 if it hasn’t recognised the floor, 1 if it has. Values between 0 and 1 may be possible later. This needs to be more than 0 for the other floor values to work.
player.floor.normal
: a vector pointing up, at right angles to the floor. If the camera is at an angle,
player.floor.pos
: point on the floor under the player (as a vector)
player.floor.rotmat
: a rotation matrix specifying the rotation of the floor, relative to the camera. (even though it’s probably the camera that was tilted, not the floor).
player.floor.y
: y coordinate of floor under player
Calibration and tracking status:
player.calibrating
: always false for now
player.calibrated
: true if the player’s skeleton has finished being calibrated, always true
player.tracking
: true if the player’s skeleton is being tracked (usually starts straight after finishing calibration)
After skeleton calibration, the following values are available for each player:
Player.SteeringAngle
: The angle to the right, in degrees, you are turning an imaginary steeringwheel held in your two hands. As seen in JoyRide, Forza 3, Burnout Paradise, and the old Project Natal ads. 0 means not turning. Currently turning more than ±180° is not supported. It might not work with props. It doesn’t check whether or not you are actually holding your hands like a steering wheel. See also Wiimote.SteeringAngle
, and Sixaxis.SteeringAngle
.
Player.ShoulderYaw
: How far to the right, in degrees, the top of your body is turned relative to the camera. See also player.head.yaw.
Player.HipYaw
: How far to the right, in degrees, your hips are turned relative to the camera.
Player.FeetYaw
: This isn’t necessarily the way your feet are pointing, it’s more the the angle of your stance based on the position of your left foot relative to your right foot.
Player.leanX
: how far to the right you are leaning, in degrees
Player.leanY
: how far backward you are leaning, in degrees
These values are for people who are used to FAAST key bindings:
player.lean_left
: how far in degrees they are leaning left. 0 if leaning right.
player.lean_right
: how far in degrees they are leaning right. 0 if leaning left.
player.lean_forwards
(or player.lean_forward
): how far in degrees they are leaning forward.
player.lean_backwards
(or player.lean_backward
or player.lean_back
): how far in degrees they are leaning backwards.
Player.left_arm_forwards
(or player.left_arm_forward
): how far in front of your shoulder your left hand is (in inches). In front is relative to the camera, not relative to your body. This will be negative if your arm is back (since FAAST doesn’t provide any value for that).
Player.right_arm_forwards
(or player.right_arm_forward
): how far in front of your shoulder your right hand is (in inches). In front is relative to the camera, not relative to your body. This will be negative if your arm is back (since FAAST doesn’t provide any value for that).
Player.left_arm_out
: how far to the left of your shoulder your left hand is, in inches.
Player.left_arm_across
: how far to the right, across your body, your left hand is, in inches. This is the opposite of left_arm_out.
Player.right_arm_out
: how far to the right of your shoulder your right hand is, in inches.
Player.right_arm_across
: how far to the left, across your body, your right hand is, in inches. This is the opposite of right_arm_out.
Player.left_arm_up
: how far above your shoulder your left hand is, in inches.
Player.right_arm_up
: how far above your shoulder your right hand is, in inches.
Player.left_arm_down
: how far below your shoulder your left hand is, in inches.
Player.right_arm_down
: how far below your shoulder your right hand is, in inches.
Player.left_arm_x
: how far to the right of your left shoulder your left hand is, or negative if it is to the left, in inches.
Player.right_arm_x
: how far to the right of your right shoulder your right hand is, or negative if it is to the left, in inches.
Player.left_arm_y
: how far above your left shoulder your left hand is, or negative if it is below, in inches.
Player.right_arm_y
: how far above your right shoulder your right hand is, or negative if it is below, in inches.
Player.left_foot_forwards
: how far in front of your left hip your left foot is, in inches. Forwards is relative to the camera, not which way you are facing. It will be 0 if your foot is back.
Player.left_foot_backwards
: how behind your left hip your left foot is, in inches. Backwards is relative to the camera, not which way you are facing. It will be 0 if your foot is forward.
Player.left_foot_sideways
: how far to the left of your left hip your left foot is, in inches. It will be negative if your left foot is to the right.
Player.left_foot_up
: how high your left foot is above your right foot, in inches. Note this is above your other foot, not above the floor. See also: player.leftfoot
.HeightAboveFloor
.
Player.left_foot_z
: how far in front of your left hip your left foot is in inches, or negative if behind.
Player.right_foot_forwards
: how far in front of your right hip your right foot is, in inches. Forwards is relative to the camera, not which way you are facing. It will be 0 if your foot is back.
Player.right_foot_backwards
: how behind your right hip your right foot is, in inches. Backwards is relative to the camera, not which way you are facing. It will be 0 if your foot is forward.
Player.right_foot_sideways
: how far to the right of your right hip your right foot is, in inches. It will be negative if your right foot is to the left.
Player.right_foot_up
: how high your right foot is above your left foot, in inches. Note this is above your other foot, not above the floor. See also: player.rightfoot.HeightAboveFloor.
Player.right_foot_z
: how far in front of your right hip your right foot is in inches, or negative if behind.
After skeleton calibration, the following body parts are available for each player:
player.head player.neck player.leftshoulder player.rightshoulder player.torso player.leftelbow player.rightelbow player.leftwrist player.rightwrist player.lefthand player.righthand player.lefthip player.righthip player.hipcenter player.leftknee player.rightknee player.leftankle player.rightankle player.leftfoot player.rightfoot
For each part, the following information is available:
player.head.x
: how far to the right (in metres) this part is relative to the center of the Kinect’s camera.
player.head.y
: how far up (in metres) this part is relative to the center of the Kinect’s camera.
player.head.z
: how far away (in metres) this part is relative to the center of the Kinect’s camera.
player.head.pos
: the above information but as a vector
Some parts have extra information:
player.head.yaw
: how many degrees to the right the part is turned (relative to the camera). This is just an estimate based on the positions of the other joints. For example it can only estimate head yaw based on the angle of your shoulders, it doesn’t check which way your nose is pointing. Only head, neck, leftshoulder, rightshoulder, lefthip, righthip, and hipcenter have yaw, and it is the same as one of the yaw values above.
Player.leftfoot.HeightAboveFloor: How many metres above the floor the foot is. Unlike all the previous values, this takes into account camera tilt, and really means vertically above. It will never be less than 0 (even if the floor has a hole in it). It’s not very accurate. If Kinect can’t see, or hasn’t recognised, the floor, then this will actually be the height above the right foot.
Player.leftfoot.UpSpeed
: How fast (in metres per second) the foot is moving up (negative means moving down).
Player.rightfoot.HeightAboveFloor
: same as above, but for the right foot.
Player.rightfoot.UpSpee
d: same as above, but for the right foot.