Sponsors of Wiimoteproject.com
IR Pens for Wiimote Whiteboard
Wiimote Project » Wiimote Projects » Wiimote Glovepie projects » Wii MotionPlus & IR Mouse (script) - Updated: March 09, 2011
Pages: [1] 2
  Print  
Author Topic: Wii MotionPlus & IR Mouse (script) - Updated: March 09, 2011  (Read 36219 times)
0 Members and 1 Guest are viewing this topic.
*
Karma: +0/-0
Posts: 8
Offline Offline
View Profile
« on: January 08, 2010, 01:42:36 PM »

Update: Mar 09, 2011
- Completely new version, written from scratch
- Combines Wii MotionPlus with Sensor Bar, or can use just one or the other
- Hold B to keep mouse still
- Double-click B to center mouse

Update: Jan 28, 2010
- Bugfix: Using wiimote.Roll instead of wiimote.SmoothRoll for var.Roll
This was causing a slight upward drift when moving side to side.

Update: Jan 27, 2010
- Dynamic Motion Smoothing
- "HoldToMove" now an option
- Calibration scrapped, just uses GlovePIE's instead
- Overall code cleanup

Update: Jan 24, 2010
- Checks GlovePIE's calibration, uses it's own "secondary" calibration if there's a problem
- Wiimote battery check (Home button)
- Friendly debug messages
- Various fixes and adjustments
- To-Do list on bottom

Code:
/*
    Wii MotionPlus and IR Mouse                                  v 2011.03.09
    by lednerg

    Control the mouse with the Wii MotionPlus accessory and the Sensor Bar.
    You can combine both or just use one or the other.
    This is just meant to be used in Windows, not for FPS games.
   
    Requires GlovePIE version .42 or higher.

    Leave the Wiimote on your desk when starting so it can calibrate.
    Wait until only the first LED is lit.
    When using MotionPlus with Sensor Bar,
      move the pointer back and forth diagonally so it can adjust itself.
    If there is a lot of drift from the MotionPlus, press Home to re-calibrate.

    A = Left-Click, Plus = Right-Click, Minus = Middle-Click
    B = Hold mouse still
    Double-Click B = Reset mouse to center
    2 + Roll Wiimote = Adjust zoom
    Home = Re-calibrate
*/

// ==== Buttons ================================================================

var.LeftMouseButton = wiimote.A
var.RightMouseButton = wiimote.Plus
var.MiddleMouseButton = wiimote.Minus

var.HoldButton = wiimote.B                   // Holds mouse still
var.ResetButton = DoubleClicked(wiimote.B)   // Resets mouse to center
var.ZoomButton = wiimote.Two                 // Hold and then roll to zoom
var.RecalibrateButton = wiimote.Home         // Press and place Wiimote down

// ==== Options ================================================================

GlovePIE.FrameRate = 100hz

var.Zoom = 1.20                         
var.MaxSmooth = 95
var.IgnoreSensorBar = false

