<>

第三章 三角学

3.1 基本三角函数的计算:
 角的正弦值 = 对边 / 斜边
 角的余弦值 = 邻边 / 斜边
 角的正切值 = 对边 / 邻边

3.2 角度与弧度的相互装换:
 弧度 = 角度 * Math.PI / 180
 角度 = 弧度* 180 / Math.PI

3.3 向鼠标旋转:

//substitute mouseX, mouseY with the x , y point to rotate to

 dx = mouseX - sprite.x;

 dy = mouseY - sprite.y;

 spirte.rotation = Math.atan2(dy, dx) * 180 / Math.PI;

3.4 创建波形:

 //assign value to x, y or other property of sprite or movie clip,

 //use as drawing coordinates, etc.

 public function OnEnterFrame(event : Event)

 {

  value = center + Math.sin(angle) * range;

  angle += speed;

 }

3.5 创建圆形:

 //assign position to x and y of sprte or movie clip,

 //use as drawing coordinates, etc.

 public function OnEnterFrame(event : Event)

 {

  xposition = centerX + Math.cos(angle) * radius;

  yposition = centerY + Math.sin(angle) * radius;



  angle += speed;

 }

3.6 创建椭圆:

//assign position to x and y of sprite or movie clip,

 //use as drawing coordinates, etc.

 public function OnEnterFrame(event : Event) : void

 {

  xposition = centerX + Math.cos(angle) * radiusX;

  yposition = centerY + Math.sin(angle) * radiusY;



  angle += speed;

 }

3.7 计算两点间的距离:

 //points are x1, y1 and x2, y2

 //can be sprite / movie clip positions, mouse coordinates, etc.

 dx = x2 - x1;

 dy = y2 - y1;



 dist = Math.sqrt(dx * dx + dy * dy);

 

第四章 渲染技术

4.1 转换为十进制:
 trace(hexValue);
 十进制转换成十六进制:
 trace(decimalValue.toString(16));
4.2 颜色合成:
 color24 = red << 16 | green << 8  | blue;
 color32 = alpha << 24 | red << 16 | green << 8 | blue;
4.3 颜色提取:
 red = color24 >> 16; green = color24 >> 8 & 0xFF; blue = color24 & 0xFF;
 alpha = color32 >> 24; red = color32 >> 16 & 0xFF; green = color32 >> 8 & 0xFF; blue = color32 & 0xFF;
4.4 过控制点的曲线:

 //xt, yt is the point you want to draw through

 //x0, y0 and x2, y2 are the end points of the curve

 x1 = xt * 2 - (x0 + x2) / 2;

 y1 = yt * 2 - (y0 + y2) / 2;

 moveTo(x0, y0);

 curveTo(x1, y1, x2, y2);

 

 第五章 速度与加速度

5.1 角速度转换为x,y速度向量:
 vx = speed * Math.cos(angle);
 vy = speed * Math.sin(angle);
5.2 角加速度(作用于物体上的force)转换为x, y加速度:
 ax = force * Math.cos(angle);
 ay = force * Math.sin(angle);
5.3 将加速度加入速度向量:
 vx += ax;
 vy += ay;
5.4 将速度向量加入坐标:
 movieclip._x += vx;
 sprite.y += vy;

第六章 边界与摩擦力

6.1 移除出界对象:

 if(sprite.x - sprite.width / 2 > right ||

  sprite.x + sprite.width / 2 < left ||

  sprite.y - sprite.height / 2 > bottom ||

  sprite.y + sprite.height / 2 < top)

 {

  //移除影片的代码

 }

6.2 重置出界对象:

 if(sprite.x - sprite.width / 2 > right ||

  sprite.x + sprite.width / 2 < left ||

  sprite.y - sprite.height / 2 > bottom ||

  sprite.y + sprite.height / 2 < top)

 {

  //重置对象位置和速度

 }

6.3 屏幕环绕出界对象:

 if(sprite.x - sprite.width / 2 > right)

 {

  sprite.x = left - sprite.width / 2;

 }

 else if(sprite.x + sprite.width / 2 < left)

 {

  sprite.x = right + sprite.width / 2;

 }



 if(sprite.y - sprite.height / 2 > bottom)

 {

  sprite.y = top - sprite.height / 2;

 }

 else if(sprite.y + sprite.height / 2 < top)

 {

  sprite.y = bottom + sprite.height / 2;

 }

6.4 摩擦力应用(正确方法):

 speed = Math.sqrt(vx * vx + vy * vy);

 angle = Math.atan2(vy, vx);



 if(speed > friction)

 {

  speed -= friction;

 }

 else

 {

  speed = 0;

 }



 vx = Math.cos(angle) * speed;

 vy = Math.sin(angle) * speed;

6.5 摩擦力应用(简便方法):
 vx *= friction;
 vy *= friction;

第七章 交互动画--移动物体

 7.1 鼠标的基本事件:按下,弹起以及移动的基本应用
 7.2 鼠标拖拽的实现:第一,使用MouseMove事件实现,可以拖拽多个物品。第二,用内置的startDrag一次只能拖一个。
 7.3 结合运动小球代码实现拖拽
 7.4 投掷功能的实现。

第八章 缓动与弹性运动

 8.1 简单缓动,长形:

 var dx : Number = targetX - sprite.x;

 var dy : Number = targetY - sprite.y;

 vx = dx * easing;

 vy = dy * easing;

 sprite.x += vx;

 sprite.y += vy;

