当前位置: 代码迷 >> Web前端 >> 让Away3D带你360°全景遨游
  详细解决方案

让Away3D带你360°全景遨游

热度:183   发布时间:2013-10-08 16:46:23.0
让Away3D带你360°全景漫游

1代码展示

package
{
	import away3d.containers.View3D;
	import away3d.controllers.HoverController;
	import away3d.entities.Mesh;
	import away3d.materials.TextureMaterial;
	import away3d.primitives.SphereGeometry;
	import away3d.textures.BitmapTexture;
	
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;

	[SWF(width='1024',height='512',frameRate='60')]
	public class Study05 extends Sprite
	{
		[Embed(source='/../embeds/pano_sphere.jpg')]
		private var _pano:Class;
		
		private var _startX:Number;
		private var _startY:Number;
		private var _mouseX:Number;
		private var _mouseY:Number;
		private var _view:View3D;
		private var _hover:HoverController;
		private var _mesh:Mesh;
		private var _sphere:SphereGeometry;
		private var _material:TextureMaterial;
		private var _bitmap:BitmapTexture;
		private var _delta:int;
		
		public function Study05()
		{
			_view = new View3D();
			addChild(_view);
			_view.camera.lens.far = 2000; // 设置照相机的渲染上限(不能低于球半径)
			_bitmap = new BitmapTexture(new _pano().bitmapData);
			_sphere = new SphereGeometry(1000,32,32);
			_material = new TextureMaterial(_bitmap);
			_material.bothSides = true;
			_mesh = new Mesh(_sphere,_material);
			_hover = new HoverController(_view.camera,null,90,0,300);
			_view.scene.addChild(_mesh);
			stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownFunction);
			stage.addEventListener(MouseEvent.MOUSE_UP,onUpHandler);
			stage.addEventListener(MouseEvent.MOUSE_WHEEL,onWheelHandler);
			addEventListener(Event.ENTER_FRAME,onLoopHandler);
		}
		
		
		protected function onWheelHandler(event:MouseEvent):void
		{
			_delta+=event.delta;
			_hover.distance=_delta;
			//trace(del);
		}
		
		protected function onUpHandler(event:MouseEvent):void
		{
			stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveFunction);
		}		
		
		private function mouseDownFunction(event:MouseEvent):void
		{
			
			_startX = _hover.panAngle;
			_startY = _hover.tiltAngle;
			_mouseX = mouseX;
			_mouseY = mouseY;
			stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveFunction);
			//stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpFunction);
		}
		
		private function mouseMoveFunction(event:MouseEvent):void
		{
			_view.camera.x=_delta;
			_hover.panAngle = (mouseX - _mouseX) * .3 + _startX;
			_hover.tiltAngle = (mouseY - _mouseY) * .3 + _startY;
		}
		
		protected function onLoopHandler(event:Event):void
		{
			_view.render();
		}
	}
}

2效果预览

 

  相关解决方案