• Home
  • Projects
  • About
  • Contact

Away3D + QuickBox2D (Finally)

Devon O. · August 30, 2009 · Actionscript · 14 comments
2

I’ll be the first to admit, I’m no 3D programmer – but whenever I needed it in Flash, I just used Papervision3D. It seems the default standard these days and the amount of available information, documentation, and tutorials seems endless. For quite some time though, I’ve been wanting to try out Away3D. The folks who use it, swear by it and I’ve seen some really great stuff done using it. Likewise, I’ve also really been wanting to try out Box2DFlash for some 2d physics simulations. The Box2DFlash api, based on its C++ counterpart, always intimidated the hell out of me though, with its crazy use of capitalization and arbitrary class names. But when Tomek Augustyn/Og2t sent me a message on Twitter suggesting I give QuickBox2D a try, that seemed a good sign that the time was ripe to try out these two new (to me) technologies.

And so, inspired by games like the old classic LineRider and the new Red Bull Soapbox Racer, I came up with this pale comparison. To play, use your mouse to draw line segments (left to right) that will become the track. When done, click “begin” and down you go. Okay, so it’s no award winner, but given the fact I’ve never used Away3D or QuickBox2D before and got that put together over the course of a Saturday, it’s not too shabby and speaks volumes about how easy the two libraries are to pick up.

Some good and bad points of each that learned along the way –

Away3D Drawbacks:

  • I hate hate hate api’s that rely on “initObjects” in class constructors. It always seems like a good idea and makes for a nice clean interface, but I find myself crippled when deprived of code hints. I would much rather enter  default values or nulls into a constructor than selectively decide what properties to instantiate and run the risk of misspelling them or worse yet, not even know what’s available.
  • Probably my own stupid fault, but I couldn’t get the SpringCam working at all. I had to devise my own with a TargetCamera3D instance and a bit of simple easing. I’ll look into that further when I have the time.

