Apr 17

仿造地球

Papervision3D


文件大,没做loading 稍稍等...........

public class test extends BasicView
  {
    private var sphere:Sphere;
    private const easing:Number = 0.1;
    private const scale:Number = 0.5;
    private var move:Boolean;
    
    private var currentPosition:Point;
    private var nodePosition:Point;
    private var endPosition:Point;
    private var oldPosition:Point;
    
    public function test() 
    {
      viewport.interactive = true;
      var mater:BitmapMaterial = new BitmapMaterial(new globe_bg(1250, 625));
      //mater.smooth = true;
      mater.interactive = true;
      sphere = new Sphere(mater, 420, 40, 34);
      scene.addChild(sphere);
      
      var _vl:ViewportLayer = viewport.getChildLayer(sphere);
      _vl.buttonMode = true;
      _vl.addEventListener(MouseEvent.MOUSE_DOWN, downH);
      stage.addEventListener(MouseEvent.MOUSE_UP, upH);
      addEventListener(Event.ENTER_FRAME,enter);
      initForce();
      singleRender();
      
    }
    private function initForce():void
    {
      currentPosition = new Point();
      endPosition = new Point();
      nodePosition = new Point();
    }
    private function downH(e:MouseEvent):void
    {
      nodePosition.x = mouseX;
      nodePosition.y = mouseY;
      oldPosition = endPosition.clone();
      move = true;
    }
    private function upH(e:MouseEvent):void
    {
      move = false;
    }
    private function enter(e:Event):void
    {
      rotate();
    }
    private function rotate():void
    {
      if( move )
      {
        endPosition.x = mouseX - nodePosition.x + oldPosition.x;
        endPosition.y = mouseY - nodePosition.y + oldPosition.y;
        
      }
      currentPosition.x += ( endPosition.x - currentPosition.x ) * easing;
      currentPosition.y += ( endPosition.y - currentPosition.y ) * easing;

      sphere.rotationX =   currentPosition.y * scale;
      sphere.rotationY = - currentPosition.x * scale;
      if (Math.abs(endPosition.x - currentPosition.x) > 0.1 || Math.abs(endPosition.y - currentPosition.y) > 0.1) {
        singleRender();
      }
    }

tags:

to "仿造地球"

  1. changewater Says:

    建议用transform
    Matrix3D.rotationMatrix()

    :)

  2. pataliu Says:

    http://www.flashquake.cn/?p=19 作者就是用的楼上说的方法

  3. emment Says:

    恩恩 确实有问题
    但是我这个鼠标交互上有所不同
    找个空我修改一下

  4. pataliu Says:

    想请教一个问题
    DisplayObject3D应用rotationX/rotationY/rotationZ相关属性、方法之后,它的x/y/z属性并不改变;比如:
    p.yaw(1);
    // x/y/z不改变
    trace(p.x+"X",p.y+"Y",p.z+"Z");

    不改变x/y/z,p又是如何运动的呢?

  5. emment Says:

    xyz是坐标 和 旋转没有关系的呀
    当然不改变了啊

  6. pataliu Says:

    我知道了 rotationX等等 是绕自身旋转的

  7. summer00xia Says:

    请问楼主你的地球是用3D画的嘛》?还是一张图片?我刚开始学PV3 呵呵

  8. emment Says:

    是3D球 不是图片

Leave a Reply