LogoLogo
  • Home
  • Projects
  • About
  • Contact

Jiglib + Augmented Reality : Playing with Balls

Devon O. · May 12, 2009 · Actionscript, Flash · 12 comments
4

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.

Get Adobe Flash player

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:

C#
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…

  Facebook   Pinterest   Twitter   Google+
augmented reality
  • A Little Friday Graffiti
    October 15, 2010 · 3 comments
    3353
    4
    Read more
  • One More Filter For Starling
    September 10, 2012 · 5 comments
    4407
    13
    Read more
  • Blist
    February 24, 2008 · 0 comments
    1458
    3
    Read more
12 Comments:
  1. “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.

    Acts7 · May 12, 2009
  2. 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!

    dVyper · May 12, 2009
  3. Fantastic, you can use it to any object!
    Do you know WOW physic engine? That’s great.

    Ramon Fritsch · May 12, 2009
  4. 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.

    Devon O. · May 12, 2009
  5. 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.

    CW · May 23, 2009
  6. 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…

    Devon O. · May 27, 2009
  7. Hi!

    nice work…

    Hi tried something similar, but with ArtToolkit on a client application..
    http://www.youtube.com/watch?v=AlIWx5YkgRc

    Gianca · November 10, 2009
  8. That’s fantastic, Gianca. Much better maze.. Did you use jiglib for the physics as well?

    Devon O. · November 11, 2009
  9. 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 !?! :

    Gianca · November 11, 2009
  10. 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).

    Devon O. · November 19, 2009
  11. 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/

    Eric · April 10, 2011
  12. 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

    Jolly Matthew · July 16, 2011

Leave a Comment! Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Devon O. Wolfgang

AIR | Unity3D | AR/VR

Unity Certified Developer

Technical Reviewer of “The Essential Guide to Flash CS4 AIR Development” and “Starling Game Development Essentials”

Reviewer of “The Starling Handbook”

Unity Engineer at Touch Press.

Categories
  • Actionscript (95)
  • AIR (16)
  • Flash (99)
  • Games (7)
  • Liberty (13)
  • Life (53)
  • Shaders (20)
  • Unity3D (21)
Recent Comments
  • Devon O. on Unity Ripple or Shock Wave Effect
  • Feral_Pug on Unity Ripple or Shock Wave Effect
  • bavvireal on Unity3D Endless Runner Part I – Curved Worlds
  • Danielius Vargonas on Custom Post Processing with the LWRP
  • Luca G on Unity Ripple or Shock Wave Effect
Archives
  • December 2020 (1)
  • December 2019 (1)
  • September 2019 (1)
  • February 2019 (2)
  • December 2018 (1)
  • July 2018 (1)
  • June 2018 (1)
  • May 2018 (2)
  • January 2018 (1)
  • December 2017 (2)
  • October 2017 (1)
  • September 2017 (2)
  • January 2017 (1)
  • July 2016 (1)
  • December 2015 (2)
  • March 2015 (1)
  • September 2014 (1)
  • January 2014 (1)
  • August 2013 (1)
  • July 2013 (1)
  • May 2013 (1)
  • March 2013 (2)
  • December 2012 (1)
  • November 2012 (1)
  • September 2012 (3)
  • June 2012 (2)
  • May 2012 (1)
  • April 2012 (1)
  • December 2011 (2)
  • October 2011 (3)
  • September 2011 (1)
  • August 2011 (1)
  • July 2011 (1)
  • May 2011 (2)
  • April 2011 (2)
  • March 2011 (1)
  • February 2011 (1)
  • January 2011 (2)
  • December 2010 (3)
  • October 2010 (5)
  • September 2010 (1)
  • July 2010 (2)
  • May 2010 (5)
  • April 2010 (2)
  • March 2010 (7)
  • February 2010 (5)
  • January 2010 (5)
  • December 2009 (3)
  • November 2009 (1)
  • October 2009 (5)
  • September 2009 (5)
  • August 2009 (1)
  • July 2009 (1)
  • June 2009 (2)
  • May 2009 (6)
  • April 2009 (4)
  • March 2009 (2)
  • February 2009 (4)
  • January 2009 (1)
  • December 2008 (5)
  • November 2008 (2)
  • September 2008 (1)
  • August 2008 (6)
  • July 2008 (6)
  • June 2008 (9)
  • May 2008 (4)
  • April 2008 (3)
  • March 2008 (4)
  • February 2008 (9)
  • January 2008 (7)
  • December 2007 (6)
Copyright © 2017 Devon O. Wolfgang