// ==== Script =================================================================
if HeldDown(not starting, 2s) and (var.started = false) and wiimote.Exists then toggle(var.started)
if wiimote.Exists = false then var.started = false
if pressed(var.RecalibrateButton) or delta(var.started) {
   // Don't bother changing any of these numbers.
   var.wmCalYP = [ 0, 2 ]
   var.wmDeadZone = 0
   toggle(var.wmCalON)
   [ var.wm_x, var.wm_y ] = [ .5, .5 ]
   [ var.WMIR_x, var.WMIR_y ] = [ 0, 0 ]
   [ var.wmMin_x, var.wmMax_x ] = [ .365, .635 ]
   [ var.irMin_x, var.irMax_x ] = [ .333, .667 ]
   [ var.wmMin_y, var.wmMax_y ] = [ .400, .600 ]
   [ var.irMin_y, var.irMax_y ] = [ .333, .667 ]
   [ var.Hold_x, var.Hold_y ] = [ 0, 0 ]
   [ var.Recenter_x, var.Recenter_y ] = [ 0, 0 ]
}
// ### Calibration
if var.wmCalON = true {
   var.wmCalDiff = EnsureMapRange(|var.wmCalYP|, 0, 1, .01, .5)
   [ var.wmCalYaw, var.wmCalPitch ] = [ var.wmCalYaw, var.wmCalPitch ] * (1-var.wmCalDiff) + var.wmSpeedYP_IN * var.wmCalDiff
   var.wmStill = |var.wmCalYP| < 2 // this will be true while wiimote is ready to be calibrated.
   var.wmMoved = var.wmMoved * .95 + ((|var.wmCalYP|<3)* |var.wmCalYP|) * .05
   if var.wmMoved < .0001 then var.wmDeadZone = 0
   if HeldDown(var.wmStill, 2s) and |var.wmCalYP| > var.wmDeadZone then var.wmDeadZone = |var.wmCalYP|
   if HeldDown(var.wmStill, 5s) then toggle(var.wmCalON)
   if smooth(|wiimote.MotionPlus.RawYawSpeed|, 29) = 0 then var.wmCalYaw = 0
   if smooth(|wiimote.MotionPlus.RawPitchSpeed|, 29) = 0 then var.wmCalPitch = 0
}
// ### Cancel calibration after 15 seconds and reset variables
if HeldDown(var.wmCalON, 15s) and not HeldDown(var.wmStill, 2s) {
   var.wmCalYaw = 0
   var.wmCalPitch = 0
   var.wmDeadZone = 0
   toggle(var.ErrorON)
   toggle(var.wmCalON)
}
// ### Calibration LED Countdown - resets when wiimote is moved
if var.wmCalON then wiimote.Leds = 15 - HeldDown(var.wmStill, 1s) * 1 - HeldDown(var.wmStill, 2s) * 2 - HeldDown(var.wmStill, 3s) * 4 - HeldDown(var.wmStill, 4s) * 8 else wiimote.Leds = 1 + var.ErrorLED
// ### LED Error Flash
if var.ErrorON {
   var.ErrorLED = ( var.ErrorLED <= 0 ) * 14 - ( var.ErrorLED > 0 ) * 1
   wait .1s
   var.ErrorON = var.ErrorON - .02 // (when var.ErrorON reaches .5 it will be false)
else
   if starting then var.ErrorLED = 15
   if var.started then var.ErrorLED = 0
}
// ### Roll - Combines accelerometer and gyroscope roll measurements
var.aRoll_360 = var.aRoll_360 - ((delta(wiimote.Roll) > 100) * 360) + ((delta(wiimote.Roll) < -100) * 360)
var.aRoll_diff = EnsureMapRange(abs(wiimote.Roll - var.aRoll_deg), 1, 10, .01, .05)
var.aRoll_deg = var.aRoll_deg * (1 - var.aRoll_diff) + (wiimote.Roll + var.aRoll_360) * var.aRoll_diff
var.aRoll = RemoveUnits(var.aRoll_deg)
var.gRoll = ( var.Roll + delta(RemoveUnits(wiimote.MotionPlus.GyroRoll)))
var.gaMinus = abs(var.gRoll - var.aRoll)
if HeldDown(var.gaMinus>3, 1s) then var.g_to_aRoll = true
if var.g_to_aRoll = true then var.g_to_aRoll = (var.gaMinus > .1)
if var.g_to_aRoll = true then var.gRoll = var.gRoll + ( - ((var.gRoll - var.aRoll)>0) * var.gaMinus * .1 + ((var.gRoll - var.aRoll)<0) * var.gaMinus * .1 )
var.Roll = var.aRoll * (var.gaMinus<.5) + var.gRoll * (var.gaMinus>.5)
// ### Wii MotionPlus - Converts [ angle & speed ] to [ X & Y ]. Accounts for Roll.
var.wmSpeedYP_IN = [ wiimote.MotionPlus.RawYawSpeed, wiimote.MotionPlus.RawPitchSpeed ]
var.wmCalYP = var.wmSpeedYP_IN - [ var.wmCalYaw, var.wmCalPitch ]
if var.wmCalYP < var.wmDeadZone then var.wmSpeedYP = [ 0, 0 ] else var.wmSpeedYP = var.wmCalYP
[ var.wmSpeedYaw, var.wmSpeedPitch ] = var.wmSpeedYP / RemoveUnits(PIE.FrameRate)
var.wmAngle = atan2(var.wmSpeedYaw, -var.wmSpeedPitch) - var.Roll
var.wmSpeed = [ var.wmSpeedYaw, -var.wmSpeedPitch ]
[ var.wmRollFix_x, var.wmRollFix_y ] = [ sin(var.wmAngle), cos(var.wmAngle) ] * |var.wmSpeed|
if var.started = true and var.wmCalON = false {
   [ var.wm_x, var.wm_y ] = [ var.wm_x, var.wm_y ] + [ var.wmRollFix_x, var.wmRollFix_y ] * .015
   if var.started = true {
      var.wmSpeed_x = var.wmSpeed_x * .8 + abs(delta(var.wm_x)) * 1000
      var.wmSpeed_y = var.wmSpeed_y * .8 + abs(delta(var.wm_y)) * 1000
      var.wmSpeed_xy = [ var.wmSpeed_x, var.wmSpeed_y ]
   }
}
// ### IR Sensor Bar
if wiimote.dot1vis and wiimote.dot2vis and not var.IgnoreSensorBar {
   // Resets Hold and Recentering when IR is seen for the first time
   if var.UsedIR = false {
      [ var.Hold_x, var.Hold_y ] = [ 0, 0 ]
      [ var.Recenter_x, var.Recenter_y ] = [ 0, 0 ]
      var.UsedIR = true
   }
   // Finds mid-point of dot1 and dot2
   var.irDot1_xy = [ (512 - wiimote.dot1x) / 1024, (wiimote.dot1y - 384) / 768 ]
   var.irDot2_xy = [ (512 - wiimote.dot2x) / 1024, (wiimote.dot2y - 384) / 768 ]
   [ var.irMid_x, var.irMid_y ] = ( var.irDot1_xy + var.irDot2_xy ) / 2
   // Finds angle of dots for Roll
   var.irMid_angle = atan2( var.irMid_x, var.irMid_y )
   var.irMid_length = [ var.irMid_x, var.irMid_y ]
   var.irNew_angle = var.irMid_angle - var.Roll
   var.irNew_xy = [ sin(var.irNew_angle) , cos(var.irNew_angle) ] * |var.irMid_length|
   [ var.ir_x, var.ir_y ] = var.irNew_xy + [ .5, .5 ]
   var.irSpeed_x = var.irSpeed_x * .8 + abs(delta(var.ir_x)) * 1000
   var.irSpeed_y = var.irSpeed_y * .8 + abs(delta(var.ir_y)) * 1000
   var.irSpeed_xy = [ var.irSpeed_x , var.irSpeed_y ]
   // Matches IR and Wii MotionPlus Position and Scale
   if (var.irSpeed_x < 40 and var.wmSpeed_x < 40) {
      if ((var.ir_x < var.irMin_x) or (var.MinMax_x = 2 and (var.irMax_x - var.ir_x) >= .15)) and ((var.wmMax_x - var.wm_x) > .075) {
         [ var.wmMin_x, var.irMin_x ] = [ var.wm_x, var.ir_x ]
         var.MinMax_x = 1
      }
      if ((var.ir_x > var.irMax_x) or (var.MinMax_x = 1 and (var.ir_x - var.irMin_x) >= .15)) and ((var.wm_x - var.wmMin_x) > .075) {
         [ var.wmMax_x, var.irMax_x ] = [ var.wm_x, var.ir_x ]
         var.MinMax_x = 2
      }
   }
   if (var.irSpeed_y < 40 and var.wmSpeed_y < 40) {
      if ((var.ir_y < var.irMin_y) or (var.MinMax_y = 2 and (var.irMax_y - var.ir_y) >= .15)) and ((var.wmMax_y - var.wm_y) > .075) {
         [ var.wmMin_y, var.irMin_y ] = [ var.wm_y, var.ir_y ]
         var.MinMax_y = 1
      }
      if ((var.ir_y > var.irMax_y) or (var.MinMax_y = 1 and (var.ir_y - var.irMin_y) >= .15)) and ((var.wm_y - var.wmMin_y) > .075) {
         [ var.wmMax_y, var.irMax_y ] = [ var.wm_y, var.ir_y ]
         var.MinMax_y = 2
      }
   }
   if var.WMIR_switch = 1 {
      [ var.IR_adj_x , var.IR_adj_y ] = [ var.Old_WM_x, var.Old_WM_y ] - [ var.ir_x, var.ir_y ]
      var.WMIR_switch = 0
   }
   if var.WMIR_switch = 0 {
      [ var.Rough_x , var.Rough_y ] = ([ var.ir_x, var.ir_y ] + [ var.IR_adj_x , var.IR_adj_y ] - [ .5, .5 ]) * var.NewZoom + [ .5, .5 ]
      [ var.WMIR_x, var.WMIR_y ] = [ var.wmNew_x , var.wmNew_y ] - [ var.ir_x , var.ir_y ]
      var.WMIR_xy = [ var.WMIR_x, var.WMIR_y ]
      var.IR_adj_c = 1 - EnsureRange(|var.WMIR_xy|, 0, .5) / 5
      [ var.IR_adj_x , var.IR_adj_y ] = [ var.IR_adj_x , var.IR_adj_y ] * var.IR_adj_c
   }
   [ var.WMIR_cal_x, var.WMIR_cal_y ] = [ var.wm_x, var.wm_y ] - [ var.ir_x, var.ir_y ]
else  // (if no IR dots visible)
   [ var.Rough_x , var.Rough_y ] = ([ var.wmNew_x, var.wmNew_y ] - [ var.WMIR_x, var.WMIR_y ] + [ var.IR_adj_x , var.IR_adj_y ] - [ .5, .5 ]) * var.NewZoom + [ .5, .5 ]
   [ var.Old_WM_x, var.Old_WM_y ] = ([ var.Rough_x , var.Rough_y ] - [ .5, .5 ]) / var.NewZoom + [ .5, .5 ]
   var.WMIR_switch = 1
   var.WMIR_xy = [ 0, 0 ]
   if var.started = true and var.wmCalON = false then [ var.ir_x, var.ir_y ] = ([ var.Smooth_x , var.Smooth_y ] - [ .5, .5 ]) / var.NewZoom + [ .5, .5 ]
}
// ### WM / IR Ratio Checking
if (var.ratio = 0) or (var.ratio = 1) or IsNAN(var.ratio) then var.ratio = var.ra
if var.ra != 1 and abs(delta(var.ra))>0 then var.ratio = var.ratio * var.rb + var.ra * (1-var.rb)
var.ra = ((var.wmMax_x - var.wmMin_x)/(var.wmMax_y - var.wmMin_y))/((var.irMax_x - var.irMin_x)/(var.irMax_y - var.irMin_y))
if abs(delta(var.ra))>0 then var.rb = .9975
if abs(var.ratio - var.ra) < .05 {
   if ( HeldDown(delta(var.wmMin_x)=0, 2s) = false ) and  ( HeldDown(delta(var.wmMax_x)=0, 2s) = false ) then [ var.wmNewMin_x, var.wmNewMax_x ] = [ var.wmMin_x, var.wmMax_x ]
   if ( HeldDown(delta(var.wmMin_y)=0, 2s) = false ) and  ( HeldDown(delta(var.wmMax_y)=0, 2s) = false ) then [ var.wmNewMin_y, var.wmNewMax_y ] = [ var.wmMin_y, var.wmMax_y ]
   if ( HeldDown(delta(var.irMin_x)=0, 2s) = false ) and  ( HeldDown(delta(var.irMax_x)=0, 2s) = false ) then [ var.irNewMin_x, var.irNewMax_x ] = [ var.irMin_x, var.irMax_x ]
   if ( HeldDown(delta(var.irMin_y)=0, 2s) = false ) and  ( HeldDown(delta(var.irMax_y)=0, 2s) = false ) then [ var.irNewMin_y, var.irNewMax_y ] = [ var.irMin_y, var.irMax_y ]
}
// ### Map WM to IR
var.wmNew_x = MapRange( var.wm_x, var.wmNewMin_x, var.wmNewMax_x, var.irNewMin_x, var.irNewMax_x  )
var.wmNew_y = MapRange( var.wm_y, var.wmNewMin_y, var.wmNewMax_y, var.irNewMin_y, var.irNewMax_y  )
// ### Mouse Movement Smoothing
if IsInfinite(var.Smooth_x + var.Smooth_y) or IsNaN(var.Smooth_x + var.Smooth_y) then [ var.Smooth_x , var.Smooth_y ] = [ var.Rough_x , var.Rough_y ]
var.Smooth_delta = [ delta(var.Rough_x) , delta(var.Rough_y) ]
var.Smooth_c = EnsureRange(var.Smooth_c * .95 + (|var.Smooth_delta| * 100) * .05 , 1-EnsureRange(sqrt(var.MaxSmooth)/10, .00001, .99999), 1)
if IsInfinite(var.Smooth_c) or IsNaN(var.Smooth_c) then var.Smooth_c = 1
[ var.Smooth_x, var.Smooth_y ] = [ var.Smooth_x, var.Smooth_y ] * (1-var.Smooth_c) + [ var.Rough_x , var.Rough_y ] * var.Smooth_c
// ### Zoom Button
if delta(var.ZoomButton) then var.ZoomFrom = var.Roll/500
if var.ZoomButton then var.ZoomShift = var.ZoomShift + delta(var.Roll)/500 //(var.Roll/500 - var.ZoomFrom)
var.NewZoom = EnsureRange(var.Zoom + var.ZoomShift, .01, 100)
// ### Zoom Cursors
[ cursor1.Visible, cursor7.Visible ] = [ 1, 1 ] * var.ZoomButton + [ 1, 1 ] * KeepDown(delta(var.ZoomButton)<0, 1 second)
[ cursor13.Visible, cursor19.Visible ] = [ 1, 1 ] * var.ZoomButton + [ 1, 1 ] * KeepDown(delta(var.ZoomButton)<0, 1 second)
[ cursor1.x, cursor1.y ] = [ -.5, 0 ] * var.NewZoom + [ .5, .5 ]
[ cursor7.x, cursor7.y ] = [ -.16666, 0 ] * var.NewZoom + [ .5, .5 ]
[ cursor13.x, cursor13.y ] = [ .16666, 0 ] * var.NewZoom + [ .5, .5 ]
[ cursor19.x, cursor19.y ] = [ .5, 0 ] * var.NewZoom + [ .5, .5 ]
// ### Reset, Hold, and Mouse
if var.ResetButton then [ var.Recenter_x, var.Recenter_y ] = [ var.Smooth_x, var.Smooth_y ] - [ var.Hold_x, var.Hold_y ] - [ .5, .5 ]
if var.started and wiimote.Exists and not var.wmCalON {
   if not HeldDown(var.HoldButton, 50ms) {
      [ mouse.x, mouse.y ] = [ var.Smooth_x, var.Smooth_y ] - [ var.Recenter_x, var.Recenter_y ] - [ var.Hold_x, var.Hold_y ]
   else
      [ var.Hold_x, var.Hold_y ] = [ var.Smooth_x, var.Smooth_y ] - [ var.Recenter_x, var.Recenter_y ] - [ mouse.x, mouse.y ]
   }
   lmb = var.LeftMouseButton
   rmb = var.RightMouseButton
   mmb = var.MiddleMouseButton
}
// ### Battery Test
if var.wmCalON = false and delta(var.wmCalON) {
   var.Battery = EnsureRange(wiimote.Battery / 1.92, 0, 100)
   if var.Battery < 15 then var.BattDebug = "  ### LOW BATTERY ###  "+ var.Battery +"%" else var.BattDebug = " Battery: "+ var.Battery +"%"
}
// ### Debug
if (var.wmCalON = true) or (var.BattDebug = 0) then var.BattDebug = ""
if var.UseCalDebug = 0 then var.UseCalDebug = ""
if (var.wmCalON = true) or (var.started = false) then var.ZoomDebug = "" else var.ZoomDebug = " Zoom: "+ var.NewZoom
if (abs(var.wmCalYaw) + abs(var.wmCalPitch) + abs(var.wmDeadZone) > 0.01) and (var.started and not var.wmCalON) {
   var.UseCalDebug = "  * Secondary Calibration *     Out: "+ var.wmSpeedYP +"   Cal: "+ [ var.wmCalYaw, var.wmCalPitch ] +"   In: "+ var.wmSpeedYP_IN +"   DeadZone: "+ var.wmDeadZone
   if delta(var.wmCalON)<0 then var.ErrorON = 0.54
elseif (abs(var.wmCalYaw) + abs(var.wmCalPitch) + abs(var.wmDeadZone) <= 0.01) and ( var.started and not var.wmCalON)
   var.UseCalDebug = "  Default GlovePIE Calibration"
elseif var.wmCalON
   var.UseCalDebug = "   ### CALIBRATING ###         Place the Wiimote down "
}
debug = var.BattDebug +"    "+ var.ZoomDebug +"    "+ var.UseCalDebug

