In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: [PV3D] Simple Sphere

必要なライブラリをインポートします
/**
 * Copyright yes_i_can ( http://wonderfl.net/user/yes_i_can )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/b8AY
 */

package  
{
	
    
        import flash.events.Event;
	
	// 必要なライブラリをインポートします
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.special.CompositeMaterial;
        import org.papervision3d.lights.PointLight3D;
        import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
	import org.papervision3d.materials.WireframeMaterial;
	import org.papervision3d.objects.primitives.Plane;
        import org.papervision3d.objects.primitives.Sphere;
        import org.papervision3d.view.BasicView;
	import org.papervision3d.core.effects.view.ReflectionView;
	

	 
	public class Main extends ReflectionView
	{
		private var ball:Sphere;
		private var dx:int = 4;
		private var dz:int = 4;
		
		public function Main() 
		{
			init();
		}
		
		private function init():void
		{
			
			
			//カメラ位置////////////////////////////////////////////////
			camera.y = 200;
			
			
			//床の作成//////////////////////////////////////////////////
			var wm:WireframeMaterial = new WireframeMaterial();
			var col:ColorMaterial = new ColorMaterial(0xffffff, 0.5);
			var co:CompositeMaterial = new CompositeMaterial();
			co.addMaterial(wm);
			co.addMaterial(col);
			
			var floor:Plane = new Plane(co, 2000, 2000, 12, 12);
			floor.pitch( -90);

                        //床を3Dシーンに表示/////////////////////////////////////////
			scene.addChild(floor);

			
                        // 球面を作成///////////////////////////////////////////////
			var material: CompositeMaterial = new CompositeMaterial();
			material.addMaterial(new WireframeMaterial(0xff6633));
			material.addMaterial(new ColorMaterial(0xdcdcdc));
            
                        ball = new Sphere(material, 100, 8, 8);
			ball.y = 100;

			// 球面を3Dシーンに表示//////////////////////////////////////
			scene.addChild(ball);
			
			
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		private function onEnterFrame(e:Event):void 
		{
			singleRender();
			updataObjct();
			updateCamera();
		}
		
		//オブジェクトの移動
		function updataObjct():void {
				ball.rotationZ -= dz;
				ball.x = ball.x + dx;
			    
			    if(ball.x > 1000 - 54){
			        ball.x = 1000 - 54;
		            dx = dx * -1;
		            dz = dz * -1;
			    }
			    
			    if (ball.x < -950 + 4) {
            		ball.x = -950 + 4;
            		dx = dx * -1;
		            dz = dz * -1;
            	}

		}
		
		//カメラの移動(オブジェクトについていく)
		function updateCamera():void {
				camera.target = ball;
				camera.x = ball.x;
				camera.y = ball.y + 200;
				camera.z = ball.z + 200;
		}
		
		
	}
	
}