A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Velocity Acceleration and Vectors Code

  1. #1
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    Velocity Acceleration and Vectors Code

    I've been reading a book call "Robert Penner's Programming Macromedia Flash MX" and just typed/modified his Vector Class that he uses to do velocity and Acceleration. Interesting stuff. If anyone wants the code that I modified for KM let me know.

    Snippet :
    Code:
    //Math Functions needed in Vector class
    
    atan2D=function(y,x){
    
       return Math.atan2(y,x)*(180/Math.PI);
    
       }
    
    cos2D=function(angle){
    
       return Math.cos(angle*(Math.PI/180));
    
       }
    
    sin2D=function(angle){
    
    	return Math.sin(angle*(Math.PI/180));
    
    	}
    
    acosD=function(ratio){
    
    	return Math.acos(ratio)*(180/Math.PI);
    
    	}
    
    	
    
    //Vector Class	
    
    function Vector(x,y){
    
       this.x=x;
    
       this.y=y;
    
       };
    
    Vector.prototype.toString=function(){
    
       var rx=Math.round(this.x*1000)/1000;
    
       var ry=Math.round(this.y*1000)/1000;
    
       return "["+rx+","+ry+"]";
    
       };
    
       
    
    Vector.prototype.reset=function(x,y){
    
       this.constructor(x,y);
    
       };

  2. #2
    Senior Member
    Join Date
    Jun 2000
    Posts
    3,512
    An example of how to use this would be valuable.

  3. #3
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Working on that next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center