package{ import flash.events.Event; import jiglib.plugin.sandy3d.Sandy3DMesh; import jiglib.plugin.sandy3d.Sandy3DPhysics; import jiglib.physics.RigidBody; import jiglib.geometry.JSphere; import sandy.core.scenegraph.Shape3D; import sandy.primitive.Sphere; import sandy.view.BasicView; /** * This example describes how any Sandy object can be explicitely bound to * a JigLib rigid body to get its physical properties. * * @author petit@petitpub.com */ public class ManualBinding extends BasicView { private var physics:Sandy3DPhysics; /** * Initiate the physics engine, add the shpere and start rendering. */ public function ManualBinding() { // Initiate the BasicView super.init(400, 400); // Create an instance of the physics engine physics = new Sandy3DPhysics(scene, 1); // Create an object createSphere(); // Start rendering render(); } /** * Create the sphere object and add it to the Sandy scene. * Then create the physical couterpart and bind them together * Finally add the physical object to the physics engine */ private function createSphere():void { var sphere:Shape3D = new Sphere("sphere",20,7,5); rootNode.addChild(sphere); // Now bind this Sandy object to a JSphere var jsphere:JSphere = new JSphere(new Sandy3DMesh(sphere), 20); physics.addBody(jsphere); } /** * Overriding the simpleRender method to call the time step method of the rendering engine. * @param event The ENTER_FRAME or timer event - the heart beat of Sandy */ override public function simpleRender( event:Event = null ):void { physics.step( ); super.simpleRender( event ); } } }