/*
// ### Debug Cursors
var.debugCursors = false
if var.debugCursors = true and var.started = true and var.wmCalON = false {
   [ cursor3.Visible, cursor9.Visible ] = [ true, true ]
   [ cursor15.Visible, cursor21.Visible ] = [ true, true ]
   [ cursor2.Visible, cursor8.Visible ] = [ true, true ]
   [ cursor14.Visible, cursor20.Visible ] = [ true, true ]
   [ cursor3.x, cursor3.y ] = [ var.wmNewMin_x, var.wmNewMin_y ] - [ var.WMIR_cal_x, var.WMIR_cal_y ]
   [ cursor9.x, cursor9.y ] = [ var.wmNewMax_x, var.wmNewMin_y ] - [ var.WMIR_cal_x, var.WMIR_cal_y ]
   [ cursor15.x, cursor15.y ] = [ var.wmNewMax_x, var.wmNewMax_y ] - [ var.WMIR_cal_x, var.WMIR_cal_y ]
   [ cursor21.x, cursor21.y ] = [ var.wmNewMin_x, var.wmNewMax_y ] - [ var.WMIR_cal_x, var.WMIR_cal_y ]
   [ cursor2.x, cursor2.y ] = [ var.irNewMin_x, var.irNewMin_y ]
   [ cursor8.x, cursor8.y ] = [ var.irNewMax_x, var.irNewMin_y ]
   [ cursor14.x, cursor14.y ] = [ var.irNewMax_x, var.irNewMax_y ]
   [ cursor20.x, cursor20.y ] = [ var.irNewMin_x, var.irNewMax_y ]
else
   [ cursor3.Visible, cursor9.Visible ] = [ false, false ]
   [ cursor15.Visible, cursor21.Visible ] = [ false, false ]
   [ cursor2.Visible, cursor8.Visible ] = [ false, false ]
   [ cursor14.Visible, cursor20.Visible ] = [ false, false ]
}
*/
« Last Edit: March 09, 2011, 10:28:42 PM by lednerg » Logged
*
Karma: +0/-0
Posts: 3
Offline Offline
View Profile Email
« Reply #1 on: January 08, 2010, 08:17:49 PM »

