//Mouse Control Script using IR //by Matteo de Marinis // // NOTE: Richiede la Sensor Bar o un dispositivo IR sul monitor: se non avete la // Sensor Bar potete costruirla mettendo alcuni led IR sugli angoli superiori del // montor, oppure due candele, posizionabili anche ai due lati. // // CALIBRAZIONE: Per calibrare, avviare il programma e mettere il Wiimote su una // superfice piatta puntato verso il centro del monitor, quindi leggere i valori // nella finestra di Debug e sostituirli ai valori qui sotto, ripetere // l'operazione finchè i valori raggiungono lo zero. var.xtrim = 10 var.ytrim = 50 var.ztrim = 0 // //OPZIONI: var.ledspeed = 100 ms //Ritardo di velocità dello scorrimento dei led var.rumble = 0 //Attiva-Disattiva la vibrazione //CONTROLLI: W = wiimote.Up S = wiimote.Down A = wiimote.Left D = wiimote.Right Mouse.RightButton = Wiimote.A Mouse.LeftButton = Wiimote.B Key.Enter = WiiMote.Plus Mouse.MiddleButton = WiiMote.Home Key.Backspace = WiiMote.Minus Mouse.WheelUp = WiiMote.One Mouse.WheelDown = WiiMote.Two Left = WiiMote.Nunchuk.JoyX < -0.2 Right = WiiMote.Nunchuk.JoyX > 0.2 Up = WiiMote.Nunchuk.JoyY < -0.2 Down = WiiMote.Nunchuk.JoyY > 0.2 Key.PageUp = WiiMote.Nunchuk.CButton Key.PageDown = WiiMote.Nunchuk.ZButton Key.O = var.XNun > 30 Key.L = var.XNun < -30 //Questa parte fà illuminare i LED e l fà scorrere quando il Wii è connesso if 0 = 0 then if var.led = 0 then wiimote.Leds = 1 endif if var.led = 1 then wiimote.Leds = 3 endif if var.led = 2 then wiimote.Leds = 6 endif if var.led = 3 then wiimote.Leds = 12 endif if var.led = 4 then wiimote.Leds = 8 endif if var.led = 5 then wiimote.Leds = 12 endif if var.led = 6 then wiimote.Leds = 6 endif if var.led = 7 then wiimote.Leds = 3 endif wait var.ledspeed var.led = (var.led + 1) % 8 endif //Fà vibrare il Wii quando viene premuto il pulsante B if Wiimote.B = 1 then wiimote.Rumble = var.rumble if Wiimote.B = 0 then wiimote.Rumble = 0 endif //Regola il sistema di controllo IR + Calibrazione SensorBar/Fascia IR var.accx = wiimote.RawForceX + var.xtrim var.accy = wiimote.RawForceY + var.ytrim var.accz = wiimote.RawForceZ + var.ztrim Var.XNun = Wiimote.Nunchuk.Pitch if wiimote.dot1vis and wiimote.dot2vis then if var.accy > -7 then var.orientation = 0 elseif var.accy > -45 then if var.accx < 0 then var.orientation = 3 else var.orientation = 1 endif else var.orientation = 2 endif if var.leftpoint = 0 then if var.orientation = 0 then if wiimote.dot1x < wiimote.dot2x then var.leftpoint = 1 else var.leftpoint = 2 endif endif if var.orientation = 1 then if wiimote.dot1y > wiimote.dot2y then var.leftpoint = 1 else var.leftpoint = 2 endif endif if var.orientation = 2 then if wiimote.dot1x > wiimote.dot2x then var.leftpoint = 1 else var.leftpoint = 2 endif endif if var.orientation = 3 then if wiimote.dot1y < wiimote.dot2y then var.leftpoint = 1 else var.leftpoint = 2 endif endif endif if var.leftpoint = 1 then var.fix1x = wiimote.dot1x var.fix1y = wiimote.dot1y var.fix2x = wiimote.dot2x var.fix2y = wiimote.dot2y else var.fix1x = wiimote.dot2x var.fix1y = wiimote.dot2y var.fix2x = wiimote.dot1x var.fix2y = wiimote.dot1y endif var.dx = var.fix2x - var.fix1x var.dy = var.fix2y - var.fix1y var.cx = (var.fix1x+var.fix2x)/1024.0 - 1 var.cy = (var.fix1y+var.fix2y)/1024.0 - .75 var.d = sqrt(var.dx*var.dx+var.dy*var.dy) var.dx = var.dx / var.d var.dy = var.dy / var.d var.ox = -var.dy*var.cy-var.dx*var.cx; var.oy = -var.dx*var.cy+var.dy*var.cx; var.ax = (var.ox * screen.desktopwidth) + (screen.desktopwidth / 2) var.ay = (-var.oy * screen.desktopwidth) + (screen.desktopheight / 2) var.dx = var.ax - mouse.cursorposx var.dy = var.ay - mouse.cursorposy var.d = sqrt((var.dx*var.dx)+(var.dy*var.dy)) var.a = 180 / (200 + var.d * var.d * var.d * .001) if var.d <= var.deadzone then var.a = 1 debug = var.d + " " + var.a var.finalx = mouse.cursorposx * var.a + var.ax * (1 - var.a) var.finaly = mouse.cursorposy * var.a + var.ay * (1 - var.a) mouse.cursorposx = var.finalx mouse.cursorposy = var.finaly else var.leftpoint = 0 endif