package{ import flash.events.Event; import flash.text.TextField; import jiglib.geometry.JBox; import jiglib.geometry.JSphere; import jiglib.geometry.JPlane; import jiglib.math.JNumber3D; import jiglib.plugin.sandy3d.Sandy3DPhysics; import jiglib.plugin.sandy3d.Sandy3DMesh; import jiglib.physics.RigidBody; import jiglib.geometry.JCapsule; import jiglib.math.JMatrix3D; import sandy.core.scenegraph.Shape3D; import sandy.primitive.GeodesicSphere; import sandy.primitive.Sphere; import sandy.primitive.Cylinder; import sandy.primitive.Box; import sandy.primitive.Plane3D; import sandy.materials.attributes.LightAttributes; import sandy.materials.attributes.LineAttributes; import sandy.materials.attributes.PhongAttributes; import sandy.materials.attributes.MaterialAttributes; import sandy.materials.attributes.GouraudAttributes; import sandy.materials.ColorMaterial; import sandy.materials.Appearance; import sandy.view.BasicView; /** * This is a test bench application for testing JigLib with Sandy * You create a test by subclassing the TestBench class. * The sub class implements the abstract createObjects method to add * JibLib enabled objects to the Sandy rootNode and to the physics engine * NOTE: Disregard the label methods - they are stubs for further development * * @author petit@petitpub.com */ public class TestBench extends BasicView { protected var physics:Sandy3DPhysics; // The physic engine adapter class protected var ground:RigidBody; private var label:TextField; /** * Initiate the physics engine, add the shpere and start rendering. */ public function TestBench( mess:String="",scrWidth:int=600, scrHeight:int = 400 ) { // Initiate the BasicView super.init(scrWidth, scrHeight); // Label the test createLabel(mess); // These properties can be overriden by direct settings scene.light.setDirection(1,-1,2); camera.z = -800; camera.y = 200; camera.lookAt(0, 200, 0); // Create an instance of the physics engine physics = new Sandy3DPhysics(scene, 2); // Create the room createRoom(); // Start rendering render(); } /** * Creates a label to add to the back wall. * This doesn't work so far * @param message The message to present */ private function createLabel( message:String ):void { label = new TextField(); label.x = 100; label.y = 25; label.text = message; } /** * Create the test bench. * A ground floor and four walls with finite height comprises the test bench arena */ private function createRoom():void { // Create some good materials var attributes:MaterialAttributes = new MaterialAttributes( new LightAttributes(true)); var wallMaterial:ColorMaterial = new ColorMaterial(0x1B9A1B, 0.4, attributes); wallMaterial.lightingEnable = true; var backMaterial:ColorMaterial = new ColorMaterial(0xFF552A, 0.8);// 0xFFFF7F var groundAttributes:MaterialAttributes = new MaterialAttributes( new LineAttributes(0.5,0xECECEC,0.6), new LightAttributes(true)); var groundMaterial:ColorMaterial = new ColorMaterial(0x26A6D0, 1, groundAttributes); var frontMaterial:ColorMaterial = new ColorMaterial(0x0000FF, 0.1); // Create the walls var leftWall:RigidBody = physics.createCube("left", new Appearance(wallMaterial), 2, 400, 400, 3); leftWall.movable = false; leftWall.x = -300; leftWall.y = 200; physics.getMesh(leftWall).forcedDepth = 40030; physics.getMesh(leftWall).useSingleContainer=false; var rightWall:RigidBody = physics.createCube("right", new Appearance( wallMaterial ), 2, 400, 400, 2); rightWall.movable = false; rightWall.x = 300; rightWall.y = 200; physics.getMesh(rightWall).forcedDepth = 40010; physics.getMesh(rightWall).useSingleContainer=false; var backWall:RigidBody = physics.createCube("back", new Appearance( backMaterial ), 600, 2, 400, 2); backWall.movable = false; backWall.z = 200; backWall.y = 200; physics.getMesh(backWall).forcedDepth = 40020; var frontWall:RigidBody = physics.createCube("front", new Appearance( frontMaterial ), 600, 2, 400, 2); frontWall.movable = false; frontWall.z = -200; frontWall.y = 200; // Create the ground ground = physics.createGround("ground", new Appearance(groundMaterial), 800, 0, 10); physics.getMesh(ground).enableForcedDepth = true; physics.getMesh(ground).forcedDepth = 40040; } /** * Abstract method to be implemented in sub classes for setting up the experiment. */ private function createObjects():void { } /** * Genrates random number inside a range * * @param minVal The minimum value * @param maxVal The maximum value * @return The random number */ private function randRange(minVal:Number, maxVal:Number):Number { return Math.random() * (maxVal - minVal) + minVal; } /** * Overrides 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 ); } } }