# Wiimote Project

### Author Topic: GlovePie Script: Wiimote 6DOF HeadTracking, now with youtube demo  (Read 38952 times)

#### manuel82

• Posts: 7
• Karma: +2/-0
on: June 10, 2008, 06:39:43 PM
Hello people,

first, here the demo: http://www.youtube.com/watch?v=QZFhXjlIiXo

I've written a little script for glovepie (http://carl.kenner.googlepages.com/glovepie) to use our beloved wiimote as a 6 degree of freedom headtracker. This can be used with every game that supports TrackIR (see TrackIR.com for list of games...)!
The only thing you need is a IR light source with three dots aligned horizontally, the same as Johnny Lee demonstrates plus one dot in the middle; this one needs to be a little bit behind the outer ones (say 5cm or more, see value var.DotDepth). I installed LEDs/reflectors on a cap.

The geometry isn't done exactly, but can be calculated very fast this way. Fortunately, your brain can compensate for the small non-linearities that arise due to this! even without headache :-)

I would appreciate leaving my name in the scriptheader below.

Enjoy and tell me your opinion!

Manuel Unternaehrer

MyHeadTracker.pie :
Code: [Select]
`// 6 Degrees of Freedom Headtracking with wiimote// 2008 by Manuel Unternaehrer// Inspired by Johnny Lee: http://www.cs.cmu.edu/~johnny/projects/wii/wiimote.Leds = 1     //Choose whatever you like :-)var.DotDist = .12     //Distance left+right dot, in metersvar.DotDepth = 0.045  //Depth of middle dot//Adjust Smoothing, Amplifying (Factor) and CalibrationFakeTrackIR.x=-smooth(var.pos[1],50)FakeTrackIR.y=smooth(var.pos[2],50)FakeTrackIR.z=smooth(var.pos[3],50)FakeTrackIR.yaw=-smooth(var.yaw,50)*30FakeTrackIR.roll=smooth(var.roll,50)FakeTrackIR.pitch=-smooth((var.pitch - 30),50)*10var.scenter = [1024,768,0]/2/1024 //Sensor's centervar.p1 = [wiimote.dot1x/1024,wiimote.dot1y/1024,0]var.p2 = [wiimote.dot2x/1024,wiimote.dot2y/1024,0]var.p3 = [wiimote.dot3x/1024,wiimote.dot3y/1024,0]//Look for Left, Right and Middle dotif wiimote.dot1x < wiimote.dot2x then   if wiimote.dot1x < wiimote.dot3x then      var.pleft = var.p1      var.pmid = 0   else       var.pleft = var.p3       var.pmid = var.p1   endif   if wiimote.dot2x < wiimote.dot3x then      var.pright = var.p3      var.pmid = var.p2   else       var.pright = var.p2       if var.pmid = 0 then var.pmid = var.p3   endifelse    if wiimote.dot2x < wiimote.dot3x then       var.pleft = var.p2       var.pmid = 0    else        var.pleft = var.p3        var.pmid = var.p2    endif    if wiimote.dot1x < wiimote.dot3x then       var.pright = var.p3       var.pmid = var.p1    else        var.pright = var.p1        if var.pmid = 0 then var.pmid = var.p3    endifendif//Do the geometric stuffif wiimote.dot1vis and wiimote.dot2vis and wiimote.dot3vis thenvar.posZ = var.DotDist/Tan(Abs(var.pright-var.pleft)*45)var.pos = ((var.pright+var.pleft)/2-var.scenter)*var.posZ + [0,0,var.posZ]var.roll = aSin((var.pright-var.pleft)[2]/Abs(var.pright-var.pleft))var.pmidoff = Abs((var.pright-var.pleft) cross (var.pmid-var.pleft))/Abs(var.pright-var.pleft)^2 //0..1,middle dot off-linevar.pmidcent = ((var.pright-var.pleft) dot (var.pmid-var.pleft))/Abs(var.pright-var.pleft)^2 //0..1, middle dot off-centervar.turn = aTan((0.5-var.pmidcent)/(var.DotDepth*Cos(var.pitch)/var.DotDist))var.yaw = var.turn - 45*((var.pright+var.pleft)/2-var.scenter)[1]var.pitch = aSin(var.pmidoff/(var.DotDepth/var.DotDist)) + 45*((var.pright+var.pleft)/2-var.scenter)[2]debug = smooth(var.pos,50) + " " + smooth(var.yaw,50) + " " + smooth(var.pitch,50)+ " " + smooth(var.roll,50)endif//Test 3D Visualisation, comment out if not neededobj4.colour= 0xFFFF00obj4.cubesize= 10cmobj4.x=0.obj4.y=0.obj4.z=1.3mobj5.colour= 0xFFFFFFobj5.cubesize= 2cmobj5.x=0.obj5.y=0.obj5.z=1mcam.x=-smooth(var.pos[1],50)  *5cam.y=smooth(var.pos[2],50)    *5cam.z=-smooth(var.pos[3],50)  *3 +1cam.yaw=-smooth(var.yaw,50)cam.roll=smooth(var.roll,50)cam.pitch=-smooth((var.pitch-30),50)`
« Last Edit: July 11, 2008, 04:17:25 PM by manuel82 »

