01 forked from: JigLibFlash Test

by vuking_p forked from JigLibFlash Test (diff: 122)
JigLibFlash が Papervision 以外の 3D エンジンに対応して、書き方が変わっていたので新 JigLibFlash をいじってみた。

...
@author tkinjo
♥0 | Line 59 | Modified 2010-08-10 16:11:55 | MIT License
play

ActionScript3 source code

/**
 * Copyright vuking_p ( http://wonderfl.net/user/vuking_p )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/xxbK
 */

package  
{
    /**
     * JigLibFlash が Papervision 以外の 3D エンジンに対応して、書き方が変わっていたので新 JigLibFlash をいじってみた。
     */
    
    import flash.display.Sprite;
    import flash.events.Event;
    
    import jiglib.math.JNumber3D;
    import jiglib.physics.RigidBody;
    import jiglib.plugin.papervision3d.Papervision3DPhysics;
    
    import org.papervision3d.core.proto.CameraObject3D;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.materials.WireframeMaterial;
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.scenes.Scene3D;
    import org.papervision3d.view.AbstractView;
    import org.papervision3d.view.BasicView;
    
    [SWF(width = "465", height = "465", frameRate = "60", backgroundColor = "#cfcfff")]
    
    /**
     * ...
     * @author tkinjo
     */
    public class Main extends Sprite
    {
        private const speed:Number = 9.8;
        
        private var view:AbstractView;
        private var scene:Scene3D;
        private var camera:CameraObject3D;
        private var cameraTarget:DisplayObject3D;
        
        private var physics:Papervision3DPhysics;
        private var boxes:Array;
        private var velocity:JNumber3D;
        
        private var frameCounter:Number;

        /**
        * 
        */
        public function Main() 
        {
            frameCounter = 0;
            
            view = new BasicView( stage.stageWidth, stage.stageHeight );
            addChild( view );
            
            scene = view.scene;
            camera = view.camera;
            
            /** --------------------------------------------------
             * カメラ設定
             */
            camera.x = 1000
            camera.y = 1000;
            
            cameraTarget = new DisplayObject3D();
            camera.lookAt( cameraTarget );
            
            /** --------------------------------------------------
             * jiglib 設定
             */
            physics = new Papervision3DPhysics( scene, speed );
            
            // 地面の作成
            var wireframeMaterial:WireframeMaterial = new WireframeMaterial( 0 );
            var ground:RigidBody = physics.createGround( wireframeMaterial, 1000, 0 );
            
            // ボックスの作成
            var materials:MaterialsList = new MaterialsList();
            materials.addMaterial( new WireframeMaterial( 0 ), "all" );
            
            var box:RigidBody;
            boxes = [];
            for (var i:int = 0; i < 5; i++) {
                box = physics.createCube( materials, 100, 100, 100 );
                boxes.push(box);
                box.y = 300 * ( i + 1 );
            }
            
            //velocity = velocity.ZERO;
            
            /** --------------------------------------------------
             * レンダリングとか
             */
            addEventListener( Event.ENTER_FRAME, enterFrameHandler );
            view.startRendering();
        }
        
        /**
         * 
         * @param    event
         */
        private function enterFrameHandler( event:Event ):void
        {
            /*
            if(frameCounter == 0)
            {
                physics.removeBody(boxes[1]);
            }
            if(frameCounter == 10)
            {
                physics.addBody(boxes[1]);
            }
            frameCounter++;
            if(frameCounter>20)
            {
               frameCounter = 0; 
            }
            */
            
            boxes[0].x += 0.5;
            //boxes[1].x += 0.25;
            //boxes[1].z += 0.25;
            //boxes[2].z += 0.5;
            
            physics.step();
        }
    }
}

Forked