Bright Hub
 
Matthew Casperson's Hubfolio

Away3D Programming Tutorials - Physics

Article by Matthew Casperson (227,413 pts )
Published on Sep 20, 2009

Learn how to integrate the Jiglib Flash physics engine with Away3D.

Introduction

Flash developers have a number of 2D physics engines available to them, and more recently a number of 3D ones as well. WOW was one of the earliest, but another 3D physics engine called Jiglib has recently been ported to ActionScript. Jiglib is very easy to use with Away3D because it includes a plugin that creates and syncs both the Jiglib and Away3D primitives. This saves a lot of time (compared to other physics engines like WOW) as you don’t have to manually update the Away3D objects to reflect the changes make to the physics objects.

Code Documentation

EngineManager.as

A new instance of the Away3DPhysics class needs to be created. It needs to have the Away3D view passed to it so Jiglib can add the Away3D primitives to the scene when the physics primitives are created. The second parameter is the time. This is usually set to 1, but it is set to 2 here to make the simulation faster. [code]

The step function needs to be called each frame in order for the physics simulation to progress. [code]

ApplicationManager.as

First up a number of spheres are created and randomly positioned. [code]

The restitution property affects how much the spheres will bounce. The higher the value, the more bouncy the spheres will be. [code]

The spheres are added to a collection, so we can reset their position later on. [code]

You can get access to the Away3D mesh that was created by the physics engine by calling physics.getMesh(ridgedBody). We use this to assign a texture to the Away3D spheres. [code]

Finally the ground is created. The ground is a plane that does not move. Like the spheres, a texture is applied to the Away3D object created by Jiblib. [code]

The reset function resets the spheres so they will start dropping again. [code]

Final Words

In order to use the Jiglib library you need to download the source code from the SVN repository. Some references to Matrix3D need to be updated to MatrixAway3D in the Jiglib source code to reflect the name changes in the newer versions of Away3D. The compiler will pick up the errors for you (there are only around 4 references to Matrix3D that need to be changed). I have also included a copy of the LibJig source code in the Related Files section with these changes already made.

Jiglib makes adding physics to an Away3D application simple and seamless, and it seems to be more actively developed that other 3D Flash physics engines.

Go back to Away3D Tutorials

Related Files

Images

Screenshot

Search More About:

Comments

Nov 18, 2009 3:31 AM
irati
UIComponent
Hi! This is a really interesting tutorial, thanks for sharing!
by the way I got an error "1017: The definition of base class UIComponent was not found" in Flex builder 3, with sdk 3.4.
 
Follow Matthew Casperson
Receive weekly updates from Matthew Casperson
 
Bright Hub - Science & Technology Articles, Buyer's Guides, How-To Tips and Software Reviews
About Bright Hub | Contact Us | Advertise with Us | Become a Writer | RSS | Site Map | Terms of Use | Privacy Policy | Copyright Policy
©2010 Bright Hub Inc. All rights reserved. Page copy protected against web site content infringement by Copyscape