[ActionScript 3.0] AS3实现3D旋转
- 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旋转的更多相关文章
- [ActionScript 3.0] as3处理xml的功能和遍历节点
as3比as2处理xml的功能增强了N倍,获取或遍历节点非常之方便,类似于json对像的处理方式. XML 的一个强大功能是它能够通过文本字符的线性字符串提供复杂的嵌套数据.将数据加载到 XML 对象 ...
- [ActionScript 3.0] AS3.0 动态加载显示内容
可以将下列任何外部显示资源加载到 ActionScript 3.0 应用程序中: 在 ActionScript 3.0 中创作的 SWF 文件 — 此文件可以是 Sprite.MovieClip 或扩 ...
- [ActionScript 3.0] AS3 3D双圆环贴图
package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.MovieCl ...
- [ActionScript 3.0] AS3 3D星形贴图
package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.MovieCl ...
- [ActionScript 3.0] AS3.0和AS2.0的相互通信
AS3和AS2之间的通信,最好的方式可能就是LocalConnection了. AS2向AS3发送数据,即AS2调用AS3的函数: as2.0代码(按钮上写的发送信息代码): on (release) ...
- [ActionScript 3.0] AS3.0 本机鼠标指针
Flash Player 10.2添加了内置的本机鼠标指针(native mouse cursor)支持,虽然在之前的版本里我们可以侦听MouseEvent事件来模拟鼠标指针,但是在有了原生的本机鼠标 ...
- [ActionScript 3.0] AS3 深入理解Flash的安全沙箱Security Domains
简介 如果你还没有与复杂的的安全域(security domain)和应用程序域(application domain)问题打过交道,那么你真是个幸运的家伙.当你在加载外部内容(然后他们开始播放)的时 ...
- [ActionScript 3.0] AS3 深入理解Flash的 应用程序域Application Domains
简介 网上有很多flash,通常都不需要显示的使用应用程序域,因为默认的应用程序域就够用了.其实复杂的情况下需要用到应用程序域,比如说有两个不同的swf,一个是旧版本的,一个是新版的,这两个文件里的类 ...
- [ActionScript 3.0] AS3调用百度天气预报查询API
接口说明 根据经纬度/城市名查询天气的结果 接口示例 http://api.map.baidu.com/telematics/v3/weather?location=成都&output=jso ...
随机推荐
- html学习代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- 【sdut2878】Circle
题目链接http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/2878.html 题意 n个结点编号为0 ...
- [hdu2665]Kth number(划分树求区间第k大)
解题关键:划分树模板题. #include<cstdio> #include<cstring> #include<algorithm> #include<cs ...
- Zedboard学习(三):PL下流水灯实验 标签: fpgazynqPL 2017-07-05 11:09 21人阅读 评论(0)
zynq系列FPGA分为PS部分和PL部分. PL: 可编程逻辑 (Progarmmable Logic), 就是FPGA部分. PS: 处理系统 (Processing System) , 就是与F ...
- [Training Video - 4] [Groovy] Function in detail
Employee.log=log Employee e1 = new Employee() Employee e2 = new Employee() e1.name = "A" e ...
- [BAT] 通过批处理删除7天前的报告,并删除当前目录下的空文件夹
set reportPath=D:\AutomationReport cd /d %reportPath% forfiles /p %reportPath% /s /m *.xml /d -7 /c ...
- datatable:dt.page(dt.page()).draw(false)
dt.page(dt.page()).draw(false);该方法可以直接返回到当前页,不用重新绘制table 描述 分页是DataTables的一个核心功能,并且该方法提供对表格显示页面的外部控制 ...
- WindowServer2016无法安装.netframework3.5
因为安装sql server的原因 需要安装.NET Framework3.5 报错内容如下: 原因分析 找不到安装源文件. 解决办法 可以通过如下 PowerShell 脚本进行安装: 从开始菜单中 ...
- (转)TinyHttp源码剖析
tinyhttpd 是一个不到 500 行的超轻量型 Http Server,用来学习非常不错,可以帮助我们真正理解服务器程序的本质. 看完所有源码,真的感觉有很大收获,无论是 unix 的编程,还是 ...
- 开源SLAM
GitHub 上优秀的开源SLAM repo (更新中):https://www.jianshu.com/p/464ca0d0c254 当前的开源SLAM方案:https://www.cnblogs. ...