Flex+pv3d 打造三维全景图

package {
import flash.events.Event;
import flash.events.MouseEvent;
import org.papervision3d.cameras.CameraType;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.view.BasicView;
import org.papervision3d.materials.BitmapFileMaterial;
  
   //设置舞台宽高、背景颜色、帧频
[SWF (width="460", height="300", backgroundColor="0xffffff", frameRate="30")]

public class pv3dwholeScene extends BasicView
{
       private var sphere:Sphere;
       private var w:Number=460;
       private var h:Number=300;
       private var angleX:Number;
       private var angleY:Number;
       private var over:Boolean=false;
      
       public function pv3dwholeScene()
     {
          super(460,300,true, false,CameraType.FREE);
          init();
      }
       private function init():void
      {
          initObj();

  //注册帧频侦听用于不断刷新屏幕
        addEventListener(Event.ENTER_FRAME,onEnterFrame);

  //当鼠标移到舞台时注册侦听
        stage.addEventListener(MouseEvent.MOUSE_OVER,onOver);

  //当鼠标移出舞台时注册侦听
        stage.addEventListener(MouseEvent.MOUSE_OUT,onOut);
      }

        private function initObj():void
        {
        var material:BitmapFileMaterial=new BitmapFileMaterial("images/yourImage.jpg");
        
  //PV3D默认情况下不显示背面,doubleSided属性应设为true
        material.doubleSided = true;
        material.smooth = true;
      
  //实例化球体 (由周长算出半径 S=2*PI*R)
        sphere=new Sphere(material,98.68,20,20);
        scene.addChild(sphere);

  //把摄像机移到中心位置,PV3D摄像机的默认位置是camera.z=-1000
        camera.z=0;

  //摄象机的缩放参数,
        camera.zoom=.8;

  //摄象机的焦距
        camera.focus=300;
}

    private function onEnterFrame(e:Event):void
    {
  
     if(over)
     {
   //当over是真时设置摄像机的旋转角度
        var xm:Number=stage.mouseX;
        var ym:Number=stage.mouseY;
        angleX=(w/2-xm)*-.004;
        angleY=(h/2-ym)*-.002;
     }
     else
     {
   //当over是假时设置摄像机的旋转角度为0
        angleX=0;
        angleY=0;
      }
  // 旋转摄像机
        camera.yaw(angleX);
        camera.pitch(angleY);
  //渲染
        singleRender();
}

private function onOver(event:MouseEvent):void
{
  over=true;//鼠标移到场景上为真
}
private function onOut(event:MouseEvent):void
{
  over=false;//鼠标移出场景为假
}

}

}
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
评论: 0 | 引用: 0 | 查看次数: 5930
发表评论
昵 称:
密 码: 游客发言不需要密码.
验证码: 验证码
内 容:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 关闭 | [img]标签 关闭