Guest User

Untitled

a guest
Aug 8th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import flash.geom.Vector3D;
  2. import flash.geom.Matrix3D;
  3.  
  4. var topLeft:Vector3D = new Vector3D(-20, -20, 0);
  5. var topRight:Vector3D = new Vector3D(100, -20, 0);
  6. var bottomRight:Vector3D = new Vector3D(100, 100, 0);
  7. var bottomLeft:Vector3D = new Vector3D(-20, 100, 0);
  8.  
  9. function draw():void{
  10.     graphics.beginFill(0xFF0000);
  11.     graphics.drawCircle(topLeft.x, topLeft.y, 4);
  12.     graphics.drawCircle(topRight.x, topRight.y, 4);
  13.     graphics.drawCircle(bottomRight.x, bottomRight.y, 4);
  14.     graphics.drawCircle(bottomLeft.x, bottomLeft.y, 4);
  15. }
  16.  
  17. var matrix:Object = {};
  18. matrix.m11 = 1; matrix.m12 = 0; matrix.m13 = 0;
  19. matrix.m21 = 0; matrix.m22 = 1; matrix.m23 = 0;
  20. matrix.m31 = 0; matrix.m32 = 0; matrix.m33 = 1;
  21.  
  22. setupScale(0.5, 0.5);
  23. setupRotation(10 * Math.PI / 180);
  24. setupTranslation(100, 100);
  25.  
  26. topLeft = transformVector(topLeft);
  27. topRight = transformVector(topRight);
  28. bottomRight = transformVector(bottomRight);
  29. bottomLeft = transformVector(bottomLeft);
  30.  
  31. draw();
  32.  
  33. function setupScale(xScale:Number, yScale:Number):void {
  34.     matrix.m11 *= xScale;
  35.     matrix.m22 *= yScale;
  36. }
  37.  
  38. function setupRotation(ang:Number):void {
  39.     var sin:Number = Math.sin(ang);
  40.     var cos:Number = Math.cos(ang);
  41.    
  42.     matrix.m11 *= cos;    matrix.m12 = -sin;
  43.     matrix.m21 = sin;     matrix. m22 *= cos;
  44. }
  45.  
  46. function setupTranslation(x:Number, y:Number):void{
  47.     matrix.m31 = x;        matrix.m32 = y;
  48. }
  49.  
  50. function transformVector(v:Vector3D):Vector3D{
  51.     return new Vector3D(v.x * matrix.m11 + v.y * matrix.m21 + matrix.m31, v.x * matrix.m12 + v.y * matrix.m22 + matrix.m32);
  52. }
Add Comment
Please, Sign In to add comment