Congratulation, for me is a very good script, I have try to add another script for FPS game wich use Nunchuck + mouse traditional, but can you help me to remove your conditional moviment with button B of Wiimote?
Tank
 (sorry for my bad English, I hope wich you understand me)


/*
    WiiMotion Plus Mouse                                         v 2010.01.08
    by lednerg

    Emulates the basic functionality of a Gyration Air Mouse.
    Requires GlovePIE version .40 or higher.

    Leave the Wiimote on your desk when starting so it can calibrate.
    Hold B to move, A = Left-Click, + = Right-Click, Down = Middle-Click.
    Minus re-calibrates, just in case you need it.
*/

var.MoveButton = wiimote.B
mouse.LeftButton = wiimote.A
mouse.RightButton = wiimote.Plus
mouse.MiddleButton = wiimote.Down
var.CalibrateButton = wiimote.Minus

var.Speed = 85   // 0 to 100

PIE.FrameRate = 120hz
if wiimote.HasMotionPlus = false then debug = "WiiMotion Plus NOT DETECTED!"
if var.init = false and wiimote.HasMotionPlus = true {
   debug = "Please place the Wiimote down. CALIBRATING - " + int(EnsureMapRange(RemoveUnits(abs(Delta(Smooth(wiimote.MotionPlus.YawSpeed, 60)))), 1, .005, 0, 100)) + "%"
   if abs(Delta(Smooth(wiimote.MotionPlus.YawSpeed, 60))) < .005 then var.CalibYaw = smooth(wiimote.MotionPlus.YawSpeed, 60)
   if abs(Delta(Smooth(wiimote.MotionPlus.PitchSpeed, 60))) < .005 then var.CalibPitch = smooth(wiimote.MotionPlus.PitchSpeed, 60)
   if abs(var.CalibYaw) > 0 and abs(var.CalibPitch) > 0 then var.init = true
}
if var.init = true and var.MoveButton = true {
   var.YawSpeed = wiimote.MotionPlus.YawSpeed - var.CalibYaw
   var.PitchSpeed = wiimote.MotionPlus.PitchSpeed - var.CalibPitch
   if SameValue( Smooth(wiimote.SmoothRoll, 10), wiimote.SmoothRoll, 10) then var.Roll = Smooth(wiimote.SmoothRoll, 10) else var.Roll = wiimote.SmoothRoll
   if var.Roll < 0 and var.Roll >= -90 {
      var.XYswap = 1 - EnsureMapRange(var.Roll, -90, 0, 0, 1)
      var.RightDown = -1
      var.TopUp = 1
   }
   if var.Roll <= 90 and var.Roll >= 0 {
      var.XYswap = 1 - EnsureMapRange(var.Roll, 90, 0, 0, 1)
      var.RightDown = 1
      var.TopUp = 1
   }
   if var.Roll > 90 and var.Roll <= 180 {
      var.XYswap = 1 - EnsureMapRange(var.Roll, 90, 180, 0, 1)
      var.RightDown = 1
      var.TopUp = -1
   }
   if var.Roll < -90 and var.Roll >= -180 {
      var.XYswap = 1 - EnsureMapRange(var.Roll, -90, -180, 0, 1)
      var.RightDown = -1
      var.TopUp = -1
   }
   var.SpeedX = var.TopUp * var.YawSpeed - ( var.TopUp * var.YawSpeed * var.XYswap ) + ( var.RightDown * var.PitchSpeed * var.XYswap )
   var.SpeedY = var.TopUp * var.PitchSpeed - ( var.TopUp * var.PitchSpeed * var.XYswap) + ( -var.RightDown * var.YawSpeed * var.XYswap )
   mouse.DirectInputX = int(var.MouseX)
   mouse.DirectInputY = int(var.MouseY)
   var.MouseX = var.MouseX + ( var.SpeedX / (10500000 - EnsureMapRange(var.Speed, 0, 100, 0, 10000000) ) )
   var.MouseY = var.MouseY - ( var.SpeedY / (10500000 - EnsureMapRange(var.Speed, 0, 100, 0, 10000000) ) )
/* // for mouse.x and mouse.y instead
   mouse.x = var.MouseX
   mouse.y = var.MouseY
   var.MouseX = var.MouseX + ( var.SpeedX / (20500 - EnsureMapRange(var.Speed, 0, 100, 0, 20000) ) )
   var.MouseY = var.MouseY - ( var.SpeedY / (20500 - EnsureMapRange(var.Speed, 0, 100, 0, 20000) ) )
*/
}
if var.MoveButton = false {
   var.MouseX = mouse.DirectInputX
   var.MouseY = mouse.DirectInputY
/* // for mouse.x and mouse.y instead
   var.MouseX = mouse.x
   var.MouseY = mouse.y
*/
}
if var.init = true and var.CalibrateButton = false {
   debug = "CALIBRATED"
}
if var.init != false and var.CalibrateButton = true {
   var.init = "waiting"
   debug = "Please place the Wiimote down."
   var.CalibYaw = 0
   var.CalibPitch = 0
   wait 3 seconds
   var.init = false
}

                        // Script FPS senza IR

          // Nunchuk
// Movimenti
WASD = Wiimote.Nunchuk.Joy
// Corri tasto Z del nunchuk
Keyboard.LeftShift = Wiimote.Nunchuk.ZButton

// Libero tasto C del nunchuck
Mouse.RightButton = Wiimote.Nunchuk.CButton

//  Inclina a sin il nunnchuck tasto V, a destra tasto c
Keyboard.V  = (smooth(Wiimote.Nunchuk.Roll <= -6500% degrees))
Keyboard.C  = (smooth(Wiimote.Nunchuk.Roll >=  6500% degrees))

