Introduction: DIY Motion Control Gaming

About: Electrical Engineer

Let's talk for a moment about what we're getting into with this project.The main idea is to create a system that enables the user to have a more immersive gaming experience with the use of real-time motion controls. Now as we get further into this project, you'll see that this system has so many more applications than just gaming (for example when finished, the system could easily be used as a means of control for someone that has limited mobility). As I walk you through the steps to replicate my system, I will explain everything as thoroughly as I can in as much detail as possible so that you are not only replicating or improving, but building on your knowledge base and hopefully developing some new skills! So, without further ado, let's get started!

Step 1: Here's What You're Going to Need

Throughout this project, I will be explaining a variety of different options for building this system. I have outlined them below along with their respective parts lists. Links to the products and their prices will all be included.

*4DOF - 4 Degrees of Freedom

*6DOF - 6 Degrees of Freedom

*********************************************************************************************************************************

Option 1 (4DOF system using Wii sensor bar):

This will be the main focus of this instructable as it is the easiest to build and doesn't require too much extra knowledge of soldering or circuitry. If you want a system that works perfectly well and you can set up with minimal resources, this is the one you want. Keep in mind if you want to use one of the other options, I will be very clear in why everything is built in the way that it is and how it functions.

PROS-Simplest version, most thoroughly explained in this instructable

CONS-May be pricier if you don't already own some of the hardware

Option 1 Parts List

SOFTWARE

Glovepie - FREE

HARDWARE

Wii Sensor Bar - $7.99 *You can either power it by plugging it into a wii or with about 5-8v input

Wii Remote - $16.99

GoPro Head Mount - $7.49 (OPTIONAL)

*********************************************************************************************************************************

Option 2 (4DOF system using DIY sensor bar):

This option is basically the same as the first, however you will be creating your own (with in-depth instruction) sensor bar instead of using a wii sensor bar.

PROS-Same as option 1 in terms of code

CONS-Requires a bit more time/skill *but may be a great learning experience!

Option 2 Parts List

SOFTWARE

Glovepie - FREE

HARDWARE

PCB Board - $2.79 for 5

1kΩ Resistor

~400Ω Resistor

2x Infrared LED

