Wiimote Project

Wiimote Projects => Wiimote Desktop VR/Head Tracking => Topic started by: manuel82 on June 10, 2008, 06:39:43 PM

Title: GlovePie Script: Wiimote 6DOF HeadTracking, now with youtube demo
Post by: manuel82 on June 10, 2008, 06:39:43 PM
Hello people,

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

I've written a little script for glovepie (http://carl.kenner.googlepages.com/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 (http://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 meters
var.DotDepth = 0.045  //Depth of middle dot

//Adjust Smoothing, Amplifying (Factor) and Calibration
FakeTrackIR.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)*30
FakeTrackIR.roll=smooth(var.roll,50)
FakeTrackIR.pitch=-smooth((var.pitch - 30),50)*10

var.scenter = [1024,768,0]/2/1024 //Sensor's center
var.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 dot
if 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
   endif
else
    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
    endif
endif

//Do the geometric stuff
if wiimote.dot1vis and wiimote.dot2vis and wiimote.dot3vis then

var.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-line
var.pmidcent = ((var.pright-var.pleft) dot (var.pmid-var.pleft))/Abs(var.pright-var.pleft)^2 //0..1, middle dot off-center

var.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 needed
obj4.colour= 0xFFFF00
obj4.cubesize= 10cm
obj4.x=0.
obj4.y=0.
obj4.z=1.3m
obj5.colour= 0xFFFFFF
obj5.cubesize= 2cm
obj5.x=0.
obj5.y=0.
obj5.z=1m

cam.x=-smooth(var.pos[1],50)  *5
cam.y=smooth(var.pos[2],50)    *5
cam.z=-smooth(var.pos[3],50)  *3 +1
cam.yaw=-smooth(var.yaw,50)
cam.roll=smooth(var.roll,50)
cam.pitch=-smooth((var.pitch-30),50)
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking
Post by: tillydevine 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?
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking
Post by: manuel82 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
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking
Post by: tillydevine 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!
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking
Post by: manuel82 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=50Hz

wiimote.Leds = 1     //Choose whatever you like :-)

var.DotDist = .12 m    //Distance left+right dot, in meters
var.ScreenHeight = .18 m  //Visualisation Window's Height, measured with ruler

//interesting part
cam.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=0
cam.pitch=-smooth((var.pitch),5)
cam.vFov=aTan(var.ScreenHeight/(smooth(var.posZ,5))/2)*2
cam.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 center
var.p1 = [wiimote.dot1x/1024,wiimote.dot1y/1024,0]
var.p2 = [wiimote.dot2x/1024,wiimote.dot2y/1024,0]

//Look for Left, Right and Middle dot
if wiimote.dot1x < wiimote.dot2x then
  var.pleft = var.p1
  var.pright = var.p2
else
    var.pleft =var.p2
    var.pright = var.p1
endif

//Do the geometric stuff
if wiimote.dot1vis and wiimote.dot2vis  then

var.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 demo

var.pitch =  45*((var.pright+var.pleft)/2-var.scenter)[2]  //Changed for Fishtank demo

endif

debug = smooth(var.pos,0) + " " + smooth(var.yaw,0) + " " + smooth(var.pitch,0)+ " " + smooth(var.roll,0)

//Test 3D Visualisation, comment out if not needed
obj4.colour= 0xFFFF00
obj4.cubesize= var.ScreenHeight
obj4.x=0.
obj4.y=0.
obj4.z=.5m

obj5.colour= 0xFFFFFF
obj5.cubesize= 2cm
obj5.x=0.
obj5.y=0.
obj5.z=0.2m

//Object "in front of the monitor":
obj12.colour= 0x0000FF
obj12.cubesize= 2cm
obj12.x=0.
obj12.y=0.
obj12.z=-0.1m

obj1.colour= 0xFFFF00
obj1.cubesize= 2cm
obj1.pos = [-var.ScreenHeight/2,-var.ScreenHeight/2,.2]

obj2.colour= 0xFFFF00
obj2.cubesize= 2cm
obj2.pos = [var.ScreenHeight/2,-var.ScreenHeight/2,.2]

obj6.colour= 0xFFFF00
obj6.cubesize= 2cm
obj6.pos = [-var.ScreenHeight/2,var.ScreenHeight/2,.2]

