ZEN Tech NZ

AvatarIf there are no technical difficulties rights now, there will be!

Using a Wiimote as an Input Device - Part IV

And after a bit of cut 'n' paste magic we now have a very basic GlovePIE script that we can use to control our avatar in Second Life.



So, in summary we need to follow the following steps for it all to work together.
  1. 'connect' the Wiimote to the PC via Bluetooth
  2. startup GlovePIE
  3. run our script and don't forget to fine tune it
  4. startup SecondLife
  5. and enjoy!
End of Part IV

Using a Wiimote as a PC Input Device - Part IIIB

So now at this point we start cobbling together the scripts we need, again, most of this has been hacked and pasted from other scripts I've seen around.

First we define some of the theshold values:

var.sense0 = 1000
var.thresh0x = 2
var.thresh0y = 1

var.sense = 300
var.threshx = 10
var.threshy = 5

var.sense2 = 100
var.thresh2x = 15
var.thresh2y = 8

var.sense3 = 50
var.thresh3x = 20
var.thresh3y = 12

You can play around with these values later on to fine tune the translation from Wiimote movements to mouse movements.

if var.x > var.thresh0x
mouse.x = mouse.x - 1/var.sense0
endif
if var.x < -var.thresh0x
mouse.x = mouse.x + 1/var.sense0
endif
if var.z > var.thresh0y
mouse.y = mouse.y - 1/var.sense0
endif
if var.z < -var.thresh0y
mouse.y = mouse.y + 1/var.sense0
endif
if var.x > var.threshx
mouse.x = mouse.x - 1/var.sense
endif
if var.x < -var.threshx
mouse.x = mouse.x + 1/var.sense
endif
if var.z > var.threshy
mouse.y = mouse.y - 1/var.sense
endif
if var.z < -var.threshy
mouse.y = mouse.y + 1/var.sense
endif
if var.x > var.thresh2x
mouse.x = mouse.x - 1/var.sense2
endif
if var.x < -var.thresh2x
mouse.x = mouse.x + 1/var.sense2
endif
if var.z > var.thresh2y
mouse.y = mouse.y - 1/var.sense2
endif
if var.z < -var.thresh2y
mouse.y = mouse.y + 1/var.sense2
endif
if var.x > var.thresh3x
mouse.x = mouse.x - 1/var.sense3
endif
if var.x < -var.thresh3x
mouse.x = mouse.x + 1/var.sense3
endif
if var.z > var.thresh3y
mouse.y = mouse.y - 1/var.sense3
endif
if var.z < -var.thresh3y
mouse.y = mouse.y + 1/var.sense3
endif

End Part IIIB

Using a Wiimote as a PC Input Device - Part IIIA

Now we need to look and see how to get and use the  readings from the RawForce sensors, first, because every set up is different we need a way of 'centering' the mouse. We do this by using some 'trim' variables:

var.trimx = 6
var.trimy = -31
var.trimz = 6

var.x = Wiimote.RawForceX + var.trimx
var.y = Wiimote.RawForceY + var.trimy
var.z = Wiimote.RawForceZ + var.trimz

debug = var.x + " " + var.y + " " + var.z

The last line will display the values in those variables, you will have to adust the var.trimx, var.trimy and var.trimz values until the displayed var.x, var.y and var.z all equal 0 (zero).

End Part IIIA

Using a Wiimote as a PC Input Device - Part II

GlovePIE comes with a whole bunch of sample scripts which can be found in the installed WiimoteScripts directory. 

After spending a bit of time perusing through the many scripts I decided to throw something together based on 'WiiMouse 0.1' by WiiScript.co.nr

First the 'easy stuff' -- mapping the keyboard arrow keys with the cross-pad on the Wiimote like this:

Up = Wiimote.Up
Down = Wiimote.Down
Left = Wiimote.Left
Right = Wiimote.Right

Then we map the mouse buttons:

Mouse.LeftButton = Wiimote.B
Mouse.RightButton = Wiimote.A

I decided to map the '+' and '-' buttons on the Wiimote to the Mouse Wheel, and the 'Home' key to Escape:

Mouse.WheelUp = Wiimote.Plus
Mouse.WheelDown = Wiimote.Minus
Key.Escape = Wiimote.Home

End of Part II

.


Using a Wiimote as a PC Input Device - Part I

I was looking around for alternative input devices for taking control over my avatar in Second Life, when I stumble upon an article about Nintendo Wiis and Wiimotes. A bit more reading told me that the Wiimote uses Bluetooth to talk to the Wii.

A quick trip to the local games store and we're in business! It was a no-brainer connecting the Wiimote to the PC. The only gotcha being that the Wiimote does not automatically connect to the PC after a reboot.

The next step was to find some software to translate the Wiimote's movements and clicks into mouse movements and clicks. A quick Google search yielded GlovePIE as glue I needed. Originally intended to be used with VR gloves it supports inputs from the Wiimote (and Nunchuk addon) but also a whole raft of other controllers including joysticks.

End of Part I