//**************************************************************************** //GlovePIE WiiMote Script for Operation Wolf style games in MAME //Ted Spinks, gtspinks@hotmail.com, updated 1/29/2009 //DIRECTIONS: In MAME, enable Joystick support. Uses joystick input instead of // mouse input in order to allow 2 players/wiimotes, so PPJoy must be installed // and configured with 2 virtual joysticks (picking all default mappings is fine). // PPJoy can be downloaded from http://www.geocities.com/deonvdw/PPJoy.htm //Testing: Azio USB Blootooth (Toshiba stack), Nyko wireless sensor bar, MAME 104 //Features: uses both sensor bar dots for a wider "target area", has good roll // compensation, supports 2 players/WiiMotes, and the LED's indicate battery // charge % when you press Home. //**************************************************************************** //***************************** Table of Contents ***************************** //Global WiiMote Calibration //P1 Process WiiMote Home button and set WiiMote LED's //P1 Button Inputs //P1 Pre-Process Sensor Bar Dots //P1 Get Left and Right Sensor Bar Dots //P1 Calculate the MidPoint and assign Joystick input //P2 Process WiiMote Home button and set WiiMote LED's //P2 Button Inputs //P2 Pre-Process Sensor Bar Dots //P2 Get Left and Right Sensor Bar Dots //P2 Calculate the MidPoint and assign Joystick input //*************************** End Table of Contents *************************** //*********************** Global WiiMote Calibration ************************* //Set the sensitivity level of the WiiMote. These values must be at least 1. var.SensitivityX = 1.0 //Sensitivity multiplier for X axis var.SensitivityY = 2.0 //Sensitivity multiplier for Y axis //Adjust these values to shift the borders of the "target area" if needed. // For example, you could shift the top or the bottom border to compensate // for the position of your sensor bar (I didn't need to though). var.ShiftLeftSide = 0 //+ to shift right, - to shift left var.ShiftRightSide = 0 //+ to shift right, - to shift left var.ShiftTop = 0 //+ to shift down, - to shift up var.ShiftBottom = 0 //+ to shift down, - to shift up //Leave these values alone. // 1023 and 767 are the max X and Y dot values that the WiiMote can sense var.BeginRangeX = 0 + var.ShiftLeftSide var.EndRangeX= 1023 + var.ShiftRightSide var.BeginRangeY = 0 + var.ShiftTop var.EndRangeY = 767 + var.ShiftBottom var.RangeSizeX = var.EndRangeX - var.BeginRangeX var.RangeSizeY = var.EndRangeY - var.BeginRangeY //Set the midpoint compensation factor. // Since the range of the mindpoint's of the 2 sensor bar dots is approx 1/3 of // the combined ranges of the original 2 dots, after we calculate the midpoint // we have to fix its value range by multiplying by 3. // To figure out the 1/3 I just watched "debug = var.P1MiddleDotX" as I moved // the WiiMote left and right. var.MidpointMultiplierX = 3 //********************** End Global WiiMote Calibration ************************ //*********** P1 Process WiiMote Home button and set WiiMote LED's ************* //Normally Led 1 is lit to indicate this is wiimote #1, // but when Home button is pressed the LED's display battery charge if Pressed(wiimote1.home) then //Do this once when the button is first pressed //Calculate and display battery charge %, full battery is 0xC0 (192) var.P1Battery = Round( 100*wiimote1.battery/192 ) Say "Battery at " + var.P1Battery + " percent" endif if wiimote1.home then var.P1Flash = !var.P1Flash wiimote1.Led1 = var.P1Flash If var.P1Battery > 35 then wiimote1.Led2 = var.P1Flash else wiimote1.Led2 = False endif If var.P1Battery > 60 then wiimote1.Led3 = var.P1Flash else wiimote1.Led3 = false endif If var.P1Battery > 85 then wiimote1.Led4 = var.P1Flash else wiimote1.Led4 = false endif wait 100 ms //Increasing this will slow down the LED flash speed else wiimote1.Led1 = True wiimote1.Led2 = False wiimote1.Led3 = False wiimote1.Led4 = False endif //*********** End P1 WiiMote Home button and set WiiMote LED's ************* //**************************** P1 Button Inputs ***************************** // (see above for Home button behavior) key.LeftControl = Wiimote1.B //key.B = Wiimote1.B key.LeftAlt = Wiimote1.A //key.E = Wiimote1.A key.One = wiimote1.Plus key.Five = wiimote1.Minus key.P = wiimote1.Down key.left= wiimote1.left key.right= wiimote1.right //************************** End P1 Button Inputs *************************** //********************** P1 Pre-Process Sensor Bar Dots *********************** //For each sensor bar dot: //1) Convert the sensor bar dots from the wiimote's range of values to a standard // four quadrant setup with the origin (0,0) in the center. This is needed for // the rotation formula in #2. //2) Do roll compensation for both dots by running them through rotation formula. //3) Convert the dots to standard joystick input range (-1 to +1) //Note: #3 must happen AFTER #2. The native sensor bar dot ranges have the X // and Y ranges at a ratio of about 4:3. Since #3 stretches the Y out and makes // the ratio 1:1, we have to do this after #2, otherwise it will skew the // rotation formula. //get the WiiMote's Roll degrees once var.P1Angle = -1 * smooth(wiimote1.smoothroll, 5, 5) //dot1 if wiimote1.dot1vis then //Shift the dot1 so that its range starts at 0. // Note, this will only have an effect if you adjust the borders of the // target area at the top of the script (i.e. if you change them from 0's) var.P1Dot1X = wiimote1.dot1x - var.BeginRangeX var.P1Dot1Y = wiimote1.dot1y - var.BeginRangeY //Reverse the X and Y values to make the coordinates standard // Note: the WiiMote's dot coordinates are reversed (numbers get larger to // the left and down), so I subtract them from the max X and Y values in // order to flip them. var.P1Dot1X = var.RangeSizeX - var.P1Dot1X var.P1Dot1Y = var.RangeSizeY - var.P1Dot1Y //Now adjust X and Y value ranges so that the origin (0,0) is in the center // this is needed for the rotation formula below, because it rotates points // around the origin. var.P1Dot1X = var.P1Dot1X - (var.RangeSizeX/2) var.P1Dot1Y = var.P1Dot1Y - (var.RangeSizeY/2) //Compensate for roll; I used 2D rotation equations to rotate each // dot around the origin. http://en.wikipedia.org/wiki/Rotation_(mathematics) // Note: every web page I found on the formulas below said they are for // clockwise rotation, but when I put in some test values, they actually // rotate counter clockwise. if var.P1Angle <> 0 then var.FixedP1dot1X = cos(var.P1Angle)*var.P1dot1X - sin(var.P1Angle)*var.P1dot1Y var.FixedP1dot1Y = sin(var.P1Angle)*var.P1dot1X + cos(var.P1Angle)*var.P1dot1Y else var.FixedP1dot1X = var.P1dot1X var.FixedP1dot1Y = var.P1dot1Y endif //Now convert dot1's range to (-1 to +1) // just used good old unit conversion math here var.FixedP1Dot1X = var.FixedP1Dot1X * (2 / var.RangeSizeX) var.FixedP1Dot1Y = var.FixedP1Dot1Y * (2 / var.RangeSizeY) endif //dot2 if wiimote1.dot2vis then //Shift the dot2 so that its range starts at 0. // Note, this will only have an effect if you adjust the borders of the // target area at the top of the script (i.e. if you change them from 0's) var.P1dot2X = wiimote1.dot2x - var.BeginRangeX var.P1dot2Y = wiimote1.dot2y - var.BeginRangeY //Reverse the X and Y values to make the coordinates standard // Note: the WiiMote's dot coordinates are reversed (numbers get larger to // the left and down), so I subtract them from the max X and Y values in // order to flip them. var.P1dot2X = var.RangeSizeX - var.P1dot2X var.P1dot2Y = var.RangeSizeY - var.P1dot2Y //Now adjust X and Y value ranges so that the origin (0,0) is in the center // this is needed for the rotation formula below, because it rotates points // around the origin. var.P1dot2X = var.P1dot2X - (var.RangeSizeX/2) var.P1dot2Y = var.P1dot2Y - (var.RangeSizeY/2) //Compensate for roll; I used 2D rotation equations to rotate each // dot around the origin. http://en.wikipedia.org/wiki/Rotation_(mathematics) // Note: every web page I find on the formulas below said they are for // clockwise rotation, but when I put in some test values, they actually // rotate counter clockwise. if var.P1Angle <> 0 then var.FixedP1dot2X = cos(var.P1Angle)*var.P1dot2X - sin(var.P1Angle)*var.P1dot2Y var.FixedP1dot2Y = sin(var.P1Angle)*var.P1dot2X + cos(var.P1Angle)*var.P1dot2Y else var.FixedP1dot2X = var.P1dot2X var.FixedP1dot2Y = var.P1dot2Y endif //Now convert dot2's range to (-1 to +1) // just used good old unit conversion math here var.FixedP1dot2X = var.FixedP1dot2X * (2 / var.RangeSizeX) var.FixedP1dot2Y = var.FixedP1dot2Y * (2 / var.RangeSizeY) endif //******************** End P1 Pre-Process Sensor Bar Dots ********************* //****************** P1 Get Left and Right Sensor Bar Dots ******************** if wiimote1.dot1vis and wiimote1.dot2vis then //Both sensor bar dots are visible //Figure out which sensor bar dot is left and which is right if var.FixedP1Dot1X < var.FixedP1Dot2X then //the left dot must be dot1, and the right dot must be dot2 var.P1LeftDotX = var.FixedP1Dot1X var.P1LeftDotY = var.FixedP1Dot1Y var.P1RightDotX = var.FixedP1Dot2X var.P1RightDotY = var.FixedP1Dot2Y else //else the left dot must be dot2, and the right dot must be dot1 var.P1LeftDotX = var.FixedP1Dot2X var.P1LeftDotY = var.FixedP1Dot2Y var.P1RightDotX = var.FixedP1Dot1X var.P1RightDotY = var.FixedP1Dot1Y endif var.P1LastMidpointX = (var.P1LeftDotx + var.P1RightDotx)/2 var.P1PointedOnScreen = True //Save the previous distance (for use in the safety check below) var.OldP1DistBtwDots = var.P1DistBtwDots //Whenever both dots are visible calculate the distance between them var.P1DistBtwDots = var.P1RightDotx - var.P1LeftDotx //Make sure one of the dots didn't just disappear; if it did then //throw away this data. After a dot has just disappeared and has // stopped updating its X value, it may still register as visible // for a split second; I've seen this cause the distance to be // recorded at around 30. Weird. if !(wiimote1.dot1vis and wiimote1.dot2vis) then var.P1DistBtwDots = var.OldP1DistBtwDots var.P1PointedOnScreen = false endif elseif wiimote1.dot1vis and (var.P1DistBtwDots > 0) then //Only dot1 is visible, so we'll calculate a position for dot2 // Note, (var.P1DistBtwDots > 0) will be true as long as both dots have // been visable at least once. //Figure out if this is the left or the right dot if (var.FixedP1Dot1X < var.P1LastMidpointX) then //dot1 must be the left dot var.P1LeftDotX = var.FixedP1Dot1X var.P1LeftDotY = var.FixedP1Dot1Y var.P1RightDotX = var.FixedP1Dot1X + var.P1DistBtwDots //simulate right dot var.P1RightDotY = var.FixedP1Dot1Y else //else dot1 must be the right dot var.P1LeftDotX = var.FixedP1Dot1X - var.P1DistBtwDots //simulate left dot var.P1LeftDotY = var.FixedP1Dot1Y var.P1RightDotX = var.FixedP1Dot1X var.P1RightDotY = var.FixedP1Dot1Y endif var.P1LastMidpointX = (var.P1LeftDotx + var.P1RightDotx)/2 var.P1PointedOnScreen = True elseif wiimote1.dot2vis and (var.P1DistBtwDots > 0) then //Only dot2 is visible, so we'll calculate a position for dot1 // Note, (var.P1DistBtwDots > 0) will be true as long as both dots have // been visable at least once. //Figure out if this is the left or the right dot if (var.FixedP1Dot2X < var.P1LastMidpointX) then //dot2 must be the left dot var.P1LeftDotX = var.FixedP1Dot2X var.P1LeftDotY = var.FixedP1Dot2Y var.P1RightDotX = var.FixedP1Dot2X + var.P1DistBtwDots //simulate right dot var.P1RightDotY = var.FixedP1Dot2Y else //else dot2 must be the right dot var.P1LeftDotX = var.FixedP1Dot2X - var.P1DistBtwDots //simulate left dot var.P1LeftDotY = var.FixedP1Dot2Y var.P1RightDotX = var.FixedP1Dot2X var.P1RightDotY = var.FixedP1Dot2Y endif var.P1LastMidpointX = (var.P1LeftDotx + var.P1RightDotx)/2 var.P1PointedOnScreen = True else // else no dots are visible var.P1PointedOnScreen = False endif //debug=var.P1LeftDotX + "," + var.P1LeftDotY + " " + var.P1RightDotX + "," + var.P1RightDotY //**************** End P1 Get Left and Right Sensor Bar Dots ***************** //************** P1 Calculate the MidPoint and assign Joystick input **************** if var.P1PointedOnScreen then //Calculate the midpoint of the sensor bar dots var.P1MiddleDotX = (var.P1LeftDotx + var.P1RightDotx)/2 var.P1MiddleDotY = (var.P1LeftDoty + var.P1RightDoty)/2 //debug = var.P1MiddleDotX //Since the mindpoint's range is approx 1/3 of the ranges of the original // 2 dots, fix the range of the MidPoint's X value by multiplying by 3. // Note, I didn't do any fancy math to figure this out, I just watched // "debug = var.P1MiddleDotX" as I moved the WiiMote left and right. I think // the 1/3 could change depending on the size of your sensor bar and how near/far // it is from the WiiMote. var.P1MiddleDotX = var.P1MiddleDotX * var.MidpointMultiplierX //Apply sensitivity multipliers var.P1MiddleDotX = var.P1MiddleDotX * var.SensitivityX var.P1MiddleDotY = var.P1MiddleDotY * var.SensitivityY //Keep values within allowable joystick range If var.P1MiddleDotX > 1 Then var.P1MiddleDotX = 1 If var.P1MiddleDotX < -1 Then var.P1MiddleDotX = -1 If var.P1MiddleDotY > 1 Then var.P1MiddleDotY = 1 If var.P1MiddleDotY < -1 Then var.P1MiddleDotY = -1 //Flip the Y value, since joystick Y input is always reversed var.P1MiddleDotY = var.P1MiddleDotY * -1 PPJoy1.Analog0 = var.P1MiddleDotX PPJoy1.Analog1 = var.P1MiddleDotY //debug = var.P1MiddleDotX + "," + var.P1MiddleDotY endif //************ End P1 Calculate the MidPoint and assign Joystick input ************** //*********** P2 Process WiiMote Home button and set WiiMote LED's ************* //Normally Led 2 is lit to indicate this is wiimote #2, // but when Home button is pressed the LED's display battery charge if Pressed(wiimote2.home) then //Do this once when the button is first pressed //Calculate and display battery charge %, full battery is 0xC0 (192) var.P2Battery = Round( 100*wiimote2.battery/192 ) Say "Battery at " + var.P2Battery + " percent" endif if wiimote2.home then var.P2Flash = !var.P2Flash wiimote2.Led1 = var.P2Flash If var.P2Battery > 35 then wiimote2.Led2 = var.P2Flash else wiimote2.Led2 = False endif If var.P2Battery > 60 then wiimote2.Led3 = var.P2Flash else wiimote2.Led3 = false endif If var.P2Battery > 85 then wiimote2.Led4 = var.P2Flash else wiimote2.Led4 = false endif wait 100 ms //Increasing this will slow down the LED flash speed else wiimote2.Led1 = False wiimote2.Led2 = True wiimote2.Led3 = False wiimote2.Led4 = False endif //*********** End P2 WiiMote Home button and set WiiMote LED's ************* //**************************** P2 Button Inputs ***************************** // (see above for Home button behavior) //mouse.LeftButton = wiimote2.B key.A = wiimote2.B key.S = wiimote2.A key.Two = wiimote2.Plus key.Six = wiimote2.Minus key.P = wiimote2.Down key.left= wiimote2.left key.right= wiimote2.right //************************** End P2 Button Inputs *************************** //********************** P2 Pre-Process Sensor Bar Dots *********************** //For each sensor bar dot: //1) Convert the sensor bar dots from the wiimote's range of values to a standard // four quadrant setup with the origin (0,0) in the center. This is needed for // the rotation formula in #2. //2) Do roll compensation for both dots by running them through rotation formula. //3) Convert the dots to standard joystick input range (-1 to +1) //Note: #3 must happen AFTER #2. The native sensor bar dot ranges have the X // and Y ranges at a ratio of about 4:3. Since #3 stretches the Y out and makes // the ratio 1:1, we have to do this after #2, otherwise it will skew the // rotation formula. //get the WiiMote's Roll degrees once var.P2Angle = -1 * smooth(wiimote2.smoothroll, 5, 5) //dot1 if wiimote2.dot1vis then //Shift the dot1 so that its range starts at 0. // Note, this will only have an effect if you adjust the borders of the // target area at the top of the script (i.e. if you change them from 0's) var.P2Dot1X = wiimote2.dot1x - var.BeginRangeX var.P2Dot1Y = wiimote2.dot1y - var.BeginRangeY //Reverse the X and Y values to make the coordinates standard // Note: the WiiMote's dot coordinates are reversed (numbers get larger to // the left and down), so I subtract them from the max X and Y values in // order to flip them. var.P2Dot1X = var.RangeSizeX - var.P2Dot1X var.P2Dot1Y = var.RangeSizeY - var.P2Dot1Y //Now adjust X and Y value ranges so that the origin (0,0) is in the center // this is needed for the rotation formula below, because it rotates points // around the origin. var.P2Dot1X = var.P2Dot1X - (var.RangeSizeX/2) var.P2Dot1Y = var.P2Dot1Y - (var.RangeSizeY/2) //Compensate for roll; I used 2D rotation equations to rotate each // dot around the origin. http://en.wikipedia.org/wiki/Rotation_(mathematics) // Note: every web page I find on the formulas below said they are for // clockwise rotation, but when I put in some test values, they actually // rotate counter clockwise. if var.P2Angle <> 0 then var.FixedP2dot1X = cos(var.P2Angle)*var.P2dot1X - sin(var.P2Angle)*var.P2dot1Y var.FixedP2dot1Y = sin(var.P2Angle)*var.P2dot1X + cos(var.P2Angle)*var.P2dot1Y else var.FixedP2dot1X = var.P2dot1X var.FixedP2dot1Y = var.P2dot1Y endif //Now convert dot1's range to (-1 to +1) // just used good old unit conversion math here var.FixedP2Dot1X = var.FixedP2Dot1X * (2 / var.RangeSizeX) var.FixedP2Dot1Y = var.FixedP2Dot1Y * (2 / var.RangeSizeY) endif //dot2 if wiimote2.dot2vis then //Shift the dot2 so that its range starts at 0. // Note, this will only have an effect if you adjust the borders of the // target area at the top of the script (i.e. if you change them from 0's) var.P2dot2X = wiimote2.dot2x - var.BeginRangeX var.P2dot2Y = wiimote2.dot2y - var.BeginRangeY //Reverse the X and Y values to make the coordinates standard // Note: the WiiMote's dot coordinates are reversed (numbers get larger to // the left and down), so I subtract them from the max X and Y values in // order to flip them. var.P2dot2X = var.RangeSizeX - var.P2dot2X var.P2dot2Y = var.RangeSizeY - var.P2dot2Y //Now adjust X and Y value ranges so that the origin (0,0) is in the center // this is needed for the rotation formula below, because it rotates points // around the origin. var.P2dot2X = var.P2dot2X - (var.RangeSizeX/2) var.P2dot2Y = var.P2dot2Y - (var.RangeSizeY/2) //Compensate for roll; I used 2D rotation equations to rotate each // dot around the origin. http://en.wikipedia.org/wiki/Rotation_(mathematics) // Note: every web page I find on the formulas below said they are for // clockwise rotation, but when I put in some test values, they actually // rotate counter clockwise. if var.P2Angle <> 0 then var.FixedP2dot2X = cos(var.P2Angle)*var.P2dot2X - sin(var.P2Angle)*var.P2dot2Y var.FixedP2dot2Y = sin(var.P2Angle)*var.P2dot2X + cos(var.P2Angle)*var.P2dot2Y else var.FixedP2dot2X = var.P2dot2X var.FixedP2dot2Y = var.P2dot2Y endif //Now convert dot2's range to (-1 to +1) // just used good old unit conversion math here var.FixedP2dot2X = var.FixedP2dot2X * (2 / var.RangeSizeX) var.FixedP2dot2Y = var.FixedP2dot2Y * (2 / var.RangeSizeY) endif //******************** End P2 Pre-Process Sensor Bar Dots ********************* //****************** P2 Get Left and Right Sensor Bar Dots ******************** if wiimote2.dot1vis and wiimote2.dot2vis then //Both sensor bar dots are visible //Figure out which sensor bar dot is left and which is right if var.FixedP2Dot1X < var.FixedP2Dot2X then //the left dot must be dot1, and the right dot must be dot2 var.P2LeftDotX = var.FixedP2Dot1X var.P2LeftDotY = var.FixedP2Dot1Y var.P2RightDotX = var.FixedP2Dot2X var.P2RightDotY = var.FixedP2Dot2Y else //else the left dot must be dot2, and the right dot must be dot1 var.P2LeftDotX = var.FixedP2Dot2X var.P2LeftDotY = var.FixedP2Dot2Y var.P2RightDotX = var.FixedP2Dot1X var.P2RightDotY = var.FixedP2Dot1Y endif var.P2LastMidpointX = (var.P2LeftDotx + var.P2RightDotx)/2 var.P2PointedOnScreen = True //Save the previous distance (for use in the safety check below) var.OldP2DistBtwDots = var.P2DistBtwDots //Whenever both dots are visible calculate the distance between them var.P2DistBtwDots = var.P2RightDotx - var.P2LeftDotx //Make sure one of the dots didn't just disappear; if it did then //throw away this data. After a dot has just disappeared and has // stopped updating its X value, it may still register as visible // for a split second; I've seen this cause the distance to be // recorded at around 30. Weird. if !(wiimote2.dot1vis and wiimote2.dot2vis) then var.P2DistBtwDots = var.OldP2DistBtwDots var.P2PointedOnScreen = false endif elseif wiimote2.dot1vis and (var.P2DistBtwDots > 0) then //Only dot1 is visible, so we'll calculate a position for dot2 // Note, (var.P2DistBtwDots > 0) will be true as long as both dots have // been visable at least once. //Figure out if this is the left or the right dot if (var.FixedP2Dot1X < var.P2LastMidpointX) then //dot1 must be the left dot var.P2LeftDotX = var.FixedP2Dot1X var.P2LeftDotY = var.FixedP2Dot1Y var.P2RightDotX = var.FixedP2Dot1X + var.P2DistBtwDots //simulate right dot var.P2RightDotY = var.FixedP2Dot1Y else //else dot1 must be the right dot var.P2LeftDotX = var.FixedP2Dot1X - var.P2DistBtwDots //simulate left dot var.P2LeftDotY = var.FixedP2Dot1Y var.P2RightDotX = var.FixedP2Dot1X var.P2RightDotY = var.FixedP2Dot1Y endif var.P2LastMidpointX = (var.P2LeftDotx + var.P2RightDotx)/2 var.P2PointedOnScreen = True elseif wiimote2.dot2vis and (var.P2DistBtwDots > 0) then //Only dot2 is visible, so we'll calculate a position for dot1 // Note, (var.P2DistBtwDots > 0) will be true as long as both dots have // been visable at least once. //Figure out if this is the left or the right dot if (var.FixedP2Dot2X < var.P2LastMidpointX) then //dot2 must be the left dot var.P2LeftDotX = var.FixedP2Dot2X var.P2LeftDotY = var.FixedP2Dot2Y var.P2RightDotX = var.FixedP2Dot2X + var.P2DistBtwDots //simulate right dot var.P2RightDotY = var.FixedP2Dot2Y else //else dot2 must be the right dot var.P2LeftDotX = var.FixedP2Dot2X - var.P2DistBtwDots //simulate left dot var.P2LeftDotY = var.FixedP2Dot2Y var.P2RightDotX = var.FixedP2Dot2X var.P2RightDotY = var.FixedP2Dot2Y endif var.P2LastMidpointX = (var.P2LeftDotx + var.P2RightDotx)/2 var.P2PointedOnScreen = True else // else no dots are visible var.P2PointedOnScreen = False endif //debug=var.P2LeftDotX + "," + var.P2LeftDotY + " " + var.P2RightDotX + "," + var.P2RightDotY //**************** End P2 Get Left and Right Sensor Bar Dots ***************** //************** P2 Calculate the MidPoint and assign Joystick input **************** if var.P2PointedOnScreen then //Calculate the midpoint of the sensor bar dots var.P2MiddleDotX = (var.P2LeftDotx + var.P2RightDotx)/2 var.P2MiddleDotY = (var.P2LeftDoty + var.P2RightDoty)/2 //debug = var.P2MiddleDotX //Since the mindpoint's range is approx 1/3 of the ranges of the original // 2 dots, fix the range of the MidPoint's X value by multiplying by 3. // Note, I didn't do any fancy math to figure this out, I just watched // "debug = var.P2MiddleDotX" as I moved the WiiMote left and right. I think // the 1/3 could change depending on the size of your sensor bar and how near/far // it is from the WiiMote. var.P2MiddleDotX = var.P2MiddleDotX * var.MidpointMultiplierX //Apply sensitivity multipliers var.P2MiddleDotX = var.P2MiddleDotX * var.SensitivityX var.P2MiddleDotY = var.P2MiddleDotY * var.SensitivityY //Keep values within allowable joystick range If var.P2MiddleDotX > 1 Then var.P2MiddleDotX = 1 If var.P2MiddleDotX < -1 Then var.P2MiddleDotX = -1 If var.P2MiddleDotY > 1 Then var.P2MiddleDotY = 1 If var.P2MiddleDotY < -1 Then var.P2MiddleDotY = -1 //Flip the Y value, since joystick Y input is always reversed var.P2MiddleDotY = var.P2MiddleDotY * -1 PPjoy2.Analog0 = var.P2MiddleDotX PPjoy2.Analog1 = var.P2MiddleDotY endif //************ End P2 Calculate the MidPoint and assign Joystick input **************