#### tillydevine

• Posts: 22
• Karma: +0/-1
Reply #1 on: June 10, 2008, 10:45:28 PM
I think that you are my hero. Could I use this with HL2 or Doom3 (Quake etc...) instead of the other first person shooters thats mentioned in the list?

#### manuel82

• Posts: 7
• Karma: +2/-0
Reply #2 on: June 11, 2008, 08:42:50 PM
Hi,

I'm not quite sure whether this works with other games. Probably not over the TrackIR Interface. Depending on how the camera in this games are controlled, the script could be adapted do control it according to your head moving...

Here another little piece of code. this time it's a sort of fishtank made with glovePie, like the one Johnny Lee presents. You need a 2-dot glasses. there's even an object "in front of the monitor". Closing one eye gets a much stronger effect, try it out!

greets, Manuel

PS: insert "cam.Stereoscopic=true" and watch it with colored glasses... amazing ! :-)

fishtank.pie
use the one below
« Last Edit: June 13, 2008, 09:23:07 AM by manuel82 »

#### tillydevine

• Posts: 22
• Karma: +0/-1
Reply #3 on: June 11, 2008, 09:37:58 PM
Like i said before.. H.E.R.O.!!!

Thank you will play with this glovepie script later!

#### manuel82

• Posts: 7
• Karma: +2/-0
Reply #4 on: June 13, 2008, 09:22:19 AM
Me again, with a much better fishtank

