So I was playing around with the JiglibFlash Physics engine in augmented reality the other day and thought to myself, “Self, wouldn’t it be just the bees knees if you could actually control the movements of your little 3D world items by just moving around the Augmented Reality marker paper thing you’re holding in your hands?”
Well, long story short, you can. The proof of concept video below shows what I’m on about. In the quick example, a ball drops “from the sky” and lands “on” the marker paper. It can then be rolled back and forth by actually tilting the paper from side to side. When the ball falls off the paper another one drops down and on it goes.
Right now it’s a little temperamental and about as fun as rolling a marble on a piece of cardboard, so I’m not gonna bother posting an actual .swf or code until I get something a little more interesting hammered out.
For those wanting to try something out for themselves or just interested in the technical details, here’s a few tips for youse.
First I set the gravity of the physics system to the z axis so object fall onto the paper with:
PhysicsSystem.getInstance().setGravity(new JNumber3D(0, 0, -12));
The ground is just a squashed cube with a transparent MovieMaterial applied, set at (0, 0, 0).
The tricky part was getting the ground to rotate with the AR world. I knew that the transform properties of the AR environment had to be contained in FLARTransMatResult object, but I didn’t really know how to dig ’em out properly until I ran across this blog post. It turns out that the properties of the FLARtransMatResult map quite perfectly into a Papervision3D Matrix3D object. You can then get a Number3D object containing the rotation amounts with the matrix2euler() method. In my case, I was really only interested in the rotationZ property to get the ground to tilt back and forth. In short then, I got this little dealie going on in each frame:
1 2 3 4 5 6 7 8 |
var mat:Matrix3D = new Matrix3D(); mat.n11 = trans.m01; mat.n12 = trans.m00; mat.n13 = trans.m02; mat.n14 = trans.m03; mat.n21 = -trans.m11; mat.n22 = -trans.m10; mat.n23 = -trans.m12; mat.n24 = -trans.m13; mat.n31 = trans.m21; mat.n32 = trans.m20; mat.n33 = trans.m22; mat.n34 = trans.m23; var objRot:Number3D = Matrix3D.matrix2euler(mat); _ground.rotationZ = objRot.z; |
And that’s really all there is to it to get started. I’m thinking maybe rolling a ball through a maze or something next time. Interested to see what other folks might come up with though…
“about as fun as rolling a marble on a piece of cardboard”
…nice
The things you can do mate never cease to impress me. Although that doesnt look like much fun – ohhh the potential.
I had this idea absolutely ages ago. Unfortunately I haven’t got the skills to implement it yet like you have. But yes, there’s so many possibilities which AR!
Fantastic, you can use it to any object!
Do you know WOW physic engine? That’s great.
Thanks for the comments, folks.
Ramon, any object added to the physics engine environment would work. Never used the WOW engine, but it looks like it may be promising.
Great work.
However, I see the code that the ground only rotates in z axis, is it possible to rotate in all axis? As before, I have tried Jiglib, but I found rotating in more than one axis has some problem.
Hey CW, if you check out parts 2 and 3 of this “series” you can use multiple axis. It’s not easy though and I had to do a bunch of silly manipulation (like xrotation + 100 * 3 / .6 + PI etc etc. Well, not that much, but still). The third part has the script if you’d like to play around and improve on what I was doing…
Hi!
nice work…
Hi tried something similar, but with ArtToolkit on a client application..
http://www.youtube.com/watch?v=AlIWx5YkgRc
That’s fantastic, Gianca. Much better maze.. Did you use jiglib for the physics as well?
Thank you!
for phisics I used ODE
http://awarelab.wordpress.com/2009/08/24/ball-in-a-maze-augmented-reality-part-2/
I’d like trasform this in a web application, but I’m not very skilled with flash… maybe we can collaborate !?! :
Hey Gianca, A very delayed reply, but a collaboration would be great if you’re still interested. Get a hold of me (Don’t want to post my email in a comment, but you can use the contact form of my portfolio – link is on the right somewhere, or message @devon_o on twitter).
I’m working on something similar, and my matrix is being temperamental as well. Here’s the work in progress: http://www.ericjoycefilm.com/wastesoftime/youball/
Sire, it’s a nice work. Can you make a tutorial for this one?. Can you help me how to make that ball move just like what you did, because our Thesis Project is an Augmented Reality ball maze. It will be a big help for us of you lend as a hand. Thank you very much in advance