function Vector(x,y,z){ this.x=x; this.y=y; this.z=z; }

Vector.prototype.copy = function(){ return new Vector(this.x,this.y,this.z); }
Vector.prototype.refract = function(vector){ return new Vector(this.x+vector.x, this.y+vector.y, this.z+vector.z); }
Vector.prototype.normalize = function(){ this.x*=(mag=1/Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)); this.y*=mag; this.z*=mag; }
Vector.prototype.flip = function(){ this.x=-this.x; this.y=-this.y; this.z=-this.z; }
Vector.prototype.inverse = function(){ this.x=1/this.x; this.y=1/this.y; this.z=1/this.z; }
Vector.prototype.length = function() { return Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z); }
Vector.prototype.addScalar = function(x,y,z){ this.x+=x; this.y+=y; this.z+=z; }
Vector.prototype.addVector = function(vector){ this.x+=vector.x; this.y+=vector.y; this.z+=vector.z; }
Vector.prototype.dotProduct = function(vector){ return this.x*vector.x+this.y*vector.y+this.z*vector.z; }
Vector.prototype.multiplyScalar = function(x,y,z){ this.x*=x; this.y*=y; this.z*=z; }
Vector.prototype.reflect = function(Obj){ this.x-=(dotprod=(this.x*Obj.Normal.x+this.y*Obj.Normal.y+this.z*Obj.Normal.z)*(2+(Math.random()*4-2)*Obj.noise))*Obj.Normal.x; this.y-=dotprod*Obj.Normal.y; this.z-=dotprod*Obj.Normal.z; }
Vector.crossProduct = function(vector1,vector2){ return new Vector(vector1.y*vector2.z-vector1.z*vector2.y, vector1.z*vector2.x-vector1.x*vector2.z, vector1.x*vector2.y-vector1.y*vector2.x); }
Vector.distance = function(vector1, vector2){ return new Vector(vector1.x-vector2.x,vector1.y-vector2.y,vector1.z-vector2.z); }