[笔记]chapter7 of 《Advanced ActionScript3 Animation》

前面的几章关于算法等一些东西,暂时没有看,直接从第七章开始

这一章主要讲了一些基于flash cs4 的3d基础知识,图形方面的知识感觉比较简单,列一下知识点,算是这一天总结。

1.左右手坐标系,弧度和角度

2.skills:同样的代码不同编译器可能会产生不同的效果,或者是因为浏览器等产生舞台大小不同造成显示效果不同;

   方法1:设置固定舞台大小:[SWF(backgroundColor=oxffffff, width=800, height=600)]

   方法2:设置“居中”:root.transform.perspectiveProjection.projectionCenter=new Point(stage.stageWidth/2, stage.stageHeight/2);

3.3D Positioning:(目前来看)flash里面的平移直接用调用对象属性运算就可以了,暂时没有用到矩阵,不过想想也是,显示对象一般都包含在Sprite那么      只需要改变容器的相应属性就可以了,不过总是感觉怪怪的,线性问题是怎么解决的...看完这本书再看看是不是自己写一个 对于flash10中的matrix3D还缺    乏更深认识.

4.Depth sorting:就是将“显示元素”放入数组排序,然后按z的大小排序

5.3D containers:sprite容器 无需多写

6.3D Rotation:也是直接调用相关的 RotationX,RotationY,RotationZ 来转动,同样是没有用矩阵。不过这里的例子已经比较有意思,每次对                Sprite(包含多个shape),每对sprite的z调整都要从新对z排序,用到了前面的depth sorting。特别的将第二个例子的代码粘出来,因为貌似源代码参数    有些小问题。把半径调小了一些,还有初始化的RotationY值的计算也调整了一下,这样就是书中的效果了。


ContractedBlock.gif ExpandedBlockStart.gif Code
 1 package
 2 {
 3     import flash.display.DisplayObject;
 4     import flash.display.Sprite;
 5     import flash.events.Event;
 6     import flash.geom.Vector3D;
 7     
 8     [SWF(width=800, height=800, backgroundColor = 0xffffff)]
 9     public class Carousel extends Sprite
10     {
11         private var _holder:Sprite;
12         private var _items:Array;
13         private var _radius:Number = 100;
14         private var _numItems:int = 10;
15         
16         public function Carousel()
17         {
18             root.transform.perspectiveProjection.focalLength = 155;
19             
20             _holder = new Sprite();
21             _holder.x = stage.stageWidth / 2;
22             _holder.y = stage.stageHeight / 2;
23             _holder.z = 0;
24             addChild(_holder);
25             
26             _items = new Array();
27             
28             //_radius = 200;
29             for(var i:int = 0; i < _numItems; i++)
30             {
31                 var angle:Number = Math.PI * 2 / _numItems * i;
32                 trace("angle is ",angle);
33                 var item:Sprite = makeItem();
34                 item.x = Math.cos(angle) * _radius;
35                 item.z = Math.sin(angle) * _radius;
36                 trace("the ",item.z);
37                 item.rotationY = -360 / _numItems * i ;
38                 item.rotationY +=-180/_numItems+90;
39                 _items.push(item);
40             }
41             sortItems();
42             
43             addEventListener(Event.ENTER_FRAME, onEnterFrame);
44         }
45         
46         private function makeItem():Sprite
47         {
48             var item:Sprite = new Sprite();
49             item.graphics.beginFill(Math.random() * 0xffffff);
50             item.graphics.drawRect(-50-505050);
51             _holder.addChild(item);
52             return item;
53         }
54         
55         private function sortItems():void
56         {
57             _items.sort(depthSort);
58             for(var i:int = 0; i < _items.length; i++)
59             {
60                 _holder.addChildAt(_items[i] as Sprite, i);
61             }
62         }
63         
64         private function depthSort(objA:DisplayObject, objB:DisplayObject):int
65         {
66             var posA:Vector3D = objA.transform.matrix3D.position;
67             posA = _holder.transform.matrix3D.deltaTransformVector(posA);
68             var posB:Vector3D = objB.transform.matrix3D.position;
69             posB = _holder.transform.matrix3D.deltaTransformVector(posB);
70             return posB.z - posA.z;
71         }
72         
73         private function onEnterFrame(event:Event):void
74         {
75             _holder.rotationY += (stage.stageWidth / 2 - mouseX) * .01;
76             _holder.y += (mouseY - _holder.y) * .1;
77             sortItems();
78         }
79     }
80 }
81 

 

7.Field of View and Focal Length:两个属性来调节depth of field,Field of View 可以看成是一个视觉范围的角度(0-180度),另一个Focal Length可    以理解为视觉最大长度,他们之间是相互联系的,不过一般只设置一个属性就好了 。


 


8.Screen and 3D Coordinates:坐标系转换,一个是 用local3DToGlobal,另一个是掉过来,参数是Vector3D

9.Pointing at Something:特别的有一个PointAt 函数囧......作者也不太确定这东西干啥的,他说也许可以用在瞄准射击之类的应用上面吧。

ok 完事了,有时间一定要看看 geom 包

sleep。。。。。。

 

转载于:https://www.cnblogs.com/sun11086/archive/2009/02/28/1400089.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值