topical media & game development

talk show tell print

student-ar-org-papervision3d-core-math-Number2D.ax

student-ar-org-papervision3d-core-math-Number2D.ax [swf] [flash] flex


  package org.papervision3d.core.math 
{
        import org.papervision3d.Papervision3D;        
        
        
* PLUG-IN MEDIA 2D Vector Class, by Seb Lee-Delisle re-written for Papervision3D as @ax-student-ar-org-papervision3d-core-math-Number2D. * * Version 0.1 10 Feb 2008

  
        public class @ax-student-ar-org-papervision3d-core-math-Number2D 
        {
                public static const RADTODEG : Number = 180/Math.PI;                
                public static const DEGTORAD : Number = Math.PI/180;
                
                public var x:Number; 
                public var y:Number; 
                
                public function @ax-student-ar-org-papervision3d-core-math-Number2D (x:Number = 0, y:Number = 0)
                {
                        this.x = x; 
                        this.y = y; 
                }
                
         
                 public function toString():String
                {
                    var x:Number = Math.round (this.x * 1000) / 1000;
                        var y:Number = Math.round (this.y * 1000) / 1000;
                        return "[" + x + ", " + y + "]";
                }
                
                public function clone():@ax-student-ar-org-papervision3d-core-math-Number2D
                {
                        return new @ax-student-ar-org-papervision3d-core-math-Number2D(this.x, this.y);
                }
                
                public function copyTo(v:@ax-student-ar-org-papervision3d-core-math-Number2D):void
                {
                        v.x = this.x;
                        v.y = this.y;
                }
                public function copyFrom(v:@ax-student-ar-org-papervision3d-core-math-Number2D):void
                {
                        this.x = v.x;
                        this.y = v.y;
                }        
                
                public function get modulo():Number 
                {
                        return Math.sqrt((x*x)+(y*y));
                }
                
                public function normalise():void 
                {
                        var m:Number = this.modulo;
                        
                        this.x = this.x/m;
                        this.y = this.y/m;
        
                        
                }
                
                public function reverse():void 
                {
                        this.x = -this.x;
                        this.y = -this.y;
                }
                
                public static function add(v:@ax-student-ar-org-papervision3d-core-math-Number2D, w:@ax-student-ar-org-papervision3d-core-math-Number2D): @ax-student-ar-org-papervision3d-core-math-Number2D {
                        
                        return new @ax-student-ar-org-papervision3d-core-math-Number2D( v.x+=w.x, v.y+w.y);
        
                }
                public static function subtract(v:@ax-student-ar-org-papervision3d-core-math-Number2D, w:@ax-student-ar-org-papervision3d-core-math-Number2D): @ax-student-ar-org-papervision3d-core-math-Number2D {
                        
                        return new @ax-student-ar-org-papervision3d-core-math-Number2D( v.x-w.x, v.y-w.y);
        
                }        
                public function plusEq(v:@ax-student-ar-org-papervision3d-core-math-Number2D) :void
                {
                        x+=v.x; 
                        y+=v.y; 
                        
                }
                public function minusEq(v:@ax-student-ar-org-papervision3d-core-math-Number2D) :void
                {
                        x-=v.x; 
                        y-=v.y; 
                        
                }
                
                public function divideEq(d : Number) : void
                {
                        x/=d; 
                        y/=d; 
                }
                public function multiplyEq(d : Number) : void
                {
                        x*=d; 
                        y*=d; 
                }
                
                
                public static function multiplyScalar(v:@ax-student-ar-org-papervision3d-core-math-Number2D, n:Number) : @ax-student-ar-org-papervision3d-core-math-Number2D
                {
                        return new @ax-student-ar-org-papervision3d-core-math-Number2D
                        (
                                v.x*n,
                                v.y*n
                        );
                        
                }
        

                
                public static function dot(v:@ax-student-ar-org-papervision3d-core-math-Number2D, w:@ax-student-ar-org-papervision3d-core-math-Number2D):Number
                {
                        return v.x * w.x + v.y * w.y ;
                }
                
                
                public function angle():Number
                {
                        
                        if(Papervision3D.useDEGREES)
                                return ( RADTODEG*(Math.atan2(y,x)));
                        else 
                                return (Math.atan2(y,x));
                        
        
                }
                
                
        
                public function rotate(angle:Number) :void{
                        if(Papervision3D.useDEGREES) angle*=DEGTORAD;
                        var cosRY:Number = Math.cos(angle);
                        var sinRY:Number = Math.sin(angle);
                        var temp:@ax-student-ar-org-papervision3d-core-math-Number2D;
        
                        temp = clone();
                        
                        
                        this.x= (temp.x*cosRY)-(temp.y*sinRY);
                        this.y= (temp.x*sinRY)+(temp.y*cosRY);
                        
                        
                }        
                
                
                public function reset(x:Number = 0, y:Number = 0) :void
                {
                        
                        this.x = x;
                        this.y = y;
        
                }

                // ______________________________________________________________________
                
                
* Super fast modulo(length, magnitude) comparisons. * *

  
                 
                public function isModuloLessThan(v:Number):Boolean
                {
                                
                        return (moduloSquared<(v*v)); 
                        
                }
                
                public function isModuloGreaterThan(v:Number):Boolean
                {
                                
                        return (moduloSquared>(v*v)); 
                        
                }
                public function isModuloEqualTo(v:Number):Boolean
                {
                                
                        return (moduloSquared==(v*v)); 
                        
                }
                        
                public function get moduloSquared():Number
                {
                        return ( this.x*this.x + this.y*this.y );
                }
                  
          
        }
        
        
        }


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.