//  Inclina su il nunnchuck tasto j, gił tasto k
Keyboard.J = (smooth(Wiimote.Nunchuk.Pitch <= -6500% degrees))
Keyboard.K = (smooth(Wiimote.Nunchuk.Pitch >=  6500% degrees))


Logged
*
Karma: +0/-0
Posts: 8
Offline Offline
View Profile
« Reply #2 on: January 08, 2010, 09:58:03 PM »

First line:

var.MoveButton = wiimote.B


Change it to:

var.MoveButton = true
Logged
*
Karma: +0/-0
Posts: 3
Offline Offline
View Profile Email
« Reply #3 on: January 09, 2010, 01:33:09 AM »

First line:

var.MoveButton = wiimote.B


Change it to:

var.MoveButton = true

Thank, I have optimized this script for Crysis:

/*
    WiiMotion Plus Mouse                                         v 2010.01.08
    by lednerg

    Emulates the basic functionality of a Gyration Air Mouse.
    Requires GlovePIE version .40 or higher.

    Leave the Wiimote on your desk when starting so it can calibrate.
    Hold B to move, A = Left-Click, + = Right-Click, Down = Middle-Click.
    Minus re-calibrates, just in case you need it.
*/

var.MoveButton = wiimote.Home
mouse.LeftButton = wiimote.B
mouse.RightButton = wiimote.A
mouse.MiddleButton = wiimote.Plus
keyboard.Space = wiimote.1
var.CalibrateButton = wiimote.Minus

var.Speed = 80   // 0 to 100

PIE.FrameRate = 120hz
if wiimote.HasMotionPlus = false then debug = "WiiMotion Plus NOT DETECTED!"
if var.init = false and wiimote.HasMotionPlus = true {
   debug = "Please place the Wiimote down. CALIBRATING - " + int(EnsureMapRange(RemoveUnits(abs(Delta(Smooth(wiimote.MotionPlus.YawSpeed, 60)))), 1, .005, 0, 100)) + "%"
   if abs(Delta(Smooth(wiimote.MotionPlus.YawSpeed, 60))) < .005 then var.CalibYaw = smooth(wiimote.MotionPlus.YawSpeed, 60)
   if abs(Delta(Smooth(wiimote.MotionPlus.PitchSpeed, 60))) < .005 then var.CalibPitch = smooth(wiimote.MotionPlus.PitchSpeed, 60)
   if abs(var.CalibYaw) > 0 and abs(var.CalibPitch) > 0 then var.init = true
}
if var.init = true and var.MoveButton = false {
   var.YawSpeed = wiimote.MotionPlus.YawSpeed - var.CalibYaw
   var.PitchSpeed = wiimote.MotionPlus.PitchSpeed - var.CalibPitch
   if SameValue( Smooth(wiimote.SmoothRoll, 10), wiimote.SmoothRoll, 10) then var.Roll = Smooth(wiimote.SmoothRoll, 10) else var.Roll = wiimote.SmoothRoll
   if var.Roll < 0 and var.Roll >= -90 {
      var.XYswap = 1 - EnsureMapRange(var.Roll, -90, 0, 0, 1)
      var.RightDown = -1
      var.TopUp = 1
   }
   if var.Roll <= 90 and var.Roll >= 0 {
      var.XYswap = 1 - EnsureMapRange(var.Roll, 90, 0, 0, 1)
      var.RightDown = 1
      var.TopUp = 1
   }
   if var.Roll > 90 and var.Roll <= 180 {
      var.XYswap = 1 - EnsureMapRange(var.Roll, 90, 180, 0, 1)
      var.RightDown = 1
      var.TopUp = -1
   }
   if var.Roll < -90 and var.Roll >= -180 {
      var.XYswap = 1 - EnsureMapRange(var.Roll, -90, -180, 0, 1)
      var.RightDown = -1
      var.TopUp = -1
   }
   var.SpeedX = var.TopUp * var.YawSpeed - ( var.TopUp * var.YawSpeed * var.XYswap ) + ( var.RightDown * var.PitchSpeed * var.XYswap )
   var.SpeedY = var.TopUp * var.PitchSpeed - ( var.TopUp * var.PitchSpeed * var.XYswap) + ( -var.RightDown * var.YawSpeed * var.XYswap )
   mouse.DirectInputX = int(var.MouseX)
   mouse.DirectInputY = int(var.MouseY)
   var.MouseX = var.MouseX + ( var.SpeedX / (10500000 - EnsureMapRange(var.Speed, 0, 100, 0, 10000000) ) )
   var.MouseY = var.MouseY - ( var.SpeedY / (10500000 - EnsureMapRange(var.Speed, 0, 100, 0, 10000000) ) )
/* // for mouse.x and mouse.y instead
   mouse.x = var.MouseX
   mouse.y = var.MouseY
   var.MouseX = var.MouseX + ( var.SpeedX / (20500 - EnsureMapRange(var.Speed, 0, 100, 0, 20000) ) )
   var.MouseY = var.MouseY - ( var.SpeedY / (20500 - EnsureMapRange(var.Speed, 0, 100, 0, 20000) ) )
*/
}
if var.MoveButton = true {
   var.MouseX = mouse.DirectInputX
   var.MouseY = mouse.DirectInputY
/* // for mouse.x and mouse.y instead
   var.MouseX = mouse.x
   var.MouseY = mouse.y
*/
}
if var.init = true and var.CalibrateButton = false {
   debug = "CALIBRATED"
}
if var.init != false and var.CalibrateButton = true {
   var.init = "waiting"
   debug = "Please place the Wiimote down."
   var.CalibYaw = 0
   var.CalibPitch = 0
   wait 3 seconds
   var.init = false
}

                        // Script FPS senza IR

          // Nunchuk
// Movimenti
WASD = Wiimote.Nunchuk.Joy
// Corri tasto Z del nunchuk
Keyboard.LeftShift = Wiimote.Nunchuk.ZButton

// Libero tasto C del nunchuck
Mouse.RightButton = Wiimote.Nunchuk.CButton

//  Inclina a sin il nunchuck tasto F (prendi), a destra cambia arma
Keyboard.F  = (smooth(Wiimote.Nunchuk.Roll <= -6500% degrees))
Mouse.WheelDown = (smooth(Wiimote.Nunchuk.Roll >=  6500% degrees))

//  Inclina su il nunchuck tasto B (binocolo), gił tasto k
Keyboard.B = (smooth(Wiimote.Nunchuk.Pitch <= -6500% degrees))
Keyboard.K = (smooth(Wiimote.Nunchuk.Pitch >=  6500% degrees))
Logged
*
Karma: +0/-0
Posts: 8
Offline Offline
View Profile
« Reply #4 on: January 24, 2010, 03:50:03 PM »

Updated script, see top post.

Next thing I want to do is combine it with IR. After that, I can start making it suitable for games.
Logged
*
Karma: +0/-0
Posts: 21
Offline Offline
View Profile
« Reply #5 on: January 25, 2010, 02:22:36 AM »

I get sensitivity problem with glovepie, it is not as sensitive as wiimotepresenter, but it might be just the script, because I use standard old ones.

Updated script, see top post.

Next thing I want to do is combine it with IR. After that, I can start making it suitable for games.
Logged
*
Karma: +0/-0
Posts: 8
Offline Offline
View Profile
« Reply #6 on: January 27, 2010, 09:01:41 PM »

