HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

JSphere

JSphere is a geometry object.

Example

JSphere

Instructions

  1. Import
    import jiglib.geometry.JSphere;
  2. Declare
    private var jObject :JSphere
  3. Initialize
    jObject = new JSphere(skin, radius)
    ParameterDefaultDescription
    skinNONEskin
    radiusNONEradius
  4. Add
    PhysicsSystem.getInstance().addBody(jObject);

Code

package
{
    import flash.display.Sprite;
    import flash.events.Event;

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

    public class JigLibFlashJSphere extends BasicView
    {
        private var material  :CompositeMaterial;
        private var material2 :CompositeMaterial;
        private var material3 :CompositeMaterial;
        private var array     :Array = new Array();
        
        public function JigLibFlashJSphere()
        {
            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 :Sphere = new Sphere(material, 50);
                scene.addChild(object);

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

            for (i = 0; i < 2; i++) {
                object = new Sphere(material, 50);
                scene.addChild(object);

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

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

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