- 最后登录
- 2013-9-29
- 注册时间
- 2012-8-20
- 阅读权限
- 90
- 积分
- 6371
- 纳金币
- 6372
- 精华
- 0
|
看了些FlashMagazine上的Flash效果,感觉超酷的。其中有些也用到了3D引擎。这个3D旋转图象是我在看了些Away3D的教程后做的。
附加我的源代码
package
{
import away3d.cameras.HoverCamera3D;
import away3d.containers.*;
import away3d.core.base.*;
import away3d.core.math.*;
import away3d.events.*;
import away3d.primitives.*;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
[SWF(width="1000", height="600")]
public class ImageBox extends Sprite
{
private var view:View3D;
private var camera:HoverCamera3D;
private var lastMouseX:Number;
private var lastMouseY:Number;
private var lastPanAngle:Number;
private var lastTiltAngle:Number;
private var move:Boolean = false;
[Embed (source="resources/1.jpg")]
private var tex1:Class;
[Embed (source="resources/2.jpg")]
private var tex2:Class;
[Embed (source="resources/3.jpg")]
private var tex3:Class;
[Embed (source="resources/4.jpg")]
private var tex4:Class;
public function ImageBox()
{
super();
//设定view,camera
camera = new HoverCamera3D({zoom:9, focus:200, distance:1000});
view = new View3D({camera:camera,x:500, y:300});
addChild(view);
camera.lookAt( new Number3D(0, 0, 0) );
camera.targetpanangle = camera.panangle = 45;
camera.targettiltangle = camera.tiltangle = 10;
camera.mintiltangle = -90;
//前面的画面
var fPlanelane = new Plane({material:tex1,width:200,height:200,bothsides:***e});
makePlane(0,0,100,90,180,fPlane);
view.scene.addChild(fPlane);
//左边的画面
var lPlanelane = new Plane({material:tex2,width:200,height:200,bothsides:***e});
makePlane(100,0,0,90,-90,lPlane);
view.scene.addChild(lPlane);
//右边的画面
var rPlanelane = new Plane({material:tex3,width:200,height:200,bothsides:***e});
makePlane(-100,0,0,90,90,rPlane);
view.scene.addChild(rPlane);
//后面的画面
var bPlanelane = new Plane({material:tex4,width:200,height:200,bothsides:***e});
makePlane(0,0,-100,90,0,bPlane);
view.scene.addChild(bPlane);
//增加事件监听
addEventListener(Event.ENTER_FRAME, onEnterFrame);
view.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
view.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
}
private function onEnterFrame(e:Event):void
{
//旋转速度控制
var cameraSpeed:Number = 0.3;
//MouseDown事件触发时
if (move) {
//水平方向旋转
camera.targetpanangle = cameraSpeed*(stage.mouseX - lastMouseX) + lastPanAngle;
//垂直方向旋转
camera.targettiltangle = cameraSpeed*(stage.mouseY - lastMouseY) + lastTiltAngle;
//自动旋转
} else {
camera.targetpanangle = cameraSpeed + camera.targetpanangle;
}
//渲染
camera.hover();
view.render();
}
private function mouseDown(event:MouseEvent):void
{
lastPanAngle = camera.targetpanangle;
lastTiltAngle = camera.targettiltangle;
lastMouseX = stage.mouseX;
lastMouseY = stage.mouseY;
move = ***e;
}
private function mouseUp(event:MouseEvent):void
{
move = false;
}
private function makePlane(x:int,y:int,z:int,rotationX:int,rotationY:int,planelane):void {
plane.x = x;
plane.y = y;
plane.z = z;
plane.segmentsH = 2;
plane.segmentsW = 2;
plane.rotationX = rotationX;
plane.rotationY = rotationY;
}
}
} |
|