Updated. See top post.

This was pretty much a complete overhaul of the script. It was starting to look sloppy, IMO. Got rid of the extra calibration, figured out the problem I was having that led me to believe I needed it.

Dynamic Motion Smoothing is pretty nice. It's a cleaned up version of something I did a while ago for an IR mouse script - which means it works just as well for IR mice.

The option for HoldToMove is something I should've had from the beginning. Oh well, it's there now. When HoldToMove is set to false, you can flip the Wiimote face-down so you can still use your regular mouse without any problems.
Logged
*
Karma: +0/-0
Posts: 1
Offline Offline
View Profile Email
« Reply #7 on: February 03, 2010, 05:43:38 PM »

I know an easier Script:
Code:
// My MotionPlus Mousescript
mouse.CursorPosX = mouse.CursorPosX + wiimote.MotionPlus.YawSpeed / 500000
mouse.CursorPosY = mouse.CursorPosY - wiimote.MotionPlus.PitchSpeed / 500000
mouse.LeftButton = wiimote.A or wiimote.B
mouse.RightButton = wiimote.Down

key.VolumeDown = wiimote.Minus
key.VolumeUp = wiimote.Plus
key.Mute = wiimote.Home
« Last Edit: February 03, 2010, 10:06:08 PM by patagona » Logged
*
Karma: +0/-0
Posts: 1
Offline Offline
View Profile
« Reply #8 on: June 12, 2010, 12:29:34 PM »

Some minor enchantments and more button functionality. Don't forget to leave the wiimote level when you press "Start" or it will be like drunk!