Away3D Pluses:

  • Performance seems fantastic for this initial trial.
  • The learning curve (at least coming from PV3D) is pretty freaking low.
  • I love the Skybox6 class. So much easier than creating your own cube and trying to size it nicely as is required in PV3D (though making your background image seems a bit tricky and I just used one that comes with the Away3D demos download.
  • While I haven’t tried them yet, the Pixel Bender filters that come with the Flash 10 release look freakin’ awesome. I’m sure PV3D X will do something similar, but I can’t wait to have the time to dig into these and see what can be accomplished.
  • The materials available are terrific and slightly easier than their PV3D counterparts.

QuickBox2D Points:

Having never used a 2D physics engine before, I can’t make any real comparisons. One thing I loved was how simple it was to pick up. Much easier than diving straight into Box2DFlash. I highly recommend it to anyone getting into 2D physics. One thing that reallyvirked me was when creating a GroupObject containing two CircleObjects (a simple car, e.g.), the CircleObjects won’t rotate – they’ll just slide. I’m sure if I dig further into the Box2D mechanism behind it all, I can figure out a way around that, though.

In any case, both libraries are loads of fun and it was a Saturday well spent…

  Facebook   Pinterest   Twitter   Google+
  • The Webcam Warholizer
    March 19, 2010 · 1 comments
    770
    5
    Read more
  • Gone Bowling
    June 21, 2009 · 0 comments
    889
    3
    Read more
  • Flash + Spry = Fly
    June 07, 2008 · 3 comments
    434
    1
    Read more
14 Comments:
  1. Your expiriment looks pretty great for a firt try. I was blown away when I clicked ‘begin’.

    How does this work? The 2d physics are calculated while away3D makes a 3d representation of this? Or does this box2d thing actually work in 3d?

    Niels van Dijk · August 30, 2009
  2. Hey Niels. thanks for the comments. Seeing as this was my first attempt, I probably did it the hard way, basically what’s happening is, during an enterframe event it’s setting the 3d car’s x, y, and rotationZ properties equal to the x, y, and angle properties of a 2d box (that you can’t see) sliding down some ramps (equal to what you’ve drawn). So, I’ve got a method saying this:

    _world3.getCar().x = (_world2.getCar().x * WORLD_SCALE – WIDTH * .5) * SCALE3D;
    _world3.getCar().y = ((-_world2.getCar().y * WORLD_SCALE + HEIGHT * .5) * SCALE3D);
    _world3.getCar().rotationZ = -_world2.getCar().angle * (180 / Math.PI);

    Gotta be a better way, but it works. I’d post the whole script, but it’s a real mess – stuff just thrown in as I thought of/learned it.

    Devon O. · August 30, 2009
  3. Hmmm. Getting
    Error: isNaN(sz)
    at away3d.cameras.lenses::ZoomFocusLens/project()
    at away3d.core.project::MeshProjector/primitives()
    at away3d.core.traverse::PrimitiveTraverser/apply()
    at away3d.core.base::Object3D/traverse()
    at away3d.containers::ObjectContainer3D/traverse()
    at away3d.containers::ObjectContainer3D/traverse()
    at away3d.containers::View3D/render()
    at World3d/render()
    when I click on Begin after drawing. I’m on Vista/Firefox 3.5

    Pradeek · August 30, 2009
  4. Ok. Looks like I’m getting this only after drawing a lot of inclined lines.

    Pradeek · August 30, 2009
  5. So it ‘ looks ‘ 3d, but you could not use this method to move into the z-depth? (like make left turn), or is box2d capable of doing this?

    I really think these 3d experiments in flash are awsome. You should check out this dude’s blog, he does some amazing stuff too
    http://www.neuroproductions.be/

    Niels van Dijk · August 30, 2009
  6. Great first try (although it shows a lot of errors in the debug player). You should use actors to bind your physics world to the graphical output. More info is on the Box2D website.

    Patrick Pietens · August 30, 2009
  7. Hey Devon,

    Cool demo… In order to create cars etc… you should look into using joints instead of group objects – group objects will always act like one rigid body, if you want to create a car, you can do so with the use of “revolute joints”…

    Zevan · August 30, 2009
  8. Hi Devon,
    The ‘initObjects’ are entirely optional. You can also set anything using properties :)

    J

    Jensa · August 30, 2009
  9. Thanks for the comments..
    @Pradeek & Patrick – I got those errors from time to time testing, but being just a personal project, it didn’t bother me much. Obviously, Away3D is getting some bad info somewhere though and I gotta sit down some time and figure out where exactly. And thanks for the heads up on the actors/graphical binding info.

    @Zevan – Thanks for the joint information. I was actually going to come ask that on the actionsnippet site and now I don’t have to!

    @Niels – no you can’t do real z depth, but you can fake it very nicely. Check out the Red Bull site I linked to for a prime example.

    @Jensa – great news about the initObjects! Did I mention I hate them?

    Devon O. · August 31, 2009
  10. Haha nice one, I am happy to be the messenger and inspire people with another people’s experiments :) btw. Devon, would you shade the rubber cube twist demo code? I am really interested what functions you’ve used to achieve that smooth rubber feel. Tweaked Penner’s equations?

    Og2t · September 01, 2009
  11. Hey Og2t, Thanks again for the tip..
    That cube code was actually posted a couple posts later, here: http://blog.onebyonedesign.com/?p=292 Maybe I should stop being lazy and put the code in the same post…

    Devon O. · September 02, 2009
  12. I’ve used both PV3D and Away3D, and while example code for Away3D is a little harder to find (the web site is not very useful) I’d have to say that Away3D is the better of the two. Still, Papervision just incorporates the coolest Away3D features (like the QuadTreeRenderer) into their own code anyway…

    http://bit.ly/1no4G1

    Matt · September 10, 2009
  13. Hey, does anyone have any plans to integrate QuickBox2D with Box2D Alchemy from WCK? I’m using Starling and QuickBox2D is about a thousand times easier to integrate than WCK but I would really like to be using the Alchemy port. Unfortunately it’s not as easy as it might be! Just wondering if anyone has seen anything out there already?

    Tim Leslie · November 23, 2011

Leave a Comment! Cancel reply

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

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”

Currently seeking new opportunities. Contact me.

Categories
  • Actionscript (95)
  • AIR (16)
  • Flash (99)
  • Games (7)
  • Liberty (13)
  • Life (52)
  • Shaders (13)
  • Unity3D (11)
Recent Comments
  • yossi cohen on Unity Ripple or Shock Wave Effect
  • Devon O. on Unity3D Endless Runner Part II – Scrolling Worlds
  • Rafael on Unity3D Endless Runner Part II – Scrolling Worlds
  • Erez on Unity3D Endless Runner Part I – Curved Worlds
  • Joe on Unity3D Endless Runner Part I – Curved Worlds
Archives
  • 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