[papervision3d2] 全景图

      做生活 2008-7-1 13:49


代码如下:
package ex{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.materials.MovieAssetMaterial;
	import org.papervision3d.objects.primitives.Cube;
	import org.papervision3d.render.BasicRenderEngine;
	import org.papervision3d.cameras.FreeCamera3D;
	import org.papervision3d.view.Viewport3D;
	import org.papervision3d.materials.utils.MaterialsList;
	import flash.events.MouseEvent;
	public class Ex3 extends MovieClip {
		private var viewport:Viewport3D;
		private var scene:Scene3D;
		private var camera:FreeCamera3D;
		private var renderer:BasicRenderEngine;
		private var cube:Cube;
		public function Ex3() {
			stage.scaleMode=StageScaleMode.NO_SCALE;				
			viewport = new Viewport3D(400,400);
			addChild(viewport);
			scene = new Scene3D();
			camera = new FreeCamera3D();
			renderer = new BasicRenderEngine();
			camera.z=0	
			camera.focus = 100;
			var ms:MaterialsList = new MaterialsList();
			ms.addMaterial(new MovieAssetMaterial("Top",true),"top");
			ms.addMaterial(new MovieAssetMaterial("Bottom",true),"bottom");
			ms.addMaterial(new MovieAssetMaterial("Left",true),"left");
			ms.addMaterial(new MovieAssetMaterial("Right",true),"right");
			ms.addMaterial(new MovieAssetMaterial("Front",true),"front");
			ms.addMaterial(new MovieAssetMaterial("Back",true),"back");	
			cube = new Cube( ms, 5000, 5000, 5000,16,16,16,Cube.ALL,Cube.NONE);
			scene.addChild( cube, "Cube" );
			addEventListener( Event.ENTER_FRAME, enterFrameHandle );
			addEventListener( MouseEvent.CLICK,clickHandle );
		}
		private function enterFrameHandle(e:Event):void {
			camera.rotationY -= Math.max(-10,Math.min((camera.rotationY-viewport.containerSprite.mouseX)/10,10));
			renderer.renderScene(scene,camera,viewport);
		}
		private function clickHandle(e:Event):void {
			camera.focus=camera.focus-viewport.containerSprite.mouseY;
			if (camera.focus<50) camera.focus=50;
			if (camera.focus>1000) camera.focus=1000;
		}		
	}
}
标签集:TAGS:as3 example Flash
回复Comments() 点击Count()

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}