blanius
12-23-2005, 11:56 AM
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 :
//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);
};
Snippet :
//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);
};