daily pastebin goal
39%
SHARE
TWEET

Untitled

tinyevil Nov 5th, 2018 116 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package flash.geom
  2. {
  3.    [native(instance="Vector3DObject",methods="auto",cls="Vector3DClass")]
  4.    [Version("10")]
  5.    public class Vector3D
  6.    {
  7.      
  8.       public static const X_AXIS:Vector3D = new Vector3D(1,0,0);
  9.      
  10.       public static const Y_AXIS:Vector3D = new Vector3D(0,1,0);
  11.      
  12.       public static const Z_AXIS:Vector3D = new Vector3D(0,0,1);
  13.        
  14.      
  15.       public var x:Number;
  16.      
  17.       public var y:Number;
  18.      
  19.       public var z:Number;
  20.      
  21.       public var w:Number;
  22.      
  23.       public function Vector3D(x:Number = 0.0, y:Number = 0.0, z:Number = 0.0, w:Number = 0.0)
  24.       {
  25.          super();
  26.          this.x = x;
  27.          this.y = y;
  28.          this.z = z;
  29.          this.w = w;
  30.       }
  31.      
  32.       public static function angleBetween(a:Vector3D, b:Vector3D) : Number
  33.       {
  34.          var dot:Number = a.x * b.x + a.y * b.y + a.z * b.z;
  35.          var al:Number = a.length;
  36.          var bl:Number = b.length;
  37.          dot = dot / (al * bl);
  38.          if(watson(3109405))
  39.          {
  40.             if(dot < -1)
  41.             {
  42.                dot = -1;
  43.             }
  44.             if(dot > 1)
  45.             {
  46.                dot = 1;
  47.             }
  48.          }
  49.          return Math.acos(dot);
  50.       }
  51.      
  52.       public static function distance(pt1:Vector3D, pt2:Vector3D) : Number
  53.       {
  54.          return pt1.subtract(pt2).length;
  55.       }
  56.      
  57.       public function clone() : Vector3D
  58.       {
  59.          return new Vector3D(this.x,this.y,this.z,this.w);
  60.       }
  61.      
  62.       public function dotProduct(a:Vector3D) : Number
  63.       {
  64.          return this.x * a.x + this.y * a.y + this.z * a.z;
  65.       }
  66.      
  67.       public function crossProduct(a:Vector3D) : Vector3D
  68.       {
  69.          return new Vector3D(this.y * a.z - this.z * a.y,this.z * a.x - this.x * a.z,this.x * a.y - this.y * a.x,1);
  70.       }
  71.      
  72.       public function get length() : Number
  73.       {
  74.          var r:Number = this.x * this.x + this.y * this.y + this.z * this.z;
  75.          if(r <= 0)
  76.          {
  77.             return 0;
  78.          }
  79.          return Math.sqrt(r);
  80.       }
  81.      
  82.       public function get lengthSquared() : Number
  83.       {
  84.          return this.x * this.x + this.y * this.y + this.z * this.z;
  85.       }
  86.      
  87.       public function normalize() : Number
  88.       {
  89.          var len:Number = this.length;
  90.          var lenInv:Number = len != 0?Number(1 / len):Number(0);
  91.          this.x = this.x * lenInv;
  92.          this.y = this.y * lenInv;
  93.          this.z = this.z * lenInv;
  94.          return len;
  95.       }
  96.      
  97.       public function scaleBy(s:Number) : void
  98.       {
  99.          this.x = this.x * s;
  100.          this.y = this.y * s;
  101.          this.z = this.z * s;
  102.       }
  103.      
  104.       public function incrementBy(a:Vector3D) : void
  105.       {
  106.          this.x = this.x + a.x;
  107.          this.y = this.y + a.y;
  108.          this.z = this.z + a.z;
  109.       }
  110.      
  111.       public function decrementBy(a:Vector3D) : void
  112.       {
  113.          this.x = this.x - a.x;
  114.          this.y = this.y - a.y;
  115.          this.z = this.z - a.z;
  116.       }
  117.      
  118.       public function add(a:Vector3D) : Vector3D
  119.       {
  120.          return new Vector3D(this.x + a.x,this.y + a.y,this.z + a.z);
  121.       }
  122.      
  123.       public function subtract(a:Vector3D) : Vector3D
  124.       {
  125.          return new Vector3D(this.x - a.x,this.y - a.y,this.z - a.z);
  126.       }
  127.      
  128.       public function negate() : void
  129.       {
  130.          this.x = -this.x;
  131.          this.y = -this.y;
  132.          this.z = -this.z;
  133.       }
  134.      
  135.       public function equals(toCompare:Vector3D, allFour:Boolean = false) : Boolean
  136.       {
  137.          return this.x == toCompare.x && this.y == toCompare.y && this.z == toCompare.z && (!!allFour?(this.w == toCompare.w):true);
  138.       }
  139.      
  140.       public function nearEquals(toCompare:Vector3D, tolerance:Number, allFour:Boolean = false) : Boolean
  141.       {
  142.          var diff:Number = this.x - toCompare.x;
  143.          diff = diff < 0?(0 - diff):(diff);
  144.          var goodEnough:Boolean = diff < tolerance;
  145.          if(goodEnough)
  146.          {
  147.             diff = this.y - toCompare.y;
  148.             diff = diff < 0?(0 - diff):(diff);
  149.             goodEnough = diff < tolerance;
  150.             if(goodEnough)
  151.             {
  152.                diff = this.z - toCompare.z;
  153.                diff = diff < 0?(0 - diff):(diff);
  154.                goodEnough = diff < tolerance;
  155.                if(goodEnough && allFour)
  156.                {
  157.                   diff = this.w = toCompare.w;
  158.                   diff = diff < 0?(0 - diff):(diff);
  159.                   goodEnough = diff < tolerance;
  160.                }
  161.             }
  162.          }
  163.          return goodEnough;
  164.       }
  165.      
  166.       public function project() : void
  167.       {
  168.          var tRecip:Number = 1 / this.w;
  169.          this.x = this.x * tRecip;
  170.          this.y = this.y * tRecip;
  171.          this.z = this.z * tRecip;
  172.       }
  173.      
  174.       AS3 function toString() : String
  175.       {
  176.          var s:String = "Vector3D(" + this.x + ", " + this.y + ", " + this.z;
  177.          s = s + ")";
  178.          return s;
  179.       }
  180.      
  181.       [API("674")]
  182.       public function copyFrom(sourceVector3D:Vector3D) : void
  183.       {
  184.          this.x = sourceVector3D.x;
  185.          this.y = sourceVector3D.y;
  186.          this.z = sourceVector3D.z;
  187.       }
  188.      
  189.       [API("674")]
  190.       public function setTo(xa:Number, ya:Number, za:Number) : void
  191.       {
  192.          this.x = xa;
  193.          this.y = ya;
  194.          this.z = za;
  195.       }
  196.    }
  197. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top