3d carousel

[ 2010-06-12 09:48:41 | Author: liuhuan ]
Font Size: Large | Medium | Small


It's long time since i played with PV3D.
package {
  import flash.display.*;
  import flash.events.*;
  import flash.filters.*;

  import org.papervision3d.materials.*;
  import org.papervision3d.objects.*;
  import org.papervision3d.objects.primitives.*;
  import org.papervision3d.view.BasicView;
  import org.papervision3d.core.proto.*;
  import org.papervision3d.core.math.*;
  import org.papervision3d.objects.DisplayObject3D;
  import org.papervision3d.events.InteractiveScene3DEvent;

  import gs.TweenMax;
  import gs.easing.*;

  public class Main extends BasicView {
    private var carousel:DisplayObject3D = new DisplayObject3D();
    private var bmpSkyMaterial:BitmapMaterial;
    private var arr_RotationPos:Array = new Array();
    private var rotationGap:Number;
    private var arrPlans:Array = new Array();
    private var picNumber:Number;
    private var carouselRoll:Boolean = true;

    public function Main():void {
      viewport.interactive = true;
      init();
    }
    private function init():void {
      carousel=new DisplayObject3D ;
      var bmpSky:Bitmap=new Bitmap(new Sky(2000,1583));
      bmpSkyMaterial=new BitmapMaterial(bmpSky.bitmapData,false);
      bmpSkyMaterial.doubleSided = true;
      bmpSkyMaterial.interactive = true;
      picNumber = 30;
      var picture_pitch:Number = 50;
      var radian:Number =550;
      rotationGap = 360/picNumber;
      for (var i:Number=0; i<picNumber; i++) {
        var plane:Plane=new Plane(bmpSkyMaterial,300,300);
        var rx:Number = 360 / picNumber * i*-1 + 90;
        plane.rotationX = rx;
        plane.y = Math.sin(i * Math.PI / picNumber*2) * radian;
        plane.z = Math.cos(i * Math.PI / picNumber*2) * radian;
        plane.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, objectOverHandler);
        plane.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, objectOutHandler);
        plane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, objectClickHandler);
        carousel.addChild(plane);
        arrPlans.push(plane);
        var obj:Object = new Object();
        obj.rx = rx;
        obj.ry = Math.sin(i * Math.PI / picNumber*2) * radian;
        obj.rz = Math.cos(i * Math.PI / picNumber*2) * radian;
        arr_RotationPos.push(obj);
      }
      carousel.rotationY = 3;
      scene.addChild(carousel);
      camera.zoom=25;
      startRendering();
    }
    private function objectOverHandler(event:InteractiveScene3DEvent):void {
      viewport.buttonMode = true;
    }
    private function objectOutHandler(event:InteractiveScene3DEvent):void {
      viewport.buttonMode = false;
    }
    private function objectClickHandler(event:InteractiveScene3DEvent):void {
      var id:Number;
      for (var i:Number=0; i<picNumber; i++) {
        TweenMax.to(arrPlans[i], .5, {rotationX:arr_RotationPos[i].rx,y:arr_RotationPos[i].ry,z:arr_RotationPos[i].rz,delay:0, ease:Quad.easeInOut});
        if (arrPlans[i]==event.displayObject3D) {
          id = i;
        }
      }
      var targObj:Object = arr_RotationPos[id];
      if (event.displayObject3D.rotationX> targObj.rx) {
        carouselRoll = true;
        TweenMax.to(event.displayObject3D, .5, {rotationX:targObj.rx,y:targObj.ry,z:targObj.rz,delay:0, ease:Quad.easeInOut});
      } else {
        carouselRoll = false;
        TweenMax.to(event.displayObject3D, .5, {rotationX:targObj.rx+90,y:targObj.ry*1.5,z:targObj.rz*1.5,delay:0, ease:Quad.easeInOut});
        TweenMax.to(carousel, 1, {rotationX:(targObj.rx+90)*-1,delay:0, ease:Quad.easeInOut});
      }
    }
    protected override function onRenderTick(event:Event=null):void {
      if (carouselRoll) {
        var speed:Number = viewport.containerSprite.mouseY / 150;
        if (Math.abs(speed)<.3) {
          speed = (Math.abs(carousel.rotationX % rotationGap) <= .1) ? 0 : .1;
        }
        carousel.rotationX -= speed;
      }
      super.onRenderTick(event);
    }
  }
}
Comments Feed Comments Feed: http://www.liuhuan.com/blog/feed.asp?q=comment&id=1049

There is no comment on this article.

You can't post comment on this article.