Away3D + QuickBox2D (Finally)

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…

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?

  2. Devon O. says:

    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.

  3. Pradeek says:

    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

  4. Pradeek says:

    Ok. Looks like I’m getting this only after drawing a lot of inclined lines.

  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/

  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.

  7. Zevan says:

    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”…

  8. Jensa says:

    Hi Devon,
    The ‘initObjects’ are entirely optional. You can also set anything using properties :)

    J

  9. Devon O. says:

    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?

  10. Og2t says:

    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?

  11. Devon O. says:

    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…

  12. [...] Away3D + QuickBox2D (Finally) by onebyoneblog [...]

  13. Matt says:

    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

  14. Tim Leslie says:

    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?

RSS feed for comments on this post. / TrackBack URI

Leave a Reply

Devon O. Wolfgang

Technical Reviewer of “The Essential Guide to Flash CS4 AIR Development”

Contributing Author of “Flash AS3 for Interactive Agencies”

Senior Flash Engineer PopCap Games, International Ltd.

Portfolio

Santabot: A Unity3D Flash Game


All right, so a Christmas game like “Santabot vs. The Flying Saucers from Mars” may be a day late[...]

Magnify – a jQuery Plugin


Let me begin by saying right up front, I have not given up on Flash[...]

It’s a Starling Halloween


Getting some practice for the upcoming Zombie Apocalypse[...]

Getting Started with Proscenium

So I had a chance this weekend to sit down and play around with Adobe’s new 3D framework for Stage3D, Proscenium, and thought I’d share a few of the results (a word of caution, there are no preloaders for any of the examples and may load a bit slowly). The first shows some reflections and [...]

Particle Editor for Starling Framework

An in-browser particle editor for the Starling 2D Framework for Flash Player 11.

So Long and Thanks for all the Flash on the Beach

So, another Flash on the Beach has just has just drawn to a close[...]

Game Development Tips from the Trenches of PopCap

Well, this is a post that’s a bit overdue, but, thanks to a well timed bank holiday, I finally had the opportunity to sit down and type up what I’ve been meaning to for some time now…

Old Skool Demoscene FX as 3D Textures

Many moons ago, I got the idea to create some demoscene plane deformation effects in Flash based on the formulas found here: http://www.iquilezles.org/www/articles/deform/deform.htm. I posted my less than desired results up on wonderfl. Thankfully, fellow wonderfl user, Hasufel, forked my attempt and optimized the hell out of it coming up with this. Well, today, for no [...]

Making The Gaming Scene (A Change in Careers)

And for my second blog post of the day, a much more personal note. After about three years of working with, what I would consider as objectively as possible, the best digital agency in Ireland, vStream Digital Media, I have made the immense career decision to leave the agency world and enter the arena of [...]

Feeling Lucky?

Images to dice, kick ascii style [...]

Adventures in Playbook Land

Adventures in Playbook Land


Now that the ordeal is over, I thought I’d take the time to sit down and share my account of what it was like to develop a Blackberry Playbook application using the Adobe Flex SDK[...]

Flash

Draw it for Me

So many ideas – so little time….

Kinect Application Running in Dublin

So, on Friday I just wrapped up our latest project at vStream Digital Media, a Kinect powered flipbook that lets users flip through the hand written notebooks of Philip Lynott of Thin Lizzy. The app uses OpenNI, runs in Adobe AIR and is currently on display at a pretty bitchin’ Phil Lynott exhibition running in [...]

Beach Ball Kinect Party

So we finally got a Kinect camera hooked up to a pc at work and, while it doesn’t seem to be legal to use it for commercial projects (but, hey, I’m no lawyer), the boss asked me to get it figured out and come up with some ideas just in case it would be feasible [...]

Facebook and Flash – A Book Review

Now, I should begin by saying I absolutely hate building Facebook applications. And I build a lot of them at work. Every time I get the word from above that we’re doing another FB app, I just groan – both inwardly and out. It’s become a running joke of the office. Why do I dislike [...]

Multitouch Fluid Dynamics with AIR for Android and RTMFP

The other day I was having some fun playing around with Eugene Zatepyakin’s (aka @inspirit) FluidSolverHD (Actionscript port of C++ fluid dynamics library, MSAFluid. Or is MSAFluid, the processing/java port of the C++ library? In any case it’s a very cool fluid dynamics thingamabob – the HD version using Alchemy). After a bit of tinkering, [...]