obj7.colour= 0xFFFF00
obj7.cubesize= 2cm
obj7.pos = [var.ScreenHeight/2,var.ScreenHeight/2,.2]

obj8.colour= 0xFFFF00
obj8.cubesize= 2cm
obj8.pos = [var.ScreenHeight/2,-var.ScreenHeight/2,.0]

obj9.colour= 0xFFFF00
obj9.cubesize= 2cm
obj9.pos = [-var.ScreenHeight/2,-var.ScreenHeight/2,.0]

obj10.colour= 0xFFFF00
obj10.cubesize= 2cm
obj10.pos = [var.ScreenHeight/2,var.ScreenHeight/2,0.0]

obj11.colour= 0xFFFF00
obj11.cubesize= 2cm
obj11.pos = [-var.ScreenHeight/2,var.ScreenHeight/2,.0]

Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking
Post by: manuel82 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
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking
Post by: tillydevine 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?
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking
Post by: Anhar Miah 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
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking (now with youtube demo)
Post by: manuel82 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
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking (now with youtube demo)
Post by: tillydevine 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?
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking (now with youtube demo)
Post by: jmatson 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? 
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking (now with youtube demo)
Post by: manuel82 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
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking (now with youtube demo)
Post by: jmatson 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?
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking, now with youtube demo
Post by: Maginomicon 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.  ;)

(http://www.rpgrevolution.com/images/game_screens/11/led_glasses.PNG)

Now that you can use your head as a pointer, if you combine that with the "look margin" technique seen in Metroid Prime 3 (http://www.youtube.com/watch?v=1yAtybU2B3k), 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.
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking, now with youtube demo
Post by: xathor 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.
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking, now with youtube demo
Post by: manuel82 on August 07, 2008, 06:06:36 PM
Hi,

check out this site first: http://www.naturalpoint.com/trackir/03-enhanced-games/game-flight-simulator-x.html

you need to update FSX to use headtrackers as you can read there. I don't posses the FSX, so I can't help you any further.

Make sure the wiimote sees your LEDs. If the cube in glovepie moves, everything is fine...
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking, now with youtube demo
Post by: Maginomicon on August 17, 2008, 07:20:10 PM
(http://i22.photobucket.com/albums/b320/Maginomicon/mw/irled_cap.jpg)

My intention was to create a "kit" that could be mass-produced and be effortlessly attached to any baseball cap.

The IRLEDS are attached to simple clips like shown. The housing for a triple-A battery could be attached to the top of the middle IRLED clip so that there's only two wires total, from the middle to the two sides. The IRLEDs are exposed and pointing down so that they're never obstructed even when standing up some distance from the screen.

Can you see any reason why this wouldn't work?

If it would work, I've got a Wiimote stand NOT made out of plastic or metal that you might be interested in seeing.
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking, now with youtube demo
Post by: neronix on October 22, 2008, 10:33:28 PM
Hi,

I have a problem, I can't run the script with GlovePie.
When I click RUN, these lines turn red

cam.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=0
cam.pitch=-smooth((var.pitch),5)
cam.vFov=aTan(var.ScreenHeight/(smooth(var.posZ,5))/2)*2
cam.nearclip=10cm

I believe "cam" is supposed to be associate to something but I can't figure what.
thx
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking, now with youtube demo
Post by: neronix on October 22, 2008, 10:51:11 PM
Problem solved .... It only works on version .30
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking, now with youtube demo
Post by: MadMax on December 10, 2008, 06:33:37 AM
Hi, :D


I  found very interesting your  "6 DOF script" but it seam work only for games, it's a sin... why not impement "exportation of ASCII motion data"  i.e.

" http://www.wiili.org/index.php/GlovePIE:Capture_Motion_Data "

Or, better and better, standard BVH file format exportation:

"Motion camera capture" is very very amazing and useful for CG artists and animators... the possibility to capture motion data is a great thing because is very very easy for 3d artists retarget the movement of a single BVH bone to a virtual camera and the result should be greats for all CG comunities. ;) ;)   ;)


 
 
kindest regards. :D
Title: Re: GlovePie Script: Wiimote 6DOF HeadTracking, now with youtube demo
Post by: Wiweeyum on December 10, 2008, 07:00:34 AM
I'm not sure I'd regard it a 'sin' persay, but a great start.

I completely agree that having a camera for cg artists would be invaluable though.