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

擬似 Line3D

Get Adobe Flash player
by TmskSt 19 Oct 2010
package {
	import alternativ5.engine3d.controllers.*;
	import alternativ5.engine3d.core.*;
	import alternativ5.engine3d.display.*;
	import alternativ5.types.*;
	import alternativ5.utils.*;
	import alternativ5.engine3d.materials.*;
	import flash.geom.Point;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;

	[SWF(backgroundColor="#000000", frameRate="120")]
	public class Main extends Sprite {
	    
		private var scene:Scene3D;
		private var view:View;
		private var camera:Camera3D;
		private var cameraController:CameraController;
		
		private var geo:Mesh;
		
		
		public function Main() {
			this.addEventListener(Event.ADDED, init);
		}
		
		public function init(e:Event):void {
			this.removeEventListener(Event.ADDED, init);
			
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			scene = new Scene3D();
			scene.root = new Object3D();
			
			geo = scene.root.addChild(createMesh()) as Mesh;
			
			camera = new Camera3D();
			camera.x = 130;
			camera.y = -90;
			camera.z = 130;
			scene.root.addChild(camera);
			
			view = new View();
			addChild(view);
			view.camera = camera;
			
			
			cameraController = new CameraController(stage);
			cameraController.camera = camera;
			cameraController.lookAt(geo.coords);
			cameraController.setDefaultBindings();
			cameraController.checkCollisions = true;
			cameraController.collisionRadius = 20;
			cameraController.speed = 200;
			cameraController.controlsEnabled = true;
			
			FPS.init(stage);
			
			stage.addEventListener(Event.RESIZE, onResize);
			stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
			onResize(null);
		}
		
		private function onResize(e:Event):void {
			view.width = stage.stageWidth;
			view.height = stage.stageHeight;
		}
		
		private function onEnterFrame(e:Event):void {
			cameraController.processInput();
			
			var p:Point3D = view.projectPoint(scene.root.localToGlobal(new Point3D(0, 0, 0)));
			var p2:Point3D = view.projectPoint(scene.root.localToGlobal(new Point3D(0, 0, 100)));
			
			view.graphics.clear();
			view.graphics.lineStyle(1, 0xE60D0D);
			view.graphics.moveTo(p.x, p.y);
			view.graphics.lineTo (p2.x, p2.y);
			
			scene.calculate();
		}
		
		private function createMesh():Mesh {
			var mesh:Mesh = new Mesh();
			mesh.createVertex(-50, 50, 0, "v1");
			mesh.createVertex(-50, -50, 0, "v2");
			mesh.createVertex(50, -50, 0, "v3");
			mesh.createVertex(50, 50, 0, "v4");
			mesh.createFace(["v1", "v2", "v3", "v4"], "f1");
			mesh.createSurface(["f1"], "s1");
			mesh.setMaterialToSurface(new FillMaterial(0x5C58AD), "s1");
			
			return mesh;
		}
	}
}