package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.geom.PerspectiveProjection;
import flash.geom.Point;
import flash.geom.Vector3D;
import flash.utils.Timer;
import flash.utils.getDefinitionByName; /**
* @author Frost.Yen
* @E-mail 871979853@qq.com
* @create 2015-8-13 下午4:03:27
*
*/
[SWF(width="1024",height="768")]
public class RotateMain extends Sprite
{
[Embed(source="assets/001.png")]
private var _img0:Class;
[Embed(source="assets/002.png")]
private var _img1:Class;
[Embed(source="assets/003.png")]
private var _img2:Class;
[Embed(source="assets/004.png")]
private var _img3:Class;
[Embed(source="assets/005.png")]
private var _img4:Class;
[Embed(source="assets/006.png")]
private var _img5:Class;
[Embed(source="assets/007.png")]
private var _img6:Class;
[Embed(source="assets/007.png")]
private var _img7:Class; private var _num:int = 7;
private var _radius:Number = 300;
private var _itemArr:Array = [];
private var _speed:Number = 1;
private var _ratio:Number = 0.25;//系数
private var _downX:Number;
private var _container:Sprite;
private var _timer:Timer = new Timer(20);
public function RotateMain()
{
this.graphics.beginFill(0,1);
this.graphics.drawRect(0,0,1024,768);
this.graphics.endFill();
initViews();
initEventListeners();
}
private function initViews():void
{
_container = new Sprite();
_container.x = 1024*0.5;
_container.y = 768*0.5-200;
_container.z = 0;
this.addChild(_container);
for(var i:int = 0;i<_num;i++){
var angle:Number = Math.PI * 2/_num*i;
var sp:Sprite = new Sprite();
//var img:Class = getDefinitionByName("RotateMain__img"+i) as Class;
var bmp:Bitmap = new this["_img"+i](); sp.x = Math.cos(angle)*_radius;
sp.z = Math.sin(angle)*_radius;
sp.addChild(bmp);
_container.addChild(sp);
_itemArr.push(sp);
}
swapItems();
_timer.addEventListener(TimerEvent.TIMER,onTimer);
_timer.start(); }
private function initEventListeners():void
{
stage.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
}
private function onDown(e:MouseEvent):void
{
stage.addEventListener(MouseEvent.MOUSE_MOVE,onMove);
stage.addEventListener(MouseEvent.MOUSE_UP,onUp);
_timer.stop();
_downX = mouseX;
}
private function onMove(e:MouseEvent):void
{
_speed = (_downX-mouseX)*0.01;
_container.rotationY += _ratio * _speed;
var p:PerspectiveProjection = new PerspectiveProjection();
p.fieldOfView = 55;
p.projectionCenter = new Point(512,-100);
_container.transform.perspectiveProjection = p;
swapItems(); }
private function onUp(e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE,onMove);
stage.removeEventListener(MouseEvent.MOUSE_UP,onUp);
_timer.start();
}
private function onTimer(e:TimerEvent):void
{
if(_speed < -1){
_speed+=0.02;
if(_speed >=-1){
_speed = -1;
}
}else if(_speed >1){
_speed-=0.02;
if(_speed <=1){
_speed = 1;
}
}else if(_speed>-1&&_speed<0){
_speed-=0.02;
}else if(_speed<1&&_speed>0){
_speed+=0.02;
}
_container.rotationY += _ratio *_speed ;//trace(_ratio,_speed);
var p:PerspectiveProjection = new PerspectiveProjection();
p.fieldOfView = 55;
p.projectionCenter = new Point(512,-100) ; //视点
_container.transform.perspectiveProjection = p;
swapItems();
}
private function swapItems():void
{
_itemArr.sort(swapDepth);
for(var i:int = 0; i < _itemArr.length; i++ )
{
_container.addChildAt(_itemArr[i] as Sprite,i);
(_itemArr[i] as Sprite).rotationY -= _ratio *_speed;
}
}
private function swapDepth(objA:DisplayObject,objB:DisplayObject):int
{
var posA:Vector3D = objA.transform.matrix3D.position ;
posA = _container.transform.matrix3D.deltaTransformVector(posA);
var posB:Vector3D = objB.transform.matrix3D.position;
posB = _container.transform.matrix3D.deltaTransformVector(posB);
return posB.z - posA.z;
}
}
}

