Menu
Samaritan's Purse

JBOX

JBox is a geometry object.

EXAMPLE

JBox

INSTRUCTIONS

  1. Import import jiglib.geometry.JBox;
  2. Declare private var jObject :JBox
  3. Initialize jObject = new JBox(skin, width, depth, height)
    PARAMETER DEFAULT DESCRIPTION
    skin NONE skin
    width NONE width
    depth NONE depth
    height NONE height
  4. Add PhysicsSystem.getInstance().addBody(jObject);

CODE

´╗┐package
{
    import flash.display.Sprite;
    import flash.events.Event;

    import jiglib.geometry.JBox;
    import jiglib.math.JNumber3D;
    import jiglib.physics.PhysicsSystem;
    import jiglib.plugin.papervision3d.Pv3dMesh;

    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.materials.WireframeMaterial;
    import org.papervision3d.materials.special.CompositeMaterial;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.objects.primitives.Cube;
    import org.papervision3d.view.BasicView;

    public class JigLibFlashJBox extends BasicView
    {
        private var material :CompositeMaterial;
        private var material2 :CompositeMaterial;
        private var material3 :CompositeMaterial;
        private var array     :Array = new Array();
        
        public function JigLibFlashJBox()
        {
            super();

            material = new CompositeMaterial();
            material.addMaterial(new ColorMaterial(0x000000, 0.5));
            material.addMaterial(new WireframeMaterial(0x000000));

            material2 = new CompositeMaterial();
            material2.addMaterial(new ColorMaterial(0x00ff00, 0.5));
            material2.addMaterial(new WireframeMaterial(0x00ff00));

            material3 = new CompositeMaterial();
            material3.addMaterial(new ColorMaterial(0xff0000, 0.5));
            material3.addMaterial(new WireframeMaterial(0xff0000));

            var materials :MaterialsList = new MaterialsList();
            materials.addMaterial(material, "all");

            for (var i:int = 0; i < 3; i++) {
                var object :Cube = new Cube(materials, 100, 100, 100);
                scene.addChild(object);

                var jObject :JBox = new JBox(new Pv3dMesh(object), 100, 100, 100);
                jObject.movable = false;
                jObject.moveTo(new JNumber3D((250 * i) - 250, 0, -500));
                PhysicsSystem.getInstance().addBody(jObject);
            }

            for (i = 0; i < 2; i++) {
                object = new Cube(materials, 100, 100, 100);
                scene.addChild(object);

                array[i] = new JBox(new Pv3dMesh(object), 100, 100, 100);
                array[i].moveTo(new JNumber3D((250 * i), 100, -500));
                PhysicsSystem.getInstance().addBody(array[i]);
            }

            object = new Cube(materials, 100, 100, 100);
            scene.addChild(object);

            array[2] = new JBox(new Pv3dMesh(object), 100, 100, 100);
            array[2].moveTo(new JNumber3D(300, 500, -500));
            PhysicsSystem.getInstance().addBody(array[2]);

            startRendering();
        }

        protected override function onRenderTick(e:Event=null):void
        {
            for (var i:String in array) {
                if (array[i].isActive()) {
                    array[i].skin.mesh.material = material2;
                } else {
                    array[i].skin.mesh.material = material3;
                }
                if (array[2].currentState.position.y < -500) {
                    array[2].moveTo(new JNumber3D(300, 500, -500));
                }
            }
            PhysicsSystem.getInstance().integrate(0.1);

            super.onRenderTick(e);
        }
    }
}

Download

JigLibFlash Documentation