WiiLi Wiki frontpage Include your post in the News Get links Hoteles Quito
WiiLi.org Forum Index WiiLi.org
a new revolution
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Google Earth with Airplane Mode (G-Force)

 
Post new topic   Reply to topic    WiiLi.org Forum Index -> GlovePie
View previous topic :: View next topic  
Author Message
lednerg



Joined: 18 Feb 2007
Posts: 5
Location: New Jersey, US

Digg It
PostPosted: Mon Feb 19, 2007 6:23 am    Post subject: Google Earth with Airplane Mode (G-Force)

Here's something I've been working on for a couple weeks. I'm not going to have as much time to work on it because of a new job. It's got a lot of things I haven't seen elsewhere, which is why I'm making a new topic about it. It's not perfect, going to the edge of the screen in Normal Mode with 2 IR sources is kinda sketchy, for instance. But I just don't think I'll be able to get all the kinks worked out any time soon. If someone wants to work on it, then by all means, have at it.

Press 2 on the Wiimote (while in Google Earth) to make sure that both the script's and Google Earth's modes match. "Airplane Mode" is what Google calls "G-Force". But since most folks don't know what G-Force means (or that it exists), I'm calling it Airplane Mode. It uses an airplane icon, after all.

The battery tester (Home) displays 4 lights until the battery gets below 40%. This is actually how the Wii and Wiimote display battery life. This can be changed in the options.

Code:

/* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//*

   Google Earth w/ Airplane Mode v0.1
   by lednerg

 Calibrate your Wiimote before trying this script:
      ( CP-Settings menu -> Wiimote Calibration )

 Put Google Earth in full-screen (One on Wiimote).

 The Sidebar can be left on.

   --- --- --- --- How to use (default buttons) --- --- --- ---

   Normal Mode:
       Uses only the Wiimote IR sensor (1 or 2 IR sources)
       The mouse can be used while not pointing at an IR source.
 Hold A = Move         - drag the map with the pointer
 Hold B = Zoom         - with 1 IR source:  move cursor up and down
                         with 2 IR sources: move Wiimote forward and back
 A and B = Rotate      - (currently just like with the mouse)

   Airplane Mode:
       Uses only the Wiimote tilt sensor
       The mouse can be used while not pressing a Wiimote button.
 Hold B = Steer        - tilt the Wiimote like a model airplane
              (Start with buttons facing straight up for best results)
 Hold A = Throttle     - tilt up and down to change speed

    Both Modes:
 Two = Switch Modes
 Tap Minus = Top View   (of whatever is in the center of the screen)
 Hold Minus = Zoom Out
 Plus = Zoom In
 Arrow Keys = Move map
 One = Full-Screen Toggle
 Home = Battery Test   - By default, 4 lights represents anything over 40%,
                           which is how Wii measures battery life.
                         This can be changed in Options section below.


*/ /**/ /**/ /**/ /**/ /**/ /**/ /**/ /**/ /**/ /**/ /**/ /**/ /**/ /**/

// --- --- --- --- --- --- --- --- CUSTOMIZE BUTTONS

var.SteerButton = Wiimote.B     // For Airplane Mode
var.ThrottleButton = Wiimote.A  // For Airplane Mode

var.MouseLeftButton = Wiimote.B   // For Normal Mode
var.MouseRightButton = Wiimote.A  // For Normal Mode

var.TopView = Wiimote.minus   // Tap for Top View, hold for Zoom Out
Key.NumPadPlus = Wiimote.plus // Zoom In
Key.F11 = Wiimote.One         // Full-screen Toggle
var.modeChange = Wiimote.Two  // Switch between Airplane and Normal

var.BattButton = Wiimote.Home // Battery Test

Up = Wiimote.Up               // Arrow Keys for moving map
Down = Wiimote.Down
Left = Wiimote.Left
Right = Wiimote.Right

// --- --- --- --- --- --- --- --- OPTIONS

var.startMode = "Normal"      // Starting mode - "Airplane" or "Normal"
var.WiiBatteryMode = true     // Mimicks how Wii measures battery life
var.Talk = true               // Tells you what mode you're using