fishtank2.pie
Code: [Select]
`// Fishtank with glovepie and wiimote, 2 dots needed// Watching the fishtank, Close one eye, the effect is much greater!// 2008 by Manuel Unternaehrer// Inspired by Johnny Lee: http://www.cs.cmu.edu/~johnny/projects/wii/pie.framerate=50Hzwiimote.Leds = 1     //Choose whatever you like :-)var.DotDist = .12 m    //Distance left+right dot, in metersvar.ScreenHeight = .18 m  //Visualisation Window's Height, measured with ruler//interesting partcam.x=-smooth(var.pos[1],5)cam.y=smooth(var.pos[2],5)cam.z=-smooth(var.pos[3],5)cam.yaw=smooth(var.yaw,5)cam.roll=0cam.pitch=-smooth((var.pitch),5)cam.vFov=aTan(var.ScreenHeight/(smooth(var.posZ,5))/2)*2cam.nearclip=10cm// cam.Stereoscopic=true// the rest is my degenerated 6DOF Headtracker (with much shorter code)var.scenter = [1024,768,0]/2/1024 //Sensor's centervar.p1 = [wiimote.dot1x/1024,wiimote.dot1y/1024,0]var.p2 = [wiimote.dot2x/1024,wiimote.dot2y/1024,0]//Look for Left, Right and Middle dotif wiimote.dot1x < wiimote.dot2x then  var.pleft = var.p1  var.pright = var.p2else    var.pleft =var.p2    var.pright = var.p1endif//Do the geometric stuffif wiimote.dot1vis and wiimote.dot2vis  thenvar.posZ = var.DotDist/Tan(Abs(var.pright-var.pleft)*45)var.pos = ((var.pright+var.pleft)/2-var.scenter)*var.posZ*3.14/4 + [0,0,var.posZ]var.yaw = 45*((var.pright+var.pleft)/2-var.scenter)[1]   //Changed for Fishtank demovar.pitch =  45*((var.pright+var.pleft)/2-var.scenter)[2]  //Changed for Fishtank demoendifdebug = smooth(var.pos,0) + " " + smooth(var.yaw,0) + " " + smooth(var.pitch,0)+ " " + smooth(var.roll,0)//Test 3D Visualisation, comment out if not neededobj4.colour= 0xFFFF00obj4.cubesize= var.ScreenHeightobj4.x=0.obj4.y=0.obj4.z=.5mobj5.colour= 0xFFFFFFobj5.cubesize= 2cmobj5.x=0.obj5.y=0.obj5.z=0.2m//Object "in front of the monitor":obj12.colour= 0x0000FFobj12.cubesize= 2cmobj12.x=0.obj12.y=0.obj12.z=-0.1mobj1.colour= 0xFFFF00obj1.cubesize= 2cmobj1.pos = [-var.ScreenHeight/2,-var.ScreenHeight/2,.2]obj2.colour= 0xFFFF00obj2.cubesize= 2cmobj2.pos = [var.ScreenHeight/2,-var.ScreenHeight/2,.2]obj6.colour= 0xFFFF00obj6.cubesize= 2cmobj6.pos = [-var.ScreenHeight/2,var.ScreenHeight/2,.2]obj7.colour= 0xFFFF00obj7.cubesize= 2cmobj7.pos = [var.ScreenHeight/2,var.ScreenHeight/2,.2]obj8.colour= 0xFFFF00obj8.cubesize= 2cmobj8.pos = [var.ScreenHeight/2,-var.ScreenHeight/2,.0]obj9.colour= 0xFFFF00obj9.cubesize= 2cmobj9.pos = [-var.ScreenHeight/2,-var.ScreenHeight/2,.0]obj10.colour= 0xFFFF00obj10.cubesize= 2cmobj10.pos = [var.ScreenHeight/2,var.ScreenHeight/2,0.0]obj11.colour= 0xFFFF00obj11.cubesize= 2cmobj11.pos = [-var.ScreenHeight/2,var.ScreenHeight/2,.0]`

#### manuel82

• Posts: 7
• Karma: +2/-0
Reply #5 on: June 19, 2008, 05:30:15 PM
300 views an no feedbacks?

But I hope some of you try it out and see how well it works... Greets

#### tillydevine

• Posts: 22
• Karma: +0/-1
Reply #6 on: June 19, 2008, 08:29:44 PM
I have tried it. I LOVE it!!!!!

I didn't know you could place objects (cubes) on screen using glovepie. Is it possible to place complex models in a simalar way?

#### Anhar Miah

• Posts: 3
• Karma: +0/-0
Reply #7 on: June 23, 2008, 08:54:28 AM
wow, excellent work!

Can you please explain the maths and how you calculated the 6DOF? if its not too much to ask could you also upload an diagram showing the how its calcaulated?

I've been trying to figure out how to do 6DOF (and I couldn't work out how the POSIT algorithm works)
thanks in advanced,

I've been struggling with 6DOF for such a long time, if you could help me out your a star man!

Anhar

#### manuel82