8.2简单缓动,中形:

 vx = (targetX - sprite.x) * easing;

 vy = (targetY - sprite.y) * easing;

 sprite.x += vx;

 sprite.y += vy;

8.3简单缓动,短形:

 sprite.x += (targetX - sprite.x) * easing;

 sprite.y += (targetY - sprite.y) * easing;

8.4 简单弹性,长形:

 var ax : Number = (targetX - sprite.x) * spring;

 var ay : Number = (targetY - sprite.y) * spring;

 vx += ax;

 vy += ay;

 vx *= friction;

 vy *= friction;

 sprite.x += vx;

 sprite.y += vy;

8.5 偏移弹性运动:

var dx : Number = sprite.x - fixedX;

 var dy : Number = sprite.y - fixedY;

 var angle : Number = Math.atan2(dy, dx);

 var targetX : Number = fixedX + Math.cos(angle) * springLength;

 var targetY : Number = fixedY + Math.sin(angle) * springLength;

 

第九章 碰撞检测

9.1 距离碰撞检测:

//从spriteA 和spriteB开始,如果使用空白影片或没有半径则用宽度与高度除以2

 var dx : Number = spriteB.x - spriteA.x;

 var dy : Number = spriteB.y - spriteA.y;

 var dist : Number = Math.sqrt(dx * dx + dy * dy);

 if(dist < spriteA.radius + spriteB.radius)

 {

  //处理碰撞

 }

9.2 多物体碰撞检测:

 var numObjects : uint = 10;

 for(var i : uint = 0; i < numObjects - 1; i++)

 {

  var objectA = objects[i];

  for(var j : uint = i + 1; j < numObjects; j++)

  {

   var objectB = objects[j];



   if(objectB.hitObjectTest(objectA))

   {

    //碰撞处理

   }

  }

 }

 

第十章 坐标选装及角度反弹

10.1 坐标旋转:

 x1 = Math.cos(angle) * x - Math.sin(angle) * y;

 y1 = Math.cos(angle) * y + Math.sin(angle) * x;

10.2 反坐标旋转:

 x1 = Math.cos(angle) * x + Math.sin(angle) * y;

 y1 = Math.cos(angle) * y - Math.sin(angle) * x;

 

第十一章 撞球物理

11.1 动量守恒的数学表达式:
 v0Final = ((m0 - m1) * v0 + 2 * m1 * v1) / m0 + m1;
 v1Final = ((m1 - m0) * v1 + 2 * m0 * v0) / m0 + m1;

11.2 动量守恒ActionScript表达式:

 var vxTotal : Number = vx0 - vx1;

 vx0 = ((ball0.mass - ball1.mass) * vx0 + 2 * ball1.mass * vx1) / (ball0.mass + ball1.mass);

 vx1 = vxTotal + vx0;

 

第十二章 粒子引力与万有引力

12.1 引力一般公式:
 force = G * m1 * m2 / distance * distance;

12.2 ActionScript实现万有引力:

 function Gravitate(partA : Ball, partB : Ball) : void

 {

  var dx : Number = partB.x - partA.x;

  var dy : Number = partB.y - partA.y;

  var distSQ : Number = dx * dx + dy * dy;

  var dist : Number = Math.sqrt(distSQ);

  var force : Number = partA.mass * partB.mass / distSQ;

  var ax : Number = force * dx / dist;

  var ay : Number = force * dy / dist;

  partA.vx += ax / partA.mass;

  partA.vy += ay / partA.mass;

  partB.vx -= ax / partB.mass;

  partB.vy -= ay / partB.mass;

 }

 


第十三章 正向运动学:行走
第十四章 反向运动学:拖拽与伸展

14.1 余弦定理:
 a*a = b * b + c * c - 2 * b * c * cosA
 b * b = a * a + c* c - 2 * a * c * cosB
 c * c = a * a + b * b - 2 * a * b * cosC

14.2 ActionScript的余弦定理:

 var A : Number = Math.acos((b * b + c * c - a * a) / (2 * b * c));

 var B : Number = Math.acos((a * a + c * c - b * b) / (2 *a * c));

 var C : Number = Math.acos((a * a + b * b - c * c) / (2 * a * b));


第十五章 3D基础

15.1 基本透视法:

 scale = fl / (fl + zpos);

 sprite.scaleX = sprite.scaleY = scale;

 sprite.alpha = scale;//可选

 sprite.x = vanishingPointX + xpos * sclae;

 sprite.y = vanishingPointY + ypos * scale;

15.2 Z轴排序:

 //假设有一个带有Zpos属性的3D物体数组

 objectArray.sortOn("zpos", Array.DESCENDING | Array.NUMERIC);

 for(var i : uint = 0; i < numObjects; i++)

 {

  setChildIndex(objectArray[i], i);

 }

15.3 坐标旋转:

 x1 = cos(angleZ) * xpos - sin(angleZ) * ypos;

 y1 = cos(angleZ) * ypos + sin(angleZ) * xpos;

 x1 = cos(angleY) * xpos - sin(angleY) * zpos;

 z1 = cos(angleY) * zpos + sin(angleY) * xpos;

 y1 = cos(angleX) * ypos - sin(angleX) * zpos;

 z1 = cos(angleX) * zpos + sin(angleX) * ypos;

15.4 3D距离:
 dist = Math.sqrt(dx * dx + dy * dy + dz * dz);

第十六章 3D线条与填充

第十七章 背面剔除与3D灯光

第十八章 矩阵数学

第十九章 实用技巧

你可能感兴趣的:(actionscript)