Posted By

daisuke103 on 02/11/08


Tagged

textmate mouse 3D load x rotation Pic as2 y


Versions (?)

AS2 マウスによって位置が変わる擬似3D回転


 / Published in: Other
 

  1. /*
  2. author page::
  3. http://www.trick7.com/blog/2006/07/05-160520.php
  4. マウスの位置によって回転
  5. リンケージ名: rect のインスタンスを用意
  6. xmlを使う時は
  7. rectNum = xmlObject.length;として
  8. init()をxmlロード後に実行
  9. */
  10.  
  11.  
  12. //--- ↓src ---
  13.  
  14.  
  15. import flash.geom.ColorTransform;
  16.  
  17. //Vanishing Point(消失点)
  18. var vpX = Stage.width/2;
  19. var vpY = Stage.height/2;
  20. //矩形の数
  21. var rectNum:Number = 20;
  22. //中心軸と配置するムービークリップとの距離
  23. var radius:Number = 150;
  24. //Focal Length(焦点距離)
  25. var fl:Number = 250;
  26.  
  27. init();
  28. function init():Void {
  29. for (var i:Number = 0; i<rectNum; i++) {
  30. var rect:MovieClip = attachMovie("rect", "rect"+i, i);
  31. var angleInitY:Number = (360/rectNum)*i;
  32. //ラジアンに変換
  33. angleInitY = angleInitY*Math.PI/180;
  34. var cosInitY:Number = Math.cos(angleInitY);
  35. var sinInitY:Number = Math.sin(angleInitY);
  36. var initX1:Number = radius*cosInitY-0*sinInitY;
  37. var initZ1:Number = 0*cosInitY+radius*sinInitY;
  38. rect.x = initX1;
  39. rect.y = 0;
  40. rect.z = initZ1;
  41. rect.number.text=i
  42. //pall.swapDepths(0)//中心棒を通す
  43. }
  44. }
  45. function onEnterFrame():Void {
  46. if(_root._xmouse>=0&&_root._xmouse<=Stage.width){//ブラウザの別ウィンドウが開かれた時の対策
  47. for (var i:Number = 0; i<rectNum; i++) {
  48. var rect:MovieClip = this["rect"+i];
  49. var angleY:Number = (_xmouse-vpX)*0.001;
  50. var cosY:Number = Math.cos(angleY);
  51. var sinY:Number = Math.sin(angleY);
  52. var angleX:Number = (_ymouse-vpY)*0.001;
  53. var cosX:Number = Math.cos(angleX);
  54. var sinX:Number = Math.sin(angleX);
  55.  
  56. var x1:Number = rect.x*cosY-rect.z*sinY;
  57. var z1:Number = rect.z*cosY+rect.x*sinY;
  58. var y1:Number = rect.y*cosX-z1*sinX;
  59. var z2:Number = z1*cosX+rect.y*sinX;
  60.  
  61. rect.x = x1;
  62. rect.y = y1;
  63. rect.z = z2;
  64. var scale = fl/(fl+rect.z);
  65. rect._xscale = rect._yscale=scale*100;
  66. rect._x = vpX+(rect.x*scale);
  67. rect._y = vpY+(rect.y*scale);
  68. //zの値をもとに、重なり順を調整
  69. rect.swapDepths(-rect.z);
  70. //奥のムービークリップの明度を下げる
  71. var val = Math.min(-5*Math.sqrt(z2),0);
  72. rect.transform.colorTransform = new ColorTransform(1, 1, 1, 1, val, val, val, 0);
  73. }
  74. }
  75. }

Report this snippet  

You need to login to post a comment.