Male USB Cable (we will only be using this as a 5V source so it doesn't matter what the opposite connection type is) - $4.89

Wii Remote - $16.99

GoPro Head Mount - $7.49 (OPTIONAL)

*********************************************************************************************************************************

Option 3 (6DOF system using DIY sensor bar):

This option is much more complicated and requires a bit more knowledge of coding to complete successfully. I would not recommend attempting this version unless you feel confident in your abilities to understand the inner-workings of the system and will be able to develop a system based off of a simplified version.

PROS-Provides a greater amount of control over the system with more variables to observe and act on

CONS-Requires even more time/skill/insight but still provides a great learning experience!

Option 3 Parts List

SOFTWARE

Glovepie - FREE

HARDWARE

PCB Board - $2.79 for 5

33Ω Resistor (or resistor values equivalent to approximately 30Ω)- can be found for pennies at your local electronics store

4x Infrared LED

Male USB Cable (we will only be using this as a 5V source so it doesn't matter what the opposite connection type is) - $4.89

Wii Remote - $16.99

GoPro Head Mount - $7.49 (OPTIONAL)

Step 2: Bluetooth

This step is important (which is why I'm including it earlier than I should in this intructable) because if you can't get the Wiimote to connect and interact with your computer, this whole project isn't going to work for you. I'll walk you through the different ways you can connect the Wiimote via bluetooth to your windows computer.

If you have Windows 10, which I'll assume most people do, it's a bit annoying to connect the Wiimote but I have found a 100% successful way of troubleshooting and making everything connect. If you have an earlier version of Windows, connecting the Wiimote should be a breeze.

The fist step is to open your Bluetooth settings window. You can do this by either typing 'bluetooth' into the search bar or by navigating to it through the control panel.

To set the Wiimote to sync mode, open up the back cover and press the red Sync button (It is important to start the sync like this). The Wiimote LEDs should start to flash. Make sure Bluetooth on your computer is turned on and begin to search for devices. The device you are looking for should be called something similar to 'Nintendo RVL-CNT-01'. If you are NOT on Windows 10, go ahead and click to connect. There is no pin to connect to the Wiimote so just leave that space blank.

If you are on Windows 10, there is no option to connect to a device without a pairing pin so here's what you need to do:

Navigate to the bottom right corner of your screen and click the up arrow to bring up a box of background programs. You should see the Bluetooth icon here. Right click the icon and select 'Join a Personal Area Network'. A window should pop up in the control panel that has connected devices listed. Go ahead and click 'Add a Device' in the top left corner. Select the Wiimote device and click Next twice. That's it you should be connected. If you couldn't see the device listed or were unable to connect, see the troubleshooting section down below.

Troubleshooting

PROBLEM: Can't see the device in the list of available Bluetooth devices

SOLUTION: Make sure the lights on the Wiimote are still flashing. If this doesn't work and you are on Windows 10, go ahead and click 'Add a Bluetooth or other device' button in your main Bluetooth settings, wait for the popup to find the device, close the window, and add the device from the Personal Area Network window.

PROBLEM: Paired with the Wiimote previously and can see it in the Bluetooth device list as Paired but the device will not connect when I select it.

SOLUTION: Click on the device, click 'Remove Device', and start from the beginning of this step.

Step 3: Creating Your Sensor Bar

If you have chosen to do option 1 for this project (which I highly recommend), you can go to the next step. If you've chosen options 2 or 3, get out your soldering iron, hot glue gun, and other supplies and get ready to go!

A 33 (or near enough) Ohm resistor should be sufficient to power your infrared LEDs in series without too much current passing through the diodes. Another option is to use a 1k Ohm and 430 Ohm resistor as a voltage divider to power the diodes. For more information on Voltage Dividers and how to use them have a look at this link.

If you are having trouble figuring out the polarity of your diodes, remember that longer leg of the diode acts as the anode (positive connection) and the shorter leg as the cathode (negative connection).

I would recommend spacing your diodes far enough that the Wiimote will be able to distinguish between them at range. A few inches should be sufficient for either 4DOF or 6DOF sensor bars.

To give your sensor bar power, we need to clip one end of the USB cable so that we have a male USB on one end and exposed wire on the other end. Trim back the outer coating and you should have either 4 small color-coded wires (if your cable has data transfer capabilities) or 2 small color-coded wires. The ones we need should be colored red and black for 5V+ and GND. You can solder these onto your PCB as the voltage source component for your LED circuit. You may want to include a switch so that instead off plugging in or unplugging the USB to turn on/off the diodes, you can leave the sensor bar plugged in and use the switch to turn on/off the diodes. This can easily be done by interrupting the connection between the 5V (red wire) of the USB and the PCB.

After you've finished everything, plug your USB into a phone charger or other such 5V source (not your computer yet) to make sure it works. We don't want to test the circuit on the USB port of our computer because if something is connected improperly, it could damage your USB port.

When your circuit is connected, you won't see the LEDs emitting any light because the infrared light that they emit is not in the visual range of human sight. You can see if your LEDs are on by using most modern phone cameras. Just open up your camera app and have a look at the LEDs through the screen - you should see a soft purple or white light emitting from the diodes.

When all is done, you may want to add some hot glue onto the power source wires to make sure repeated movement wont tug the wires off.

Step 4: Mounting Your Sensor Bar

The following instructions are for those using a GoPro head mount as their means of attachment. If you are using something different be creative and find a solution that will have the infrared LEDs shine from the back of your head when worn.

The first thing you need to do is to find a drill bit that is the same size as the holes in your GoPro mount. I decided to hot-glue a spare PCB onto the back of the Wii sensor bar so that those who chose to do options 2 or 3 will have similar results. Slide the PCB into place where it will be held and mark the center. Drill out a hole completely through (you may want to do this before hot-gluing anything) and place the sensor back into place on the mount to make sure the holes line up. You can now secure the sensor in place by screwing in the bolt.

Make sure the sensor is centered and the Infrared LEDs shine backwards relative to your head.

Step 5: Setup - Make Some Space!

Let's talk a little bit about setup. You don't necessarily need a lot of space for this system. In fact, you can use it perfectly well just sitting at your desk. I do, however, recommend making enough space to stand in front of a TV with a few feet of spacing behind you and infront of you so that the Wiimote's built in sensor with its small degree of visibility can track your infrared diodes as you move around. Personally, I like to give myself a one body-length between myself and the TV and the same amount of space between myself and the Wiimote.

Very quickly lets discuss how the Wiimote needs to be positioned. The Wiimote should be parallel to the ground, at eyeball height to the user (whether they be standing or sitting down), and centered on the screen (It's more important for the Wiimote to be eyeball height than centered on the screen so if you can't achieve both at the same time, chose eyeball height). It is very important that the Wiimote be parallel to the ground so place it in a position so that it is as level as possible. To get your Wiimote to the desired height I would recommend a tripod with an extendable top. If not, a bookshelf or a table (depending on how tall you are or if you're sitting) might do nicely.

Have a look at the image at the beginning of this step to get a rough idea of what the setup and spacing might look like if you decide to use a TV as the viewing platform.

Step 6: Let's Code! Part 1 - the Basics

It's time to open the GlovePIE software. The 'documentation.rtf' file included with the download has everything you need to understand the language, but I will make sure to explain everything that we program here. If you plan on adding extra controllers or trackers, you may want to read through the documentation.

**Important Note: Glovepie is a looping program, so the entire program is in an infinite loop as soon as you run it.

I called this step 'The Basics' because in this stage, we're just going to write some test code and make sure all the interactions with the Wiimote go as planned. This program will track the infrared LEDs, figure out which LED is on which side, and output the corresponding positional data. Every important line of code here is commented so that you can understand what is happening.

The following code is for the 4DOF version of this project (Options 1&2):

var.leftX=0 //Left Diode X Position
var.leftY=0 //Left Diode Y Position
var.rightX=0 //Right Diode X Position
var.rightY=0 //Right Diode Y Position
var.leftSize=0 //Left Diode Size
var.rightSize=0 //Right Diode Size
//Turn all 4 Wiimote indicator LEDs on - tells us the program is running
wiimote.Led1=true
wiimote.Led2=true
wiimote.Led3=true
wiimote.Led4=true
//find dots
if (wiimote.dot1x>wiimote.dot2x){//dot1 is on the right side
   var.rightX=wiimote.dot1x
   var.rightY=wiimote.dot1y
   var.leftX=wiimote.dot2x
   var.leftY=wiimote.dot2y
}else{//dot1 is on the left side
    var.rightX=wiimote.dot2x
   var.rightY=wiimote.dot2y
   var.leftX=wiimote.dot1x
   var.leftY=wiimote.dot1y
}
var.xDistance=var.rightX-var.leftX //Distance between the two LEDs (X)
var.yDistance=abs(var.rightY-var.leftY)  //Distance between the two LEDs (Y) (Should be very small compared to xDistance)</p><p>var.leftSize=wiimote.dot1intensity //intensity of the LED is better than grabbing the actual size of the diode (for accuracy reasons)
var.rightSize=wiimote.dot2intensity
var.centerX=var.leftX+abs((var.rightX-var.leftX)/2) //Center X Position of the two diodes

The following code is for the 6DOF version of the project (Option 3). There is less commenting because most of what is needed is explained in the simpler program above. Important notes are still added as comments in this program.

var.topLeftX=0
var.topLeftY=0
var.topRightX=0
var.topRightY=0
var.bottomLeftX=0
var.bottomLeftY=0
var.bottomRightX=0
var.bottomRightY=0
wiimote.Led1=true
wiimote.Led2=true
wiimote.Led3=true
wiimote.Led4=true

//find dot 1
if ((wiimote.dot1x-wiimote.dot2x>50) || (wiimote.dot1x-wiimote.dot3x>50) || (wiimote.dot1x-wiimote.dot4x>50)){//dot1 is on the right side
   if ((wiimote.dot1y-wiimote.dot2y>50) || (wiimote.dot1y-wiimote.dot3y>50) || (wiimote.dot1y-wiimote.dot4y>50)){ //dot1 is on the top
      var.topRightX=wiimote.dot1x
      var.topRightY=wiimote.dot1y
   }else{//dot1 is on the bottom
      var.bottomRightX=wiimote.dot1x
      var.bottomRightY=wiimote.dot1y
   }
}else{//dot1 is on the left side
   if ((wiimote.dot1y-wiimote.dot2y>50) || (wiimote.dot1y-wiimote.dot3y>50) || (wiimote.dot1y-wiimote.dot4y>50)){ //dot1 is on the top
      var.topLeftX=wiimote.dot1x
      var.topLeftY=wiimote.dot1y
   }else{//dot1 is on the bottom
      var.bottomLeftX=wiimote.dot1x
      var.bottomLeftY=wiimote.dot1y
   }
}
/***********************************************/
//find dot 2
if ((wiimote.dot2x-wiimote.dot1x>50) || (wiimote.dot2x-wiimote.dot3x>50) || (wiimote.dot2x-wiimote.dot4x>50)){ //dot2 is on the right side
   if ((wiimote.dot2y-wiimote.dot1y>50) || (wiimote.dot2y-wiimote.dot3y>50) || (wiimote.dot2y-wiimote.dot4y>50)){ //dot2 is on the top
      var.topRightX=wiimote.dot2x
      var.topRightY=wiimote.dot2y
   }else{//dot2 is on the bottom
      var.bottomRightX=wiimote.dot2x
      var.bottomRightY=wiimote.dot2y
   }
}else{//dot2 is on the left side
   if ((wiimote.dot2y-wiimote.dot1y>50) || (wiimote.dot2y-wiimote.dot3y>50) || (wiimote.dot2y-wiimote.dot4y>50)){ //dot2 is on the top
      var.topLeftX=wiimote.dot2x
      var.topLeftY=wiimote.dot2y
   }else{//dot2 is on the bottom
      var.bottomLeftX=wiimote.dot2x
      var.bottomLeftY=wiimote.dot2y
   }
}
/***********************************************/
//find dot 3
if ((wiimote.dot3x-wiimote.dot1x>50) || (wiimote.dot3x-wiimote.dot2x>50) || (wiimote.dot3x-wiimote.dot4x>50)){ //dot3 is on the right side
   if ((wiimote.dot3y-wiimote.dot1y>50) || (wiimote.dot3y-wiimote.dot2y>50) || (wiimote.dot3y-wiimote.dot4y>50)){ //dot3 is on the top
      var.topRightX=wiimote.dot3x
      var.topRightY=wiimote.dot3y
   }else{//dot3 is on the bottom
      var.bottomRightX=wiimote.dot3x
      var.bottomRightY=wiimote.dot3y
   }
}else{//dot3 is on the left side
   if ((wiimote.dot3y-wiimote.dot1y>50) || (wiimote.dot3y-wiimote.dot2y>50) || (wiimote.dot3y-wiimote.dot4y>50)){ //dot3 is on the top
      var.topLeftX=wiimote.dot3x
      var.topLeftY=wiimote.dot3y
   }else{//dot3 is on the bottom
      var.bottomLeftX=wiimote.dot3x
      var.bottomLeftY=wiimote.dot3y
   }
}
/***********************************************/
//find dot 4
if ((wiimote.dot4x-wiimote.dot1x>50) || (wiimote.dot4x-wiimote.dot2x>50) || (wiimote.dot4x-wiimote.dot3x>50)){ //dot4 is on the right side
   if ((wiimote.dot4y-wiimote.dot1y>50) || (wiimote.dot4y-wiimote.dot2y>50) || (wiimote.dot4y-wiimote.dot3y>50)){ //dot4 is on the top
      var.topRightX=wiimote.dot4x
      var.topRightY=wiimote.dot4y
   }else{//dot4 is on the bottom
      var.bottomRightX=wiimote.dot4x
      var.bottomRightY=wiimote.dot4y
   }
}else{//dot4 is on the left side
   if ((wiimote.dot4y-wiimote.dot1y>50) || (wiimote.dot4y-wiimote.dot2y>50) || (wiimote.dot4y-wiimote.dot3y>50)){ //dot4 is on the top
      var.topLeftX=wiimote.dot4x
      var.topLeftY=wiimote.dot4y
   }else{//dot4 is on the bottom
      var.bottomLeftX=wiimote.dot4x
      var.bottomLeftY=wiimote.dot4y
   }
}
/***********************************************/

Now that you've pasted in the code and made any modifications that you see fit, go ahead and position yourself in front of your screen with the Wiimote positioned a few feet behind you pointing at the back of your head. Make sure the Bluetooth connection is still active and go ahead and click 'Run'. Check behind you to make sure all 4 of the Wiimote's LEDs are turned on - this indicates the program is running and has connected to the Wiimote. You can now click on the tab that says 'Variables' and you will see the collected data change as you move and turn your head in various directions. If everything appears to be in order go ahead and proceed to the next step where we learn to control the mouse! If you have any questions, feel free to message me or post in the comments.

Step 7: Let's Code! Part 2 - Mouse Control/Limited Mobility User Application

As I stated at the beginning of this instructable, this project isn't only intended for people to have a more fun and immersive gaming experience. This step in particular will not only generate mouse control, but provide a means for any users with limited mobility to take control of their computers.

I've gone ahead and added a calibration section to this code so all you have to do to get it to work is plug in the pixel dimensions of your screen and hit run. It will talk you through the calibration process and start the looping function that takes control of the mouse. After the calibration section has finished running, the mouse will position itself wherever you look.

*If you don't know the pixel dimensions of your screen, add the following snippet of code to the program after the comment '//pixel'.

say("Move your mouse completely to the right side of your screen")
wait 7s
var.mouseMaxX=mouse.CursorPosX
say("Move your mouse completely to the bottom of your screen")
wait 7s
var.mouseMaxY=mouse.CursorPosY

For 4DOF systems (options 1 and 2) use the following code:

//Light up all 4 LEDS on the wiimote so we know the program is running and connected
wiimote.Led1=true
wiimote.Led2=true
wiimote.Led3=true
wiimote.Led4=true
//Your Screen Resolution
var.cursorMaxX=1920
var.cursorMaxY=1080
/*********************************************************************************************************************************/
//This section is for calibration and will run once
if var.init=0 then
     var.init=1
     say("Stand central and look at the center of the screen")
     wait 7s
     //dot intensities are recorded
     var.leftSize=wiimote.dot1intensity
     var.rightSize=wiimote.dot2intensity     //pixel
     say("Look at the left side of the screen for a few seconds")
     wait 5s
     if (wiimote.dot1x>wiimote.dot2x){//dot1 is on the right side
        var.rightX=wiimote.dot1x
        var.leftX=wiimote.dot2x
     }else{//dot1 is on the left side
        var.rightX=wiimote.dot2x
        var.leftX=wiimote.dot1x
     }
     var.xMax=round(var.leftX+abs((var.rightX-var.leftX)/2))//max X value is found by taking the center location of the two points
     say("Look at the right side of the screen for a few seconds")
     wait 5s
     if (wiimote.dot1x>wiimote.dot2x){//dot1 is on the right side
        var.rightX=wiimote.dot1x
        var.leftX=wiimote.dot2x
     }else{//dot1 is on the left side
        var.rightX=wiimote.dot2x
        var.leftX=wiimote.dot1x
     }
     var.xMin=round(var.leftX+abs((var.rightX-var.leftX)/2))//min X value is found by taking the center location of the two points
     say("Look at the bottom of the screen for a few seconds")
     wait 5s
     if (wiimote.dot1x>wiimote.dot2x){//dot1 is on the left side
        var.rightY=wiimote.dot1y
        var.leftY=wiimote.dot2y
     }else{//dot1 is on the left side
        var.rightY=wiimote.dot2y
        var.leftY=wiimote.dot1y
     }
     var.yMax=round((var.rightY+var.leftY)/2)//max Y value is found by taking the center location of the two points
     say("Look at the top of the screen for a few seconds")
     wait 5s
     if (wiimote.dot1x>wiimote.dot2x){//dot1 is on the left side
        var.rightY=wiimote.dot1y
        var.leftY=wiimote.dot2y
     }else{//dot1 is on the left side
        var.rightY=wiimote.dot2y
        var.leftY=wiimote.dot1y
     }
     var.yMin=round((var.rightY+var.leftY)/2)//min X value is found by taking the center location of the two points
     var.centerX=round(var.xMin+((var.xMin+var.xMax)/2))
     var.centerY=round(var.yMin+((var.yMin+var.yMax)/2))
end if
/*********************************************************************************************************************************/
//This part loops infinitely
//find dots
if (wiimote.dot1x>wiimote.dot2x){//dot1 is on the right side
   var.rightX=wiimote.dot1x
   var.rightY=wiimote.dot1y
   var.leftX=wiimote.dot2x
   var.leftY=wiimote.dot2y
}else{//dot1 is on the left side
   var.rightX=wiimote.dot2x
   var.rightY=wiimote.dot2y
   var.leftX=wiimote.dot1x
   var.leftY=wiimote.dot1y
}
if(wiimote.dot1vis==true && wiimote.dot2vis==true){//if both dots are visible
   mouse.CursorPosX=mouse.CursorPosX-(var.currentX-(var.cursorMaxX-var.cursorMaxX*(((var.leftX+((var.rightX-var.leftX)/2))-var.xMin)/(var.xMax-var.xMin))))//convert centerX to pixel ration and set mouse to position
   var.currentX=mouse.CursorPosX
   mouse.CursorPosY=mouse.CursorPosY-(var.currentY-(var.cursorMaxY*(((var.leftY+((var.rightY-var.leftY)/2))-var.yMin)/(var.yMax-var.yMin))))//convert centerY to pixel ratio and set mouse to position
   var.currentY=mouse.CursorPosY
}
//"panic" button ESCAPE will stop/exit the program if anything goes wrong
if ESCAPE then
   exitpie
end if
/*********************************************************************************************************************************/*******************************************************************************************************************************/</p>

For 6DOF systems (option 3) use the following code:

var.topLeftX=0
var.topLeftY=0
var.topRightX=0
var.topRightY=0
var.bottomLeftX=0
var.bottomLeftY=0
var.bottomRightX=0
var.bottomRightY=0
wiimote.Led1=true
wiimote.Led2=true
wiimote.Led3=true
wiimote.Led4=true
var.xMin=0
var.xMax=0
var.yMin=0
var.yMax=0
//Screen Size
var.mouseMaxX=1920
var.mouseMaxY=1080
/*********************************************************************************************************************************</p><p>//This section is for calibration and will run once
if var.init=0 then
     var.init=1
//xMin (LeftSide)
say("Look at the left side of your screen for a few seconds")
wait 7s
//find dot 1
if ((wiimote.dot1x-wiimote.dot2x>50) || (wiimote.dot1x-wiimote.dot3x>50) || (wiimote.dot1x-wiimote.dot4x>50)){//dot1 is on the right side
   if ((wiimote.dot1y-wiimote.dot2y>50) || (wiimote.dot1y-wiimote.dot3y>50) || (wiimote.dot1y-wiimote.dot4y>50)){ //dot1 is on the top
      var.topRightx=wiimote.dot1x
      var.topRightY=wiimote.dot1y
   }else{//dot1 is on the bottom
      var.bottomRightx=wiimote.dot1x
      var.bottomRightY=wiimote.dot1y
   }
}else{//dot1 is on the left side
   if ((wiimote.dot1y-wiimote.dot2y>50) || (wiimote.dot1y-wiimote.dot3y>50) || (wiimote.dot1y-wiimote.dot4y>50)){ //dot1 is on the top
      var.topLeftx=wiimote.dot1x
      var.topLeftY=wiimote.dot1y
   }else{//dot1 is on the bottom
      var.bottomLeftx=wiimote.dot1x
      var.bottomLeftY=wiimote.dot1y
   }
}
/***********************************************/
//find dot 2
if ((wiimote.dot2x-wiimote.dot1x>50) || (wiimote.dot2x-wiimote.dot3x>50) || (wiimote.dot2x-wiimote.dot4x>50)){ //dot2 is on the right side
   if ((wiimote.dot2y-wiimote.dot1y>50) || (wiimote.dot2y-wiimote.dot3y>50) || (wiimote.dot2y-wiimote.dot4y>50)){ //dot2 is on the top
      var.topRightx=wiimote.dot2x
      var.topRightY=wiimote.dot2y
   }else{//dot2 is on the bottom
      var.bottomRightx=wiimote.dot2x
      var.bottomRightY=wiimote.dot2y
   }
}else{//dot2 is on the left side
   if ((wiimote.dot2y-wiimote.dot1y>50) || (wiimote.dot2y-wiimote.dot3y>50) || (wiimote.dot2y-wiimote.dot4y>50)){ //dot2 is on the top
      var.topLeftx=wiimote.dot2x
      var.topLeftY=wiimote.dot2y
   }else{//dot2 is on the bottom
      var.bottomLeftx=wiimote.dot2x
      var.bottomLeftY=wiimote.dot2y
   }
}
/***********************************************/
//find dot 3
if ((wiimote.dot3x-wiimote.dot1x>50) || (wiimote.dot3x-wiimote.dot2x>50) || (wiimote.dot3x-wiimote.dot4x>50)){ //dot3 is on the right side
   if ((wiimote.dot3y-wiimote.dot1y>50) || (wiimote.dot3y-wiimote.dot2y>50) || (wiimote.dot3y-wiimote.dot4y>50)){ //dot3 is on the top
      var.topRightx=wiimote.dot3x
      var.topRightY=wiimote.dot3y
   }else{//dot3 is on the bottom
      var.bottomRightx=wiimote.dot3x
      var.bottomRightY=wiimote.dot3y
   }
}else{//dot3 is on the left side
   if ((wiimote.dot3y-wiimote.dot1y>50) || (wiimote.dot3y-wiimote.dot2y>50) || (wiimote.dot3y-wiimote.dot4y>50)){ //dot3 is on the top
      var.topLeftx=wiimote.dot3x
      var.topLeftY=wiimote.dot3y
   }else{//dot3 is on the bottom
      var.bottomLeftx=wiimote.dot3x
      var.bottomLeftY=wiimote.dot3y
   }
}
/***********************************************/
//find dot 4
if ((wiimote.dot4x-wiimote.dot1x>50) || (wiimote.dot4x-wiimote.dot2x>50) || (wiimote.dot4x-wiimote.dot3x>50)){ //dot4 is on the right side
   if ((wiimote.dot4y-wiimote.dot1y>50) || (wiimote.dot4y-wiimote.dot2y>50) || (wiimote.dot4y-wiimote.dot3y>50)){ //dot4 is on the top
      var.topRightx=wiimote.dot4x
      var.topRightY=wiimote.dot4y
   }else{//dot4 is on the bottom
      var.bottomRightx=wiimote.dot4x
      var.bottomRightY=wiimote.dot4y
   }
}else{//dot4 is on the left side
   if ((wiimote.dot4y-wiimote.dot1y>50) || (wiimote.dot4y-wiimote.dot2y>50) || (wiimote.dot4y-wiimote.dot3y>50)){ //dot4 is on the top
      var.topLeftx=wiimote.dot4x
      var.topLeftY=wiimote.dot4y
   }else{//dot4 is on the bottom
      var.bottomLeftx=wiimote.dot4x
      var.bottomLeftY=wiimote.dot4y
   }
}
/***********************************************/
var.xMin=var.topLeftx+(abs(var.topLeftx-var.topRightx)/2)//xMax (RightSide)
say("Look at the right side of your screen for a few seconds")
wait 7s
//find dot 1
if ((wiimote.dot1x-wiimote.dot2x>50) || (wiimote.dot1x-wiimote.dot3x>50) || (wiimote.dot1x-wiimote.dot4x>50)){//dot1 is on the right side
   if ((wiimote.dot1y-wiimote.dot2y>50) || (wiimote.dot1y-wiimote.dot3y>50) || (wiimote.dot1y-wiimote.dot4y>50)){ //dot1 is on the top
      var.topRightx=wiimote.dot1x
      var.topRightY=wiimote.dot1y
   }else{//dot1 is on the bottom
      var.bottomRightx=wiimote.dot1x
      var.bottomRightY=wiimote.dot1y
   }
}else{//dot1 is on the left side
   if ((wiimote.dot1y-wiimote.dot2y>50) || (wiimote.dot1y-wiimote.dot3y>50) || (wiimote.dot1y-wiimote.dot4y>50)){ //dot1 is on the top
      var.topLeftx=wiimote.dot1x
      var.topLeftY=wiimote.dot1y
   }else{//dot1 is on the bottom
      var.bottomLeftx=wiimote.dot1x
      var.bottomLeftY=wiimote.dot1y
   }
}
/***********************************************/
//find dot 2
if ((wiimote.dot2x-wiimote.dot1x>50) || (wiimote.dot2x-wiimote.dot3x>50) || (wiimote.dot2x-wiimote.dot4x>50)){ //dot2 is on the right side
   if ((wiimote.dot2y-wiimote.dot1y>50) || (wiimote.dot2y-wiimote.dot3y>50) || (wiimote.dot2y-wiimote.dot4y>50)){ //dot2 is on the top
      var.topRightx=wiimote.dot2x
      var.topRightY=wiimote.dot2y
   }else{//dot2 is on the bottom
      var.bottomRightx=wiimote.dot2x
      var.bottomRightY=wiimote.dot2y
   }
}else{//dot2 is on the left side
   if ((wiimote.dot2y-wiimote.dot1y>50) || (wiimote.dot2y-wiimote.dot3y>50) || (wiimote.dot2y-wiimote.dot4y>50)){ //dot2 is on the top
      var.topLeftx=wiimote.dot2x
      var.topLeftY=wiimote.dot2y
   }else{//dot2 is on the bottom
      var.bottomLeftx=wiimote.dot2x
      var.bottomLeftY=wiimote.dot2y
   }
}
/***********************************************/
//find dot 3
if ((wiimote.dot3x-wiimote.dot1x>50) || (wiimote.dot3x-wiimote.dot2x>50) || (wiimote.dot3x-wiimote.dot4x>50)){ //dot3 is on the right side
   if ((wiimote.dot3y-wiimote.dot1y>50) || (wiimote.dot3y-wiimote.dot2y>50) || (wiimote.dot3y-wiimote.dot4y>50)){ //dot3 is on the top
      var.topRightx=wiimote.dot3x
      var.topRightY=wiimote.dot3y
   }else{//dot3 is on the bottom
      var.bottomRightx=wiimote.dot3x
      var.bottomRightY=wiimote.dot3y
   }
}else{//dot3 is on the left side
   if ((wiimote.dot3y-wiimote.dot1y>50) || (wiimote.dot3y-wiimote.dot2y>50) || (wiimote.dot3y-wiimote.dot4y>50)){ //dot3 is on the top
      var.topLeftx=wiimote.dot3x
      var.topLeftY=wiimote.dot3y
   }else{//dot3 is on the bottom
      var.bottomLeftx=wiimote.dot3x
      var.bottomLeftY=wiimote.dot3y
   }
}
/***********************************************/
//find dot 4
if ((wiimote.dot4x-wiimote.dot1x>50) || (wiimote.dot4x-wiimote.dot2x>50) || (wiimote.dot4x-wiimote.dot3x>50)){ //dot4 is on the right side
   if ((wiimote.dot4y-wiimote.dot1y>50) || (wiimote.dot4y-wiimote.dot2y>50) || (wiimote.dot4y-wiimote.dot3y>50)){ //dot4 is on the top
      var.topRightx=wiimote.dot4x
      var.topRightY=wiimote.dot4y
   }else{//dot4 is on the bottom
      var.bottomRightx=wiimote.dot4x
      var.bottomRightY=wiimote.dot4y
   }
}else{//dot4 is on the left side
   if ((wiimote.dot4y-wiimote.dot1y>50) || (wiimote.dot4y-wiimote.dot2y>50) || (wiimote.dot4y-wiimote.dot3y>50)){ //dot4 is on the top
      var.topLeftx=wiimote.dot4x
      var.topLeftY=wiimote.dot4y
   }else{//dot4 is on the bottom
      var.bottomLeftx=wiimote.dot4x
      var.bottomLeftY=wiimote.dot4y
   }
}
/***********************************************/
var.xMax=var.topLeftx+(abs(var.topLeftx-var.topRightx)/2)</p><p>//yMin (BottomSide)
say("Look at the bottom of your screen for a few seconds")
wait 7s
//find dot 1
if ((wiimote.dot1x-wiimote.dot2x>50) || (wiimote.dot1x-wiimote.dot3x>50) || (wiimote.dot1x-wiimote.dot4x>50)){//dot1 is on the right side
   if ((wiimote.dot1y-wiimote.dot2y>50) || (wiimote.dot1y-wiimote.dot3y>50) || (wiimote.dot1y-wiimote.dot4y>50)){ //dot1 is on the top
      var.topRightx=wiimote.dot1x
      var.topRightY=wiimote.dot1y
   }else{//dot1 is on the bottom
      var.bottomRightx=wiimote.dot1x
      var.bottomRightY=wiimote.dot1y
   }
}else{//dot1 is on the left side
   if ((wiimote.dot1y-wiimote.dot2y>50) || (wiimote.dot1y-wiimote.dot3y>50) || (wiimote.dot1y-wiimote.dot4y>50)){ //dot1 is on the top
      var.topLeftx=wiimote.dot1x
      var.topLeftY=wiimote.dot1y
   }else{//dot1 is on the bottom
      var.bottomLeftx=wiimote.dot1x
      var.bottomLeftY=wiimote.dot1y
   }
}
/***********************************************/
//find dot 2
if ((wiimote.dot2x-wiimote.dot1x>50) || (wiimote.dot2x-wiimote.dot3x>50) || (wiimote.dot2x-wiimote.dot4x>50)){ //dot2 is on the right side
   if ((wiimote.dot2y-wiimote.dot1y>50) || (wiimote.dot2y-wiimote.dot3y>50) || (wiimote.dot2y-wiimote.dot4y>50)){ //dot2 is on the top
      var.topRightx=wiimote.dot2x
      var.topRightY=wiimote.dot2y
   }else{//dot2 is on the bottom
      var.bottomRightx=wiimote.dot2x
      var.bottomRightY=wiimote.dot2y
   }
}else{//dot2 is on the left side
   if ((wiimote.dot2y-wiimote.dot1y>50) || (wiimote.dot2y-wiimote.dot3y>50) || (wiimote.dot2y-wiimote.dot4y>50)){ //dot2 is on the top
      var.topLeftx=wiimote.dot2x
      var.topLeftY=wiimote.dot2y
   }else{//dot2 is on the bottom
      var.bottomLeftx=wiimote.dot2x
      var.bottomLeftY=wiimote.dot2y
   }
}
/***********************************************/
//find dot 3
if ((wiimote.dot3x-wiimote.dot1x>50) || (wiimote.dot3x-wiimote.dot2x>50) || (wiimote.dot3x-wiimote.dot4x>50)){ //dot3 is on the right side
   if ((wiimote.dot3y-wiimote.dot1y>50) || (wiimote.dot3y-wiimote.dot2y>50) || (wiimote.dot3y-wiimote.dot4y>50)){ //dot3 is on the top
      var.topRightx=wiimote.dot3x
      var.topRightY=wiimote.dot3y
   }else{//dot3 is on the bottom
      var.bottomRightx=wiimote.dot3x
      var.bottomRightY=wiimote.dot3y
   }
}else{//dot3 is on the left side
   if ((wiimote.dot3y-wiimote.dot1y>50) || (wiimote.dot3y-wiimote.dot2y>50) || (wiimote.dot3y-wiimote.dot4y>50)){ //dot3 is on the top
      var.topLeftx=wiimote.dot3x
      var.topLeftY=wiimote.dot3y
   }else{//dot3 is on the bottom
      var.bottomLeftx=wiimote.dot3x
      var.bottomLeftY=wiimote.dot3y
   }
}
/***********************************************/
//find dot 4
if ((wiimote.dot4x-wiimote.dot1x>50) || (wiimote.dot4x-wiimote.dot2x>50) || (wiimote.dot4x-wiimote.dot3x>50)){ //dot4 is on the right side
   if ((wiimote.dot4y-wiimote.dot1y>50) || (wiimote.dot4y-wiimote.dot2y>50) || (wiimote.dot4y-wiimote.dot3y>50)){ //dot4 is on the top
      var.topRightx=wiimote.dot4x
      var.topRightY=wiimote.dot4y
   }else{//dot4 is on the bottom
      var.bottomRightx=wiimote.dot4x
      var.bottomRightY=wiimote.dot4y
   }
}else{//dot4 is on the left side
   if ((wiimote.dot4y-wiimote.dot1y>50) || (wiimote.dot4y-wiimote.dot2y>50) || (wiimote.dot4y-wiimote.dot3y>50)){ //dot4 is on the top
      var.topLeftx=wiimote.dot4x
      var.topLeftY=wiimote.dot4y
   }else{//dot4 is on the bottom
      var.bottomLeftx=wiimote.dot4x
      var.bottomLeftY=wiimote.dot4y
   }
}
/***********************************************/
var.yMin=var.bottomLefty+(abs(var.topLefty-var.bottomLefty)/2)</p><p>//yMax (TopSide)
say("Look at the top of your screen for a few seconds")
wait 7s
//find dot 1
if ((wiimote.dot1x-wiimote.dot2x>50) || (wiimote.dot1x-wiimote.dot3x>50) || (wiimote.dot1x-wiimote.dot4x>50)){//dot1 is on the right side
   if ((wiimote.dot1y-wiimote.dot2y>50) || (wiimote.dot1y-wiimote.dot3y>50) || (wiimote.dot1y-wiimote.dot4y>50)){ //dot1 is on the top
      var.topRightx=wiimote.dot1x
      var.topRightY=wiimote.dot1y
   }else{//dot1 is on the bottom
      var.bottomRightx=wiimote.dot1x
      var.bottomRightY=wiimote.dot1y
   }
}else{//dot1 is on the left side
   if ((wiimote.dot1y-wiimote.dot2y>50) || (wiimote.dot1y-wiimote.dot3y>50) || (wiimote.dot1y-wiimote.dot4y>50)){ //dot1 is on the top
      var.topLeftx=wiimote.dot1x
      var.topLeftY=wiimote.dot1y
   }else{//dot1 is on the bottom
      var.bottomLeftx=wiimote.dot1x
      var.bottomLeftY=wiimote.dot1y
   }
}
/***********************************************/
//find dot 2
if ((wiimote.dot2x-wiimote.dot1x>50) || (wiimote.dot2x-wiimote.dot3x>50) || (wiimote.dot2x-wiimote.dot4x>50)){ //dot2 is on the right side
   if ((wiimote.dot2y-wiimote.dot1y>50) || (wiimote.dot2y-wiimote.dot3y>50) || (wiimote.dot2y-wiimote.dot4y>50)){ //dot2 is on the top
      var.topRightx=wiimote.dot2x
      var.topRightY=wiimote.dot2y
   }else{//dot2 is on the bottom
      var.bottomRightx=wiimote.dot2x
      var.bottomRightY=wiimote.dot2y
   }
}else{//dot2 is on the left side
   if ((wiimote.dot2y-wiimote.dot1y>50) || (wiimote.dot2y-wiimote.dot3y>50) || (wiimote.dot2y-wiimote.dot4y>50)){ //dot2 is on the top
      var.topLeftx=wiimote.dot2x
      var.topLeftY=wiimote.dot2y
   }else{//dot2 is on the bottom
      var.bottomLeftx=wiimote.dot2x
      var.bottomLeftY=wiimote.dot2y
   }
}
/***********************************************/
//find dot 3
if ((wiimote.dot3x-wiimote.dot1x>50) || (wiimote.dot3x-wiimote.dot2x>50) || (wiimote.dot3x-wiimote.dot4x>50)){ //dot3 is on the right side
   if ((wiimote.dot3y-wiimote.dot1y>50) || (wiimote.dot3y-wiimote.dot2y>50) || (wiimote.dot3y-wiimote.dot4y>50)){ //dot3 is on the top
      var.topRightx=wiimote.dot3x
      var.topRightY=wiimote.dot3y
   }else{//dot3 is on the bottom
      var.bottomRightx=wiimote.dot3x
      var.bottomRightY=wiimote.dot3y
   }
}else{//dot3 is on the left side
   if ((wiimote.dot3y-wiimote.dot1y>50) || (wiimote.dot3y-wiimote.dot2y>50) || (wiimote.dot3y-wiimote.dot4y>50)){ //dot3 is on the top
      var.topLeftx=wiimote.dot3x
      var.topLeftY=wiimote.dot3y
   }else{//dot3 is on the bottom
      var.bottomLeftx=wiimote.dot3x
      var.bottomLeftY=wiimote.dot3y
   }
}
/***********************************************/
//find dot 4
if ((wiimote.dot4x-wiimote.dot1x>50) || (wiimote.dot4x-wiimote.dot2x>50) || (wiimote.dot4x-wiimote.dot3x>50)){ //dot4 is on the right side
   if ((wiimote.dot4y-wiimote.dot1y>50) || (wiimote.dot4y-wiimote.dot2y>50) || (wiimote.dot4y-wiimote.dot3y>50)){ //dot4 is on the top
      var.topRightx=wiimote.dot4x
      var.topRightY=wiimote.dot4y
   }else{//dot4 is on the bottom
      var.bottomRightx=wiimote.dot4x
      var.bottomRightY=wiimote.dot4y
   }
}else{//dot4 is on the left side
   if ((wiimote.dot4y-wiimote.dot1y>50) || (wiimote.dot4y-wiimote.dot2y>50) || (wiimote.dot4y-wiimote.dot3y>50)){ //dot4 is on the top
      var.topLeftx=wiimote.dot4x
      var.topLeftY=wiimote.dot4y
   }else{//dot4 is on the bottom
      var.bottomLeftx=wiimote.dot4x
      var.bottomLeftY=wiimote.dot4y
   }
}
/***********************************************/
var.yMax=var.bottomLefty+(abs(var.topLefty-var.bottomLefty)/2)
end if
/*********************************************************************************************************************************/
//This part loops infinitely
//find dots
//find dot 1
if ((wiimote.dot1x-wiimote.dot2x>50) || (wiimote.dot1x-wiimote.dot3x>50) || (wiimote.dot1x-wiimote.dot4x>50)){//dot1 is on the right side
   if ((wiimote.dot1y-wiimote.dot2y>50) || (wiimote.dot1y-wiimote.dot3y>50) || (wiimote.dot1y-wiimote.dot4y>50)){ //dot1 is on the top
      var.topRightx=wiimote.dot1x
      var.topRightY=wiimote.dot1y
   }else{//dot1 is on the bottom
      var.bottomRightx=wiimote.dot1x
      var.bottomRightY=wiimote.dot1y
   }
}else{//dot1 is on the left side
   if ((wiimote.dot1y-wiimote.dot2y>50) || (wiimote.dot1y-wiimote.dot3y>50) || (wiimote.dot1y-wiimote.dot4y>50)){ //dot1 is on the top
      var.topLeftx=wiimote.dot1x
      var.topLeftY=wiimote.dot1y
   }else{//dot1 is on the bottom
      var.bottomLeftx=wiimote.dot1x
      var.bottomLeftY=wiimote.dot1y
   }
}
/***********************************************/
//find dot 2
if ((wiimote.dot2x-wiimote.dot1x>50) || (wiimote.dot2x-wiimote.dot3x>50) || (wiimote.dot2x-wiimote.dot4x>50)){ //dot2 is on the right side
   if ((wiimote.dot2y-wiimote.dot1y>50) || (wiimote.dot2y-wiimote.dot3y>50) || (wiimote.dot2y-wiimote.dot4y>50)){ //dot2 is on the top
      var.topRightx=wiimote.dot2x
      var.topRightY=wiimote.dot2y
   }else{//dot2 is on the bottom
      var.bottomRightx=wiimote.dot2x
      var.bottomRightY=wiimote.dot2y
   }
}else{//dot2 is on the left side
   if ((wiimote.dot2y-wiimote.dot1y>50) || (wiimote.dot2y-wiimote.dot3y>50) || (wiimote.dot2y-wiimote.dot4y>50)){ //dot2 is on the top
      var.topLeftx=wiimote.dot2x
      var.topLeftY=wiimote.dot2y
   }else{//dot2 is on the bottom
      var.bottomLeftx=wiimote.dot2x
      var.bottomLeftY=wiimote.dot2y
   }
}
/***********************************************/
//find dot 3
if ((wiimote.dot3x-wiimote.dot1x>50) || (wiimote.dot3x-wiimote.dot2x>50) || (wiimote.dot3x-wiimote.dot4x>50)){ //dot3 is on the right side
   if ((wiimote.dot3y-wiimote.dot1y>50) || (wiimote.dot3y-wiimote.dot2y>50) || (wiimote.dot3y-wiimote.dot4y>50)){ //dot3 is on the top
      var.topRightx=wiimote.dot3x
      var.topRightY=wiimote.dot3y
   }else{//dot3 is on the bottom
      var.bottomRightx=wiimote.dot3x
      var.bottomRightY=wiimote.dot3y
   }
}else{//dot3 is on the left side
   if ((wiimote.dot3y-wiimote.dot1y>50) || (wiimote.dot3y-wiimote.dot2y>50) || (wiimote.dot3y-wiimote.dot4y>50)){ //dot3 is on the top
      var.topLeftx=wiimote.dot3x
      var.topLeftY=wiimote.dot3y
   }else{//dot3 is on the bottom
      var.bottomLeftx=wiimote.dot3x
      var.bottomLeftY=wiimote.dot3y
   }
}
/***********************************************/
//find dot 4
if ((wiimote.dot4x-wiimote.dot1x>50) || (wiimote.dot4x-wiimote.dot2x>50) || (wiimote.dot4x-wiimote.dot3x>50)){ //dot4 is on the right side
   if ((wiimote.dot4y-wiimote.dot1y>50) || (wiimote.dot4y-wiimote.dot2y>50) || (wiimote.dot4y-wiimote.dot3y>50)){ //dot4 is on the top
      var.topRightx=wiimote.dot4x
      var.topRightY=wiimote.dot4y
   }else{//dot4 is on the bottom
      var.bottomRightx=wiimote.dot4x
      var.bottomRightY=wiimote.dot4y
   }
}else{//dot4 is on the left side
   if ((wiimote.dot4y-wiimote.dot1y>50) || (wiimote.dot4y-wiimote.dot2y>50) || (wiimote.dot4y-wiimote.dot3y>50)){ //dot4 is on the top
      var.topLeftx=wiimote.dot4x
      var.topLeftY=wiimote.dot4y
   }else{//dot4 is on the bottom
      var.bottomLeftx=wiimote.dot4x
      var.bottomLeftY=wiimote.dot4y
   }
}
/***********************************************/
if(wiimote.dot1vis==true && wiimote.dot2vis==true && wiimote.dot3vis==true && wiimote.dot4vis==true){//if all dots are visible
   mouse.CursorPosX=mouse.CursorPosX-(var.currentX-(var.cursorMaxX-var.cursorMaxX*(((var.topLeftX+((var.topRightX-var.topLeftX)/2))-var.xMin)/(var.xMax-var.xMin))))//convert CenterX to pixel ration and set mouse to position
   var.currentX=mouse.CursorPosX
   mouse.CursorPosY=mouse.CursorPosY-(var.currentY-(var.cursorMaxY*(((var.bottomLeftY+((var.topRightY-var.bottomLeftY)/2))-var.yMin)/(var.yMax-var.yMin))))//convert CenterY to pixel ratio and set mouse to position
   var.currentY=mouse.CursorPosY
}
//"panic" button ESCAPE will stop/exit the program if anything goes wrong
if ESCAPE then
   exitpie
end if
/*********************************************************************************************************************************/</p>

As usual, if you have any questions feel free to message me or comment down below!

Step 8: Let's Code! Part 3 - Game Integration - Mouse

Here we go... what you've all been waiting for. This is the part where you get to connect this system to your favorite games such as Fortnite, Rocket League, Overwatch, etc. You may have been thinking, "Why can't I just use the mouse control program from the last step to make my character look around in the games I play?". You could try, but your character would be staring straight no matter how hard you whip your head around. The reason for this is because games like this use a method of mouse movement called 'Direct Input'. That takes the relative position of the mouse rather than the absolute position. In other words you could move your mouse infinitely to one side or the other without being bound by the size of your screen. This step goes through what you need to know to integrate this system with all of your favorite games. Since Direct Input doesn't take mouse position based on pixel ratios, but rather on relative position, I won't be including a calibration step in the code. The only things that need to be adjusted for your use are the sensitivity variables prefaced by the comment 'Sensitivity'. You may need to increase or decrease these values for the best response of the game with the system. We generate a new mouse position based on system movement by taking the current mouse position and adding/subtracting the change in central x or y locations since the last loop of the program.

The following code is for any 4DOF system but can easily be modified for a 6DOF system:

//These variables will hold the IR LED locations
var.leftX=0
var.leftY=0
var.rightX=0
var.rightY=0
//Light up all 4 LEDS on the wiimote so we know the program is running and connected
wiimote.Led1=true
wiimote.Led2=true
wiimote.Led3=true
wiimote.Led4=true
//Sensitivity
var.sX=5
var.sY=5
//find dots
if (wiimote.dot1x>wiimote.dot2x){//dot1 is on the right side
   var.rightX=wiimote.dot1x
   var.rightY=wiimote.dot1y
   var.leftX=wiimote.dot2x
   var.leftY=wiimote.dot2y
}else{//dot1 is on the left side
    var.rightX=wiimote.dot2x
   var.rightY=wiimote.dot2y
   var.leftX=wiimote.dot1x
   var.leftY=wiimote.dot1y
}
if(wiimote.dot1vis==true && wiimote.dot2vis==true){//if both dots are visible
   mouse.DirectInputX=mouse.DirectInputX+(((var.currentRightX+var.currentLeftX)/2)-((var.rightX+var.leftX)/2))*var.sX
   mouse.DirectInputY=mouse.DirectInputY-(((var.currentRightY+var.currentLeftY)/2)-((var.rightY+var.leftY)/2))*var.sY
}
var.currentRightX=var.rightX
var.currentLeftX=var.leftX
var.currentRightY=var.rightY
var.currentLeftY=var.leftY
//"panic" button ESCAPE will stop/exit the program if anything goes wrong
if ESCAPE then
   exitpie
end if

Increased sensitivity values will cause a greater mouse movement relative to user movement and decreased sensitivity values will cause the mouse to move a smaller distance with user movement.

Feel free to message me or comment with any questions.

Step 9: Let's Code! Part 4 - Game Integration - Keyboard

In this section, we're going to learn how to integrate key-presses into our system. For this example, I will be using a game that has camera functions based on key-presses. Let's write a simple program that will make the game Rocket League a bit more immersive. In Rocket League, there are key-binds you can set that will swivel the camera in a particular direction. Let's take control over the camera swivel left and swivel right functions. Now, we don't want the camera to be moving around all the time while we play this game, so we're going to create a program that will make the camera swivel in a particular direction once the user looks at the right or left 10% of the screen. This should enable seamless gameplay where camera integration is used only when we need it. In this program I will also include the calibration loop so that everything is as precise as it can be.

The following code is for any 4DOF system but can easily be modified for a 6DOF system:

//These variables will hold the IR LED locations
var.leftX=0
var.leftY=0
var.rightX=0
var.rightY=0
//Light up all 4 LEDS on the wiimote so we know the program is running and connected
wiimote.Led1=true
wiimote.Led2=true
wiimote.Led3=true
wiimote.Led4=true
//Your Screen Resolution
var.cursorMaxX=1920
var.cursorMaxY=1080
//find the '10% region'
var.minTenX=0.1*var.cursorMaxX
var.maxTenX=0.9*var.cursorMaxX
var.currentX=0
var.currentY=0
//single loop for initial calibration
if var.init=0 then
     var.init=1
     say("Stand central and look at the center of the screen")
     wait 7s
     //dot intensities are recorded
     var.leftSize=wiimote.dot1intensity
     var.rightSize=wiimote.dot2intensity
     say("Look at the left side of the screen for a few seconds")
     wait 5s
     if (wiimote.dot1x>wiimote.dot2x){//dot1 is on the right side
        var.rightX=wiimote.dot1x
        var.leftX=wiimote.dot2x
     }else{//dot1 is on the left side
        var.rightX=wiimote.dot2x
        var.leftX=wiimote.dot1x
     }
     var.xMax=round(var.leftX+abs((var.rightX-var.leftX)/2))//max X value is found by taking the center location of the two points
     say("Look at the right side of the screen for a few seconds")
     wait 5s
     if (wiimote.dot1x>wiimote.dot2x){//dot1 is on the right side
        var.rightX=wiimote.dot1x
        var.leftX=wiimote.dot2x
     }else{//dot1 is on the left side
        var.rightX=wiimote.dot2x
        var.leftX=wiimote.dot1x
     }
     var.xMin=round(var.leftX+abs((var.rightX-var.leftX)/2))//min X value is found by taking the center location of the two points
     say("Look at the bottom of the screen for a few seconds")
     wait 5s
     if (wiimote.dot1x>wiimote.dot2x){//dot1 is on the left side
        var.rightY=wiimote.dot1y
        var.leftY=wiimote.dot2y
     }else{//dot1 is on the left side
        var.rightY=wiimote.dot2y
        var.leftY=wiimote.dot1y
     }
     var.yMax=round((var.rightY+var.leftY)/2)//max Y value is found by taking the center location of the two points
     say("Look at the top of the screen for a few seconds")
     wait 5s
     if (wiimote.dot1x>wiimote.dot2x){//dot1 is on the left side
        var.rightY=wiimote.dot1y
        var.leftY=wiimote.dot2y
     }else{//dot1 is on the left side
        var.rightY=wiimote.dot2y
        var.leftY=wiimote.dot1y
     }
     var.yMin=round((var.rightY+var.leftY)/2)//min X value is found by taking the center location of the two points
     var.centerX=round(var.xMin+((var.xMin+var.xMax)/2))
     var.centerY=round(var.yMin+((var.yMin+var.yMax)/2))
end if
//This part loops infinitely
//find dots
if (wiimote.dot1x>wiimote.dot2x){//dot1 is on the right side
   var.rightX=wiimote.dot1x
   var.rightY=wiimote.dot1y
   var.leftX=wiimote.dot2x
   var.leftY=wiimote.dot2y
}else{//dot1 is on the left side
    var.rightX=wiimote.dot2x
   var.rightY=wiimote.dot2y
   var.leftX=wiimote.dot1x
   var.leftY=wiimote.dot1y
}
if(wiimote.dot1vis==true && wiimote.dot2vis==true){//if both dots are visible
   var.currentX=var.cursorMaxX-var.cursorMaxX*(((var.leftX+((var.rightX-var.leftX)/2))-var.xMin)/(var.xMax-var.xMin))//current x location
   /*var.currentY=var.cursorMaxY*(((var.leftY+((var.rightY-var.leftY)/2))-var.yMin)/(var.yMax-var.yMin))*/ //current y location
}
if (var.currentX>=var.maxTenX){
   keyboard.S=true//keybind for camera swivel right
}else if (var.currentX<=var.minTenX){
   keyboard.A=true//keybind for camera swivel left
}else{//not looking at min or max X
   keyboard.S=false
   keyboard.A=false
}
//"panic" button ESCAPE will stop/exit the program if anything goes wrong
if ESCAPE then
   exitpie
end if

As you can see near the end of the program, if the user's current x location goes within the 10 percent zones (top 10 percent of the right side of the screen or bottom 10 percent of the left side of the screen), the program holds down the corresponding keys. When the zone is exited, the keys are released.

Step 10: Final Thoughts

1. You may have noticed that we saved some variables in the calibration code that were called 'leftSize' and 'rightSize' that were never used. These variables take into account the 'size' (intensity) of the dots and the numbers associated with these variables increase the closer you get to the Wiimote and decrease the father away you get. This could be used as a way to calculated the user's distance from the screen and add another variable to the motion control gaming experience - forward and backward movement. Feel free to mess around with these variables but keep in mind they wont update unless you read/write to the 'leftSize' and 'rightSize' variables in the looping section of the code.

2. GlovePIE has SO many more functionalities in it's language that we have not even brushed on with this project. It's speech recognition abilities, for example, could enable you to add yet another factor to your gaming experience and for those that may have limited mobility and are using the mouse control code, a speech integration to click the mouse or press certain keys might be beneficial.

mouse.LeftButton,mouse.MiddleButton,mouse.RightButton,mouse.XButton1, and mouse.XButton2 all refer to Boolean variables that can be set to either true or false. For example if you wanted to simulate a left click, you could use

mouse.LeftButton=true
wait 0.01s
mouse.LeftButton=false

or a double click would be that function repeated twice with a small wait time after the 'mouse.LeftButton=false'.

3. I have been considering making a system with two angled Wiimote sensors to provide a greater range of movement and extra degrees of freedom. If you would be interested in me posting that here please let me know.

I hope everyone has had an insightful experience with this project whether you decided to build it yourself or just read through this instructable. Any questions, criticisms, or ideas for improvement are welcome either in the comments or via direct message.

-Eric Hill