[ActionScript 3.0] AS3实现3D旋转的更多相关文章

  1. [ActionScript 3.0] as3处理xml的功能和遍历节点

    as3比as2处理xml的功能增强了N倍,获取或遍历节点非常之方便,类似于json对像的处理方式. XML 的一个强大功能是它能够通过文本字符的线性字符串提供复杂的嵌套数据.将数据加载到 XML 对象 ...

  2. [ActionScript 3.0] AS3.0 动态加载显示内容

    可以将下列任何外部显示资源加载到 ActionScript 3.0 应用程序中: 在 ActionScript 3.0 中创作的 SWF 文件 — 此文件可以是 Sprite.MovieClip 或扩 ...

  3. [ActionScript 3.0] AS3 3D双圆环贴图

    package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.MovieCl ...

  4. [ActionScript 3.0] AS3 3D星形贴图

    package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.MovieCl ...

  5. [ActionScript 3.0] AS3.0和AS2.0的相互通信

    AS3和AS2之间的通信,最好的方式可能就是LocalConnection了. AS2向AS3发送数据,即AS2调用AS3的函数: as2.0代码(按钮上写的发送信息代码): on (release) ...

  6. [ActionScript 3.0] AS3.0 本机鼠标指针

    Flash Player 10.2添加了内置的本机鼠标指针(native mouse cursor)支持,虽然在之前的版本里我们可以侦听MouseEvent事件来模拟鼠标指针,但是在有了原生的本机鼠标 ...

  7. [ActionScript 3.0] AS3 深入理解Flash的安全沙箱Security Domains

    简介 如果你还没有与复杂的的安全域(security domain)和应用程序域(application domain)问题打过交道,那么你真是个幸运的家伙.当你在加载外部内容(然后他们开始播放)的时 ...

  8. [ActionScript 3.0] AS3 深入理解Flash的 应用程序域Application Domains

    简介 网上有很多flash,通常都不需要显示的使用应用程序域,因为默认的应用程序域就够用了.其实复杂的情况下需要用到应用程序域,比如说有两个不同的swf,一个是旧版本的,一个是新版的,这两个文件里的类 ...

  9. [ActionScript 3.0] AS3调用百度天气预报查询API

    接口说明 根据经纬度/城市名查询天气的结果 接口示例 http://api.map.baidu.com/telematics/v3/weather?location=成都&output=jso ...

随机推荐

  1. AddComponentMenu

    [AddComponentMenu] The AddComponentMenu attribute allows you to place a script anywhere in the " ...

  2. SQL 数据库 学习 005 学习必备的一些操作 --- 如何新建数据库 如何附加和分离数据库(如何备份还原数据库) 如何删除数据库

    我的电脑系统: Windows 10 64位 使用的SQL Server软件: SQL Server 2014 Express 如果我们要学习这个数据库,我们需要学习什么知识.比如:如何新建一个数据库 ...

  3. 设计模式--适配器模式(Adapter)详解

    适配器模式将某个类的接口转换成客户端期望的另一个接口表示,目的是消除由于接口不匹配所造成的类的兼容性问题.主要分为三类:类的适配器模式.对象的适配器模式.接口的适配器模式. 01.类的适配器模式 核心 ...

  4. Cw210开发板

    达内培训嵌入式开发板 qt + kernel uboot toolchain

  5. 白盒测试实践--Day5

    累计完成任务情况: 阶段内容 参与人 完成个人情况说明并提交作业 全体 汇总作业,查漏补缺,完成代码测试总结 小靳.小龙 完成测试小结 小黄.小尹 完成静态代码检查结果报告 小靳 完成JUnit脚本编 ...

  6. Web测试项目计划与安排

    本次Web测试项目实践的需求如下: 1 选中某一款产品(暂且选择博客园和CSDN进行横向比较),对被测产品进行评测: 2 进行用户调研: 3 对产品进行定量的评价: 4 对这个产品进行分析: 5 例会 ...

  7. css实现水平伸缩菜单

    ul li a{transition:width 500ms ease;} a:hover{width:*;} 高度向上延伸用height:*;margin-top:-*px;//负值实现向上

  8. 利用crosstool-ng自动化编译交叉编译环境(转)

    原文地址:http://www.bootc.net/archives/2012/05/26/how-to-build-a-cross-compiler-for-your-raspberry-pi/ A ...

  9. 去除SVN图标并解除svn控制 (转)

    今天一不小心把F盘弄成了SVN管理项目,结果如图: 看到这个,当场晕菜,经过不懈的努力终于找到一种方法,如下: 右键  ===>TortoiseSVN   ===>Settings 点击确 ...

  10. java修饰符 protect public protected

    1.private修饰词,表示成员是私有的,只有自身可以访问: 2.protected,表示受保护权限,体现在继承,即子类可以访问父类受保护成员(子类是可以访问父类的带protected修饰符的成员的 ...