Menu
Samaritan's Purse

JCAPSULE

JCapsule is a geometry object.

EXAMPLE

JCapsule

INSTRUCTIONS

  1. Import import jiglib.geometry.JCapsule;
  2. Declare private var jObject :JCapsule
  3. Initialize jObject = new JCapsule(skin, r, l)
    PARAMETER DEFAULT DESCRIPTION
    skin NONE skin
    r NONE radius
    l NONE length
  4. Add PhysicsSystem.getInstance().addBody(jObject);

CODE

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

    import jiglib.geometry.JCapsule;
    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.Cylinder;
    import org.papervision3d.view.BasicView;

    public class JigLibFlashJCapsule extends BasicView
    {
        private var material :CompositeMaterial;
        private var material2 :CompositeMaterial;
        private var material3 :CompositeMaterial;
        private var array     :Array = new Array();
        
        public function JigLibFlashJCapsule()
        {
            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));

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

                var jObject :JCapsule = new JCapsule(new Pv3dMesh(object), 50, 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 Cylinder(material, 50, 100);
                scene.addChild(object);

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

            object = new Cylinder(material, 50, 100);
            scene.addChild(object);

            array[2] = new JCapsule(new Pv3dMesh(object), 50, 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