debug = var.BattDebug + "  [ x: " + mouse.x + "  y: " + mouse.y +" ] "

//\//\//\//\//\///\//\//\//\// CODE START //\//\//\//\//\///\//\//\//\//\//

if var.init = false {
  var.Mode = var.startMode
  var.init = true
  var.steery = .5
  var.steerx = .5
}

if var.modeChange = true {
  if var.mCdone = false {
    if var.Mode = "Airplane" {
      Key.Ctrl+T = true
      Key.Ctrl+T = false
      var.Mode = "Normal"
      mouse.y = 0.5
      mouse.x = 0.5
    elseif var.Mode = "Normal" {
      Key.Ctrl+G = true
      Key.Ctrl+G = false
      var.mode = "Airplane"
      mouse.x = 0.86
      mouse.y = 0.96
    }
    if var.talk = true {
      Say var.mode + "."
    }
  var.mCdone = true
  }
}
if var.modeChange = false {
  var.mCdone = false
}
if var.TopView = true {
  if var.above = false {
    var.above = true
    wait 200ms
    if var.TopView = true {
      Key.NumPadMinus = true
    else
      Key.U = true
      wait 1ms
      Key.U = false
    }
  }
elseif var.TopView = false
  Key.NumPadMinus = false
  var.above = false
}

// =========================     Airplane     ==========================

if var.Mode = "Airplane" {

if var.SteerButton and not var.ThrottleButton = true {
  if var.DragMode != "steer" {
    var.DragMode = "steer"
  }
  if var.MouseLeft != "helddown" {
    var.MouseLeft = "down"
  }
}
if var.SteerButton = false {
  if var.MouseLeft != "up" {
    var.MouseLeft = "up"
  }
}
if var.ThrottleButton and not var.SteerButton = true {
  if var.DragMode != "throttle" {
    var.DragMode = "throttle"
  }
  if var.MouseRight != "helddown" {
    var.MouseRight = "down"
  }
}
if var.ThrottleButton = false {
  if var.MouseRight != "up" {
    var.MouseRight = "up"
  }
}
if var.DragMode = "steer" {
  if var.MouseLeft = "helddown" {
    var.steery = (Wiimote.SmoothPitch/195) + .5
    var.steerx = (Wiimote.SmoothRoll/360) + .5
  }
  mouse.y = Smooth ( var.steery, 30) // Smooth ( (Wiimote.SmoothPitch/195), 30 ) + .5
  mouse.x = Smooth ( var.steerx, 30) // Smooth ( (Wiimote.SmoothRoll/360), 30 ) + .5
}
if var.DragMode = "throttle" {
  mouse.x = 0.8
  mouse.y = mouse.y - ( Smooth ( (Wiimote.SmoothPitch/17000), 3 ) )
  if (mouse.y > 0.75 ) or (mouse.y < 0.28) {
    Mouse.RightButton = false
    var.RightChanged = false
    mouse.y = 0.5
    mouse.x = 0.8
    var.MouseRight = "down"
  }
  var.MouseRight = "down"
}
if var.MouseLeft = "down" {
  var.MouseLeft = "helddown"
  if var.LeftChanged = false {
    var.LeftChanged = true
    Mouse.LeftButton = true
  }
}
if var.MouseLeft = "up" {
  var.MouseLeft = "released"
  var.DragMode = "off"
  if var.LeftChanged = true {
    var.LeftChanged = false
    Mouse.LeftButton = false
    var.steery = .5
    var.steerx = .5
    mouse.x = 0.86
    mouse.y = 0.96
  }
}
if var.MouseRight = "down" {
  var.MouseRight = "helddown"
  if var.RightChanged = false {
    var.RightChanged = true
    mouse.y = 0.5
    mouse.x = 0.8
    Mouse.RightButton = true
  }
}
if var.MouseRight = "up" {
  var.MouseRight = "released"
  var.DragMode = "off"
  if var.RightChanged = true {
    var.RightChanged = false
    Mouse.RightButton = false
    mouse.x = 0.86
    mouse.y = 0.96
  }
}
} // end Airplane

// =========================     Normal     ==========================

if var.Mode = "Normal" {

//debug = "[ "+ Wiimote.SmoothRoll +" / "+ var.irRoll +" ] [ x: "+ var.XP +" y: "+ var.YP +" ]"

if var.MouseLeftButton and not var.MouseRightButton = true {
  if var.MouseLeft != "helddown" {
    var.MouseLeft = "down"
  }
}
if var.MouseRightButton and not var.MouseLeftButton = true {
  if ( Wiimote.dot1vis = false ) or ( Wiimote.dot2vis = false ) {
    if var.MouseRight != "helddown" {
      var.MouseRight = "down"
      if var.zoomIR != false {
        var.zoomIR = false
      }
    }
  else
    if var.zoomIR != true {
      var.zoomIR = true
    }
  }
else
  if var.zoomIR != false {
    var.zoomIR = false
    var.zoomInit = 0
  }
}
if var.MouseLeftButton and var.MouseRightButton = true {
  if var.MouseLeft != "released" {
    var.MouseLeft = "up"
  }
  if var.MouseRight != "released" {
    var.MouseRight = "up"
  }
  if var.MouseMiddle != "helddown" {
    var.MouseMiddle = "down"
  }
}
if var.MouseLeftButton = false {
  if var.MouseLeft != "released" {
    var.MouseLeft = "up"
  }
  if var.MouseRightButton = false {
    if var.MouseMiddle != "released" {
      var.MouseMiddle = "up"
    }
  }
}
if var.MouseRightButton = false {
  if var.MouseRight != "released" {
    var.MouseRight = "up"
  }
}
if var.MouseLeft = "down" {
  if var.LeftChanged = false {
    var.LeftChanged = true
    Mouse.LeftButton = true
    var.MouseLeft = "helddown"
  }
}
if var.MouseRight = "down" {
  if var.RightChanged = false {
    var.RightChanged = true
    Mouse.RightButton = true
    var.MouseRight = "helddown"
  }
}
if var.MouseMiddle = "down" {
  if var.MiddleChanged = false {
    var.MiddleChanged = true
    Mouse.MiddleButton = true
    var.MouseMiddle = "helddown"
  }
}
if var.MouseLeft = "up" {
  if var.LeftChanged = true {
    var.LeftChanged = false
    Mouse.LeftButton = false
    var.MouseLeft = "released"
  }
}
if var.MouseRight = "up" {
  if var.RightChanged = true {
    var.RightChanged = false
    Mouse.RightButton = false
    var.MouseRight = "released"
  }
}
if var.MouseMiddle = "up" {
  if var.MiddleChanged = true {
    var.MiddleChanged = false
    Mouse.MiddleButton = false
    var.MouseMiddle = "released"
  }
}
if var.zoomIR = true {
  if var.zoomInit = 0
    var.zoomInit = abs( Wiimote.dot1x - Wiimote.dot2x ) + abs( Wiimote.dot1y - Wiimote.dot2y )
    mouse.y = 0.5
    mouse.x = 0.8
    var.MouseRight = "down"
  else
    var.zoom = ( abs( Wiimote.dot1x - Wiimote.dot2x ) + abs( Wiimote.dot1y - Wiimote.dot2y ) ) - var.zoominit
    if abs(var.zoom) > 5 {
      mouse.y = smooth (mouse.y + var.zoom / 400, 10)
    }
  }
else
if Wiimote.dot1vis and not Wiimote.dot2vis = true {
  var.dotx = Wiimote.dot1x
  var.doty = Wiimote.dot1y
  if var.wasLeft = 1 {
    var.XP = var.zcXP - var.XPdiff
    var.YP = var.zcYP - var.YPdiff
  elseif var.wasLeft = 2 {
    var.XP = var.zcXP + var.XPdiff
    var.YP = var.zcYP + var.YPdiff
  }
elseif Wiimote.dot2vis and not Wiimote.dot1vis = true {
  var.dotx = Wiimote.dot2x
  var.doty = Wiimote.dot2y
  if var.wasLeft = 2 {
    var.XP = var.zcXP - var.XPdiff
    var.YP = var.zcYP - var.YPdiff
  elseif var.wasLeft = 1 {
    var.XP = var.zcXP + var.XPdiff
    var.YP = var.zcYP + var.YPdiff
  }
}
if ( Wiimote.dot1vis and not Wiimote.dot2vis ) or ( Wiimote.dot2vis and not Wiimote.dot1vis ) {
  if abs( Smooth( Wiimote.Roll, 7) - Wiimote.Roll ) > 45 {
    var.Roll = var.Roll
  else
    var.Roll = Smooth( Wiimote.Roll, 7)
  }
  var.xRaw = ( var.dotx - ( var.Sensitivity * 1.5 ) ) / ( 1024 - ( var.Sensitivity * 2 ) )
  var.yRaw = ( var.doty - var.Sensitivity ) / ( 768 - ( var.Sensitivity * 2 ) )
  var.r = math.sqrt( math.sqr( var.xRaw ) + math.sqr( var.yRaw ) )
  var.t = math.aTan( ( var.xRaw ) / ( var.yRaw ) ) + var.Roll
  var.midX = math.sqrt( .5 ) * math.sin( 45 + var.Roll )
  var.midY = math.sqrt( .5 ) * math.cos( 45 + var.Roll )
  var.preXP = - ( ( var.r ) * math.sin( var.t ) + ( .5 - var.midX ) ) + 1
  var.preYP = ( var.r ) * math.cos( var.t )  + ( .5 - var.midY )
  if var.preXP <= 0 or var.preXP > 1 {
    var.zcXP = mouse.x
  else
    var.zcXP = var.preXP
  }
  if var.preYP <= 0 or var.preYP > 1 {
    var.zcYP = smooth( var.preYP , 5)
  else
    var.zcYP = var.preYP
  }
  if var.wasLeft < 1 {
    var.XP = var.zcXP
    var.YP = var.zcYP
  }
  if abs( Smooth( var.XP, 2) - var.XP ) + abs( Smooth( var.YP, 2) - var.YP)  > .1 {
    mouse.x = var.XP
    mouse.y = var.YP
  elseif abs( Smooth( var.XP, 7) - var.XP ) + abs( Smooth( var.YP, 7) - var.YP )  > .003 {
    mouse.x = Smooth( var.XP, 4)
    mouse.y = Smooth( var.YP, 4)
  }
}
if Wiimote.dot1vis and Wiimote.dot2vis = true {
  if Wiimote.SmoothRoll < 45 and Wiimote.SmoothRoll > -45 {
    if Wiimote.dot1x < Wiimote.dot2x {
      var.irRoll = ArcTan( (Wiimote.dot2y - Wiimote.dot1y) / (Wiimote.dot2x - Wiimote.dot1x) )
    else
      var.irRoll = ArcTan( (Wiimote.dot1y - Wiimote.dot2y) / (Wiimote.dot1x - Wiimote.dot2x) )
    }
  elseif Wiimote.SmoothRoll > 45 and Wiimote.SmoothRoll < 135 {
    if Wiimote.dot1y < Wiimote.dot2y {
      var.preRoll = ArcTan( (Wiimote.dot2y - Wiimote.dot1y) / (Wiimote.dot2x - Wiimote.dot1x) )
    else
      var.preRoll = ArcTan( (Wiimote.dot1y - Wiimote.dot2y) / (Wiimote.dot1x - Wiimote.dot2x) )
    }
    if var.preRoll < 0 {
      var.irRoll = (var.preRoll + 180)
    else
      var.irRoll = var.preRoll
    }
  elseif Wiimote.SmoothRoll < -45 and Wiimote.SmoothRoll > -135 {
    if Wiimote.dot1y > Wiimote.dot2y {
      var.preRoll = ArcTan( (Wiimote.dot2y - Wiimote.dot1y) / (Wiimote.dot2x - Wiimote.dot1x) )
    else
      var.preRoll = ArcTan( (Wiimote.dot1y - Wiimote.dot2y) / (Wiimote.dot1x - Wiimote.dot2x) )
    }
    if var.preRoll > 0 {
      var.irRoll = (var.preRoll - 180)
    else
      var.irRoll = var.preRoll
    }
  else
    if Wiimote.dot1x < Wiimote.dot2x {
      var.irRoll = 180 + ArcTan( (Wiimote.dot2y - Wiimote.dot1y) / (Wiimote.dot2x - Wiimote.dot1x) )
    else
      var.irRoll = 180 + ArcTan( (Wiimote.dot1y - Wiimote.dot2y) / (Wiimote.dot1x - Wiimote.dot2x) )
    }
  }
  var.1xRaw = ( Wiimote.dot1x - ( var.Sensitivity * 1.5 ) ) / ( 1024 - ( var.Sensitivity * 2 ) )
  var.1yRaw = ( Wiimote.dot1y - var.Sensitivity ) / ( 768 - ( var.Sensitivity * 2 ) )
  var.2xRaw = ( Wiimote.dot2x - ( var.Sensitivity * 1.5 ) ) / ( 1024 - ( var.Sensitivity * 2 ) )
  var.2yRaw = ( Wiimote.dot2y - var.Sensitivity ) / ( 768 - ( var.Sensitivity * 2 ) )
  var.1r = math.sqrt( math.sqr( var.1xRaw ) + math.sqr( var.1yRaw ) )
  var.2r = math.sqrt( math.sqr( var.2xRaw ) + math.sqr( var.2yRaw ) )
  var.1t = math.aTan( ( var.1xRaw ) / ( var.1yRaw ) ) + var.irRoll
  var.2t = math.aTan( ( var.2xRaw ) / ( var.2yRaw ) ) + var.irRoll
  var.midX = math.sqrt( .5 ) * math.sin( 45 + var.irRoll )
  var.midY = math.sqrt( .5 ) * math.cos( 45 + var.irRoll )
  var.1xP = - ( ( var.1r ) * math.sin( var.1t ) + ( .5 - var.midX ) ) + 1
  var.2xP = - ( ( var.2r ) * math.sin( var.2t ) + ( .5 - var.midX ) ) + 1
  var.1yP = ( var.1r ) * math.cos( var.1t )  + ( .5 - var.midY )
  var.2yP = ( var.2r ) * math.cos( var.2t )  + ( .5 - var.midY )
  if var.1xP > var.2xP {
    var.XPdiff = ( ( var.1xP - var.2xP ) / 2 )// * ( var.1xP / .50 )
    var.YPdiff = ( ( var.1yp - var.2yP ) / 2 )// * ( var.1yP / .50 )
    var.wasLeft = 1
    var.XP = var.1xP - var.XPdiff
    var.YP = var.1yP - var.YPdiff
  elseif var.2xP > var.1xP {
    var.XPdiff = ( ( var.2xP - var.1xP ) / 2 )// * ( var.2xP / .50 )
    var.YPdiff = ( ( var.2yp - var.1yP ) / 2 )// * ( var.2yP / .50 )
    var.wasLeft = 2
    var.XP = var.2xP - var.XPdiff
    var.YP = var.2yP - var.YPdiff
  }
  if var.XP < 0 or var.XP > 1 {
    var.zcXP = mouse.x
  else
    var.zcXP = var.XP
  }
  if var.YP < 0 or var.YP > 1 {
    var.zcYP = mouse.y
  else
    var.zcYP = var.YP
  }
  if abs( Smooth( var.zcXP, 2) - var.zcXP ) + abs( Smooth( var.zcYP, 2) - var.zcYP)  > .1 {
    mouse.x = var.zcXP
    mouse.y = var.zcYP
  elseif abs( Smooth( var.zcXP, 7) - var.zcXP ) + abs( Smooth( var.zcYP, 7) - var.zcYP )  > .003 {
    mouse.x = Smooth( var.zcXP, 3)
    mouse.y = Smooth( var.zcYP, 3)
  }
}
}
}
//
// Detailed Battery Indicator v0.03
// by lednerg
//
// Example reading:
// [x] [ ] [ ] [ ]   then   [x] [x] [x] [ ]   (a quick flash)
//
//    This would mean...
//   One full bar    plus    3/4 of the 2nd bar
//  ...or just under half the battery
//
// No flash means the battery level is at/near a 25% increment.
//
// With WiiBatteryMode set to true, the 4 bars represent the last 40%.

// var.BattButton = Wiimote.Home // Button for checking battery
// var.BattWiiMode = true // Mimicks how Wii measures battery life

var.BattDebug = "  [ Battery: " + int(var.BattRead / 2) + "% ]  " + var.tick

if var.BattButton = true {
  if var.BattRunning = false {
    var.BattMode = "battTest"
    var.BattRunning = true
  }
}
if var.BattMode = "battTest" {
  if var.BattTested = false {
    var.BattTested = true
    var.BattRead = wiimote.battery
    Wiimote.Report15 = 0x80 | Int(wiimote.Rumble)
  }
  if var.WiiBatteryMode = true {
    if var.BattRead >= 80 {
      if var.BattRead >= 200 {
        wait 1 s
        var.BattMode = "battTest"
        var.BattTested = false
      elseif var.BattRead < 200
        var.BattPLEDs = false
        var.BattFullLED = 15
        var.BattNum = Int(var.BattRead / 2 , 0 )
        var.BattMode = "lightStart"
      }
    else
      var.BattNum = Int(var.BattRead / 2 , 0 )
      var.BattMode = "fullLED"
    }
  else
    if var.BattRead >= 200 {
      wait 1 s
      var.BattMode = "battTest"
      var.BattTested = false
    else
      var.BattNum = Int(var.BattRead / 5 , 0 )
      var.BattMode = "fullLED"
    }
  }
  var.BattTen = ( Int ( var.BattNum / 10 , 1 ) * 10 )
}
if var.BattMode = "fullLED" {
  if var.BattNum >= 9 {
    var.BattFullLED = 1
    if var.BattNum >= 19 {
      for var.BattCount = 9 to ( var.BattNum ) step 10 {
        var.BattFullLED = var.BattFullLED + var.BattFullLED
      }
      var.BattFullLED = var.BattFullLED - 1
    }
  else
    var.BattFullLED = 0
  }
  var.BattMode = "partLED"
}
if var.BattMode = "partLED" {
  if 9 > ( var.BattNum - var.BattTen ) > 1 {
    var.BattPartLED = 1
    for var.BattCount = 1 to Round( ( var.BattNum - var.BattTen ) / 2.5 ) {
      var.BattPartLED = var.BattPartLED + var.BattPartLED
    }
    var.BattPartLED = var.BattPartLED - 1
    var.BattPLEDs = true
    var.BattMode = "lightStart"
    else
      var.BattPLEDs = false
      var.BattMode = "lightStart"
    }
  else
}
if var.BattMode = "lightStart" {
  if var.BattRead <= 24 then
  if var.BattWarned <= 0 then
    Say "bat-tery is low"
    var.BattWarned = 1
  endif
  endif
  if var.BattPLEDs = true {
    Wiimote.Leds = var.BattFullLED
    wait 1000 ms
    Wiimote.Leds = 0
    wait 236 ms
    Wiimote.Leds = var.BattPartLED
    wait 2 ms
    Wiimote.Leds = 0
    wait 20 ms
    Wiimote.Leds = var.BattPartLED
    wait 2 ms
    Wiimote.Leds = 0
    wait 240 ms
    var.BattMode = "lightEnd"
  else
    Wiimote.Leds = var.BattFullLED
    var.BattFullOnly = true
    wait 1500 ms
    var.BattMode = "lightEnd"
  }
}
if var.BattMode = "lightEnd" {
  if var.BattButton = false {
    Wiimote.Leds = 0
    var.BattRunning = false
    var.BattMode = "OFF"
    var.BattTested = false
  else
    var.BattTested = false
    var.BattMode = "battTest"
  }
  var.BattPLEDs = false
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    WiiLi.org Forum Index -> GlovePie All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group