Later i will try to make the following "Press 1 button for 2 seconds to shutdown the PC" (so you don't have to get out of bed/couch)

Code:
/*

    WiiMotion Plus Mouse                                  v 2010.01.28

    by lednerg



    Emulates the basic functionality of a Gyration Air Mouse.

    Requires GlovePIE version .42 or higher.



    Leave the Wiimote on your desk when starting so it can calibrate.

    Wait until only the first LED is lit.



    A = Left-Click, + = Right-Click, Down = Middle-Click

    If var.HoldToMove is true, Hold B to move

    If var.HoldToMove is false, Hold B to stop ...

    ...and you can flip Wiimote upside-down to use normal mouse

    Home = Battery Test

*/



// ==== Buttons ================================================================

var.MoveButton = wiimote.B

mouse.LeftButton = wiimote.A

mouse.RightButton = wiimote.Plus

mouse.MiddleButton = wiimote.Minus

var.BatteryTestButton = wiimote.Home

mouse.WheelUp = Wiimote1.Up

mouse.WheelDown = Wiimote1.Down

Key.VolumeDown = Wiimote1.Left

Key.VolumeUp = Wiimote1.Right





// ==== Options ================================================================

var.HoldToMove = true

// true = Hold MoveButton to move

// false = Hold MoveButton to stop, flip Wiimote upside-down to use normal mouse



var.EdgeStop = true

// Stops movement at the edge of the screen



var.Speed = 75  // 0 to 100

// Overall speed of movement



var.Mouse_Precision = 1 // 0 to 15

// Low values smooth the movement of the cursor



PIE.FrameRate = 100hz  // Wii MotionPlus has a refresh rate of 100hz



// ==== Wii MotionPlus =========================================================

// Start of Wii Motion Plus script

IF HeldDown(abs(wiimote.SmoothRoll)>135, 1 second) THEN var.WiimoteUpsideDown = true ELSE var.WiimoteUpsideDown = false

IF var.HoldToMove = true {

   var.Move = var.MoveButton

ELSE

   IF var.MoveButton = false AND var.WiimoteUpsideDown = false THEN var.Move = true ELSE var.Move = false

}

IF wiimote.HasMotionPlus = false THEN var.CalibDebug = "[ WiiMotion Plus NOT DETECTED! ]" ELSE var.CalibDebug = ""

IF wiimote.HasMotionPlus = true AND var.Move = true {

   var.YawSpeed = wiimote.MotionPlus.YawSpeed

   var.PitchSpeed = wiimote.MotionPlus.PitchSpeed

   IF SameValue( Smooth(wiimote.Roll, 30), wiimote.Roll, 50) THEN var.Roll = Smooth(wiimote.Roll, 30) ELSE var.Roll = wiimote.Roll

   IF var.Roll < 0 AND var.Roll >= -90 {

      var.XYswap = 1 - EnsureMapRange(var.Roll, -90, 0, 0, 1)

      var.RightDown = -1

      var.TopUp = 1

   }

   IF var.Roll <= 90 AND var.Roll >= 0 {

      var.XYswap = 1 - EnsureMapRange(var.Roll, 90, 0, 0, 1)

      var.RightDown = 1

      var.TopUp = 1

   }

   IF var.Roll > 90 AND var.Roll <= 180 {

      var.XYswap = 1 - EnsureMapRange(var.Roll, 90, 180, 0, 1)

      var.RightDown = 1

      var.TopUp = -1

   }

   IF var.Roll < -90 AND var.Roll >= -180 {

      var.XYswap = 1 - EnsureMapRange(var.Roll, -90, -180, 0, 1)

      var.RightDown = -1

      var.TopUp = -1

   }

   var.TopUpFix = Smooth(var.TopUp,40) / abs(Smooth(var.TopUp,40))

   var.RightDownFix = Smooth(var.RightDown,30) / abs(Smooth(var.RightDown,30))

   var.SpeedX = var.TopUpFix * var.YawSpeed - ( var.TopUpFix * var.YawSpeed * var.XYswap ) + ( var.RightDownFix * var.PitchSpeed * var.XYswap )

   var.SpeedY = var.TopUpFix * var.PitchSpeed - ( var.TopUpFix * var.PitchSpeed * var.XYswap) + ( -var.RightDownFix * var.YawSpeed * var.XYswap )

   var.Mouse_X = var.Mouse_X + ( var.SpeedX / (20500 - EnsureMapRange(var.Speed, 0, 100, 0, 20000) ) )

   var.Mouse_Y = var.Mouse_Y - ( var.SpeedY / (20500 - EnsureMapRange(var.Speed, 0, 100, 0, 20000) ) )

}

IF var.Move = false {

   IF delta(var.Move) = true {

      var.Mouse_X = var.CursorX

      var.Mouse_Y = var.CursorY

   }

   var.Mouse_X = mouse.x

   var.Mouse_Y = mouse.y

ELSE

   IF var.EdgeStop = true {

      var.Mouse_X = EnsureRange(var.Mouse_X, 0, 1)

      var.Mouse_Y = EnsureRange(var.Mouse_Y, 0, 1)

   }

   mouse.x = var.CursorX

   mouse.y = var.CursorY

   IF delta(var.Move) = true {

      var.Mouse_X = var.CursorX

      var.Mouse_Y = var.CursorY

   }

}



// ==== Dynamic Motion Smoothing ===============================================

//  This automatically adjusts the smoothness

//  of the movement based on the cursor's speed.

var.Mouse_Speed_X = int(abs(delta(var.Mouse_X))*1000)

var.Mouse_Speed_Y = int(abs(delta(var.Mouse_Y))*1000)

var.Mouse_Speed_XY = int(sqrt(var.Mouse_Speed_X + var.Mouse_Speed_Y) * var.Mouse_Precision)

IF var.Mouse_Speed_XY >= 30 THEN var.Mouse_SmoothHold = 0 ELSE var.Mouse_SmoothHold = 30 - var.Mouse_Speed_XY

var.Mouse_SmoothLimit = 30 - EnsureRange(var.Mouse_Precision*2, 0, 30)

IF var.Mouse_SmoothHold < var.Mouse_Smooth THEN var.Mouse_Smooth = var.Mouse_Smooth - (1 + int(EnsureMapRange(var.Mouse_SmoothHold, 0, 30, 30, 0)))

IF var.Mouse_SmoothHold > var.Mouse_Smooth OR (var.Mouse_SmoothHold = 30 AND var.Mouse_Smooth <= 29) {

   wait EnsureMapRange(var.Mouse_Smooth, 0, 29, 0, 100)ms

   IF var.Mouse_Smooth < var.Mouse_SmoothLimit THEN var.Mouse_Smooth++

}

IF var.Mouse_Smooth <= 0 THEN var.Mouse_Smooth = 0

IF var.Mouse_Smooth <= 0 THEN var.CursorX = var.Mouse_X

IF var.Mouse_Smooth <= 0 THEN var.CursorY = var.Mouse_Y

IF var.Mouse_Smooth = 1 THEN var.CursorX = Smooth(var.Mouse_X, 1)

IF var.Mouse_Smooth = 1 THEN var.CursorY = Smooth(var.Mouse_Y, 1)

IF var.Mouse_Smooth = 2 THEN var.CursorX = Smooth(var.Mouse_X, 2)

IF var.Mouse_Smooth = 2 THEN var.CursorY = Smooth(var.Mouse_Y, 2)

IF var.Mouse_Smooth = 3 THEN var.CursorX = Smooth(var.Mouse_X, 3)

IF var.Mouse_Smooth = 3 THEN var.CursorY = Smooth(var.Mouse_Y, 3)

IF var.Mouse_Smooth = 4 THEN var.CursorX = Smooth(var.Mouse_X, 4)

IF var.Mouse_Smooth = 4 THEN var.CursorY = Smooth(var.Mouse_Y, 4)

IF var.Mouse_Smooth = 5 THEN var.CursorX = Smooth(var.Mouse_X, 5)

IF var.Mouse_Smooth = 5 THEN var.CursorY = Smooth(var.Mouse_Y, 5)

IF var.Mouse_Smooth = 6 THEN var.CursorX = Smooth(var.Mouse_X, 6)

IF var.Mouse_Smooth = 6 THEN var.CursorY = Smooth(var.Mouse_Y, 6)

IF var.Mouse_Smooth = 7 THEN var.CursorX = Smooth(var.Mouse_X, 7)

IF var.Mouse_Smooth = 7 THEN var.CursorY = Smooth(var.Mouse_Y, 7)

IF var.Mouse_Smooth = 8 THEN var.CursorX = Smooth(var.Mouse_X, 8)

IF var.Mouse_Smooth = 8 THEN var.CursorY = Smooth(var.Mouse_Y, 8)

IF var.Mouse_Smooth = 9 THEN var.CursorX = Smooth(var.Mouse_X, 9)

IF var.Mouse_Smooth = 9 THEN var.CursorY = Smooth(var.Mouse_Y, 9)

IF var.Mouse_Smooth = 10 THEN var.CursorX = Smooth(var.Mouse_X, 10)

IF var.Mouse_Smooth = 10 THEN var.CursorY = Smooth(var.Mouse_Y, 10)

IF var.Mouse_Smooth = 11 THEN var.CursorX = Smooth(var.Mouse_X, 11)

IF var.Mouse_Smooth = 11 THEN var.CursorY = Smooth(var.Mouse_Y, 11)

IF var.Mouse_Smooth = 12 THEN var.CursorX = Smooth(var.Mouse_X, 12)

IF var.Mouse_Smooth = 12 THEN var.CursorY = Smooth(var.Mouse_Y, 12)

IF var.Mouse_Smooth = 13 THEN var.CursorX = Smooth(var.Mouse_X, 13)

IF var.Mouse_Smooth = 13 THEN var.CursorY = Smooth(var.Mouse_Y, 13)

IF var.Mouse_Smooth = 14 THEN var.CursorX = Smooth(var.Mouse_X, 14)

IF var.Mouse_Smooth = 14 THEN var.CursorY = Smooth(var.Mouse_Y, 14)

IF var.Mouse_Smooth = 15 THEN var.CursorX = Smooth(var.Mouse_X, 15)

IF var.Mouse_Smooth = 15 THEN var.CursorY = Smooth(var.Mouse_Y, 15)

IF var.Mouse_Smooth = 16 THEN var.CursorX = Smooth(var.Mouse_X, 16)

IF var.Mouse_Smooth = 16 THEN var.CursorY = Smooth(var.Mouse_Y, 16)

IF var.Mouse_Smooth = 17 THEN var.CursorX = Smooth(var.Mouse_X, 17)

IF var.Mouse_Smooth = 17 THEN var.CursorY = Smooth(var.Mouse_Y, 17)

IF var.Mouse_Smooth = 18 THEN var.CursorX = Smooth(var.Mouse_X, 18)

IF var.Mouse_Smooth = 18 THEN var.CursorY = Smooth(var.Mouse_Y, 18)

IF var.Mouse_Smooth = 19 THEN var.CursorX = Smooth(var.Mouse_X, 19)

IF var.Mouse_Smooth = 19 THEN var.CursorY = Smooth(var.Mouse_Y, 19)

IF var.Mouse_Smooth = 20 THEN var.CursorX = Smooth(var.Mouse_X, 20)

IF var.Mouse_Smooth = 20 THEN var.CursorY = Smooth(var.Mouse_Y, 20)

IF var.Mouse_Smooth = 21 THEN var.CursorX = Smooth(var.Mouse_X, 21)

IF var.Mouse_Smooth = 21 THEN var.CursorY = Smooth(var.Mouse_Y, 21)

IF var.Mouse_Smooth = 22 THEN var.CursorX = Smooth(var.Mouse_X, 22)

IF var.Mouse_Smooth = 22 THEN var.CursorY = Smooth(var.Mouse_Y, 22)

IF var.Mouse_Smooth = 23 THEN var.CursorX = Smooth(var.Mouse_X, 23)

IF var.Mouse_Smooth = 23 THEN var.CursorY = Smooth(var.Mouse_Y, 23)

IF var.Mouse_Smooth = 24 THEN var.CursorX = Smooth(var.Mouse_X, 24)

IF var.Mouse_Smooth = 24 THEN var.CursorY = Smooth(var.Mouse_Y, 24)

IF var.Mouse_Smooth = 25 THEN var.CursorX = Smooth(var.Mouse_X, 25)

IF var.Mouse_Smooth = 25 THEN var.CursorY = Smooth(var.Mouse_Y, 25)

IF var.Mouse_Smooth = 26 THEN var.CursorX = Smooth(var.Mouse_X, 26)

IF var.Mouse_Smooth = 26 THEN var.CursorY = Smooth(var.Mouse_Y, 26)

IF var.Mouse_Smooth = 27 THEN var.CursorX = Smooth(var.Mouse_X, 27)

IF var.Mouse_Smooth = 27 THEN var.CursorY = Smooth(var.Mouse_Y, 27)

IF var.Mouse_Smooth = 28 THEN var.CursorX = Smooth(var.Mouse_X, 28)

IF var.Mouse_Smooth = 28 THEN var.CursorY = Smooth(var.Mouse_Y, 28)

IF var.Mouse_Smooth = 29 THEN var.CursorX = Smooth(var.Mouse_X, 29)

IF var.Mouse_Smooth = 29 THEN var.CursorY = Smooth(var.Mouse_Y, 29)

IF var.Mouse_Smooth >= 30 THEN var.CursorX = Smooth(var.Mouse_X, 30)

IF var.Mouse_Smooth >= 30 THEN var.CursorY = Smooth(var.Mouse_Y, 30)



// ==== Wiimote Battery Test  =================================================

// Fills up with blinking LEDs to 50%

// then fills with solid LEDs to 100%

if var.BatteryDebug = false then var.BatteryDebug = ""

if var.BatteryTestButton = true and var.BatteryDisplayOn != true {

   wiimote.Report15 = 0x80 | int(wiimote.Rumble)

   var.BatteryLevel = wiimote.Battery

   var.BatteryDebug = " [ Battery : "+(int(var.BatteryLevel/1.92))+"% ] "

   var.BatteryLEDs = 0

   var.BatteryLEDbefore = wiimote.LEDs

   var.BatteryDisplayOn = true

}

if var.BatteryDisplayOn = true {

   if var.BatteryLEDs <= var.BatteryLevel {

      var.BatteryLEDs = var.BatteryLEDs + 12

      wait 60ms

   else

      wait 1000ms

      var.BatteryDisplayOn = "done"

   }

   if var.BatteryLEDs <= 96 {

      var.BatteryLED_A = 0

      if var.BatteryLEDs <= 24 then var.BatteryLED_B = 1

      if var.BatteryLEDs > 24 and var.BatteryLEDs <= 48 then var.BatteryLED_B = 3

      if var.BatteryLEDs > 48 and var.BatteryLEDs <= 72 then var.BatteryLED_B = 7

      if var.BatteryLEDs > 72 then var.BatteryLED_B = 15

   else

      if var.BatteryLEDs <= 120 then var.BatteryLED_A = 1

      if var.BatteryLEDs > 120 and var.BatteryLEDs <= 144 then var.BatteryLED_A = 3

      if var.BatteryLEDs > 144 and var.BatteryLEDs <= 168 then var.BatteryLED_A = 7

      if var.BatteryLEDs > 168 then var.BatteryLED_A = 15

   }

   wiimote.LEDs = var.BatteryLED_A

   wait 40ms

   wiimote.LEDs = var.BatteryLED_B

   wait 20ms

elseif var.BatteryDisplayOn = "done"

   wiimote.LEDs = 0

   wait 2 seconds

   wiimote.LEDs = var.BatteryLEDbefore

   var.BatteryDisplayOn = false

}



debug = var.CalibDebug + var.DebugPrecision + var.DebugSmooth + var.BatteryDebug

var.DebugPrecision = " [ Precision: "+ var.Mouse_Precision +" ]"

var.DebugSmooth = " [ Smooth: "+ int(var.Mouse_Smooth) +" ]"
Logged
*
Karma: +0/-0
Posts: 1
Offline Offline
View Profile Email
« Reply #9 on: October 14, 2010, 05:46:21 PM »

Awesome script! What would be the best way to invert the Y axis? For first person shooter for example?

Many thanks
Logged
*
Karma: +0/-0
Posts: 3
Offline Offline
View Profile Email
« Reply #10 on: October 19, 2010, 07:06:24 PM »

Hello,

i am not really good when it comes to scripting, but what i can do is copy/paste the lines that i need and make small changes.

I am looking for a way to use the WM+ to play car games, and using the wiimote like a wheel. I am already using the code that i saw here for WM+ to play FPS games and it is really good and accurate, i love it, but i did not see any code to use the WM+ like a wheel for race/car games. Is there somewhere something like that that i missed? Or maybe a list of all the variables and functions with explanations.

Thank you.
Logged
*
Karma: +0/-0
Posts: 5
Offline Offline
View Profile
« Reply #11 on: October 26, 2010, 10:43:22 PM »

I made this one for cursor moving

Code:
  var.gyroPitch=wiimote.MotionPlus.GyroPitch
   var.gyroYaw=wiimote.MotionPlus.GyroYaw
   var.gyroRoll=wiimote.MotionPlus.GyroRoll
   //var.gyroYawSpeed=Wiimote.MotionPlus.YawSpeed
   //var.gyroPitchSpeed=Wiimote.MotionPlus.PitchSpeed
   //var.gyroRollSpeed=Wiimote.MotionPlus.RollSpeed

   var.pitchrange=3000 mickeys
   var.yawrange=6000 mickeys

   // proportional to angle  (rotate )
   //var.diy=MapRange(wiimote.gyroPitch, -90 degrees,90 degrees, var.pitchrange mickeys,-var.pitchrange mickeys)
   //var.dix=MapRange(wiimote.gyroYaw, -90 degrees,90 degrees, -var.yawrange mickeys,var.yawrange mickeys)

   // proportional to pointed surface (aiming)
   var.diysin=-MapRange(sin(wiimote.gyroPitch), -1, 1, -var.pitchrange mickeys, var.pitchrange mickeys)
   var.dixsin=MapRange(sin(wiimote.gyroYaw), -1, 1, -var.yawrange mickeys,var.yawrange mickeys)


   If Wiimote.A
        mouse.DirectInputX += delta(var.dixsin)
        mouse.DirectInputY += delta(var.diysin)
        Wiimote.led4=true
   else
     Wiimote.led4=false
   endif

The idea here is to use a sinus of the angle, to reflect more accurately how a fast a laser emited from the wiimote would move on the screen surface when you rotate the wiimote

the problem however is that if you move right, left, right left several times, the cursor isn't centered anymore

The idea of using the A button is to recenter, and especially for a fps, allowing after reaching the desired position to recenter the wiimote
« Last Edit: October 26, 2010, 10:49:02 PM by mirak » Logged
*
Karma: +0/-0
Posts: 5
Offline Offline
View Profile
« Reply #12 on: October 27, 2010, 02:54:50 AM »

ok, I think I understand why you use giration speed

The wiimote totally loses where is the front, so the degree zero of the yaw is lost (I think the pitch is lost as well in fact).

The only way would be to regularly reset the gyroscope to 0 degree on yaw and pitch when the wiimote is pointing the sensor bar.
Logged
*
Karma: +0/-0
Posts: 1
Offline Offline
View Profile
« Reply #13 on: November 10, 2010, 08:08:09 AM »

hi everybody,

i just started to play with glovepie (lot of fun)
but still on some basics.
i try with no success to move my mouse
with the D-pad of a simple wiimote.
any help? please?
Logged
*
Karma: +0/-0
Posts: 8
Offline Offline
View Profile
« Reply #14 on: March 09, 2011, 11:44:13 AM »

Okay, I updated the script. Check out the first post.

I'll be working on an FPS version next.
Logged
Pages: [1] 2
  Print  
 
Jump to:  

Clicky Web Analytics