• Posts: 7
• Karma: +2/-0
Reply #8 on: July 07, 2008, 04:38:13 PM
here the demo: http://www.youtube.com/watch?v=QZFhXjlIiXo

I'll make a documentation as soon as I have time and I'm in the mood to do it :-)

Greets

BTW: in this demo I used a negativ "DotDepth" value, because the middle dot is *in front of* the others
« Last Edit: July 08, 2008, 12:14:15 PM by manuel82 »

#### tillydevine

• Posts: 22
• Karma: +0/-1
Reply #9 on: July 07, 2008, 08:33:14 PM
OH MAN!!!! Thats sooooo what i'm after!!

I take it its easy to use the glovepie script, then start a game and then start playing?

#### jmatson

• Posts: 24
• Karma: +0/-0
Reply #10 on: July 09, 2008, 09:41:31 PM
here the demo: http://www.youtube.com/watch?v=QZFhXjlIiXo

I'll make a documentation as soon as I have time and I'm in the mood to do it :-)

Greets

BTW: in this demo I used a negativ "DotDepth" value, because the middle dot is *in front of* the others

Wow, I love what you have done with this!  Thank you!  I have a question though.  I used the fishtank one that uses the 2 dot glasses.  I can run the script and watch what happens to the cubes within glovepie, but how can I get it to work with TrackIR games like you did in the video.  I have downloaded the demo of "Live for Speed" from the TrackIR website you included.  Am I doing something wrong?

#### manuel82

• Posts: 7
• Karma: +2/-0
Reply #11 on: July 10, 2008, 02:33:40 PM
Hi,

in order to use it in games you need the first script, the "headtracker" and not the "fishtank". This one needs 3 dots, as you can see in the youtube movie, so as to calculate not only the position of your head (X,Y,Z) but also its turning-axes (Pitch, Yaw and Roll).
Using a 3dot headset, simply run the script in glovepie, minimize the glovepie window, start the game, et voilą, that's it. (Glovepie simulates a virtual TrackIR-device)

I hope this helps you

greets

#### jmatson

• Posts: 24
• Karma: +0/-0
Reply #12 on: July 10, 2008, 04:33:56 PM
Hi,

in order to use it in games you need the first script, the "headtracker" and not the "fishtank". This one needs 3 dots, as you can see in the youtube movie, so as to calculate not only the position of your head (X,Y,Z) but also its turning-axes (Pitch, Yaw and Roll).
Using a 3dot headset, simply run the script in glovepie, minimize the glovepie window, start the game, et voilą, that's it. (Glovepie simulates a virtual TrackIR-device)

I hope this helps you

greets

Perfect!  Thanks for your help!  Do you have any ideas of how to make my 2 dot glasses into 3 dots?

#### Maginomicon

• Posts: 4
• Karma: +0/-0
Reply #13 on: July 13, 2008, 07:20:12 PM
I always thought a 3-horizontal-LEDs system would work. Looks like someone beat me to the punch.

Now that you can use your head as a pointer, if you combine that with the "look margin" technique seen in Metroid Prime 3, the Wiimote in your hand becomes free to point wherever you want.

Now that you don't have to use a Wiimote you hold for looking and turning, Two-mote Style (holding a Wiimote in each hand) is now an option. (Use the D-Pad for moving and strafing)

Granted, a head pointer isn't precise enough to select objects like you would with a normal pointer, but that's no big deal. You could just use a Wiimote the normal way for that.
« Last Edit: July 13, 2008, 07:39:19 PM by Maginomicon »

#### xathor

• Posts: 1
• Karma: +0/-0
Reply #14 on: August 06, 2008, 03:36:30 PM
This is awesome.  I purchased a Wiimote (~\$30) a bluetooth adapter (\$30 from target) and some IR led's, resistor, AC adapter, some solder and misc stuff (\$30 from radio shack)...

I have GlovePIE and your script, but when I run your script and go into FSX nothing happens.  Im sure there's more to it than just that?

This would make me infinitely happy if I could get this to work with FSX.