Balls
makes a vector and applies functions
JavaScript
var Position = (function () {
function Position(x, y) {
this.x = x;
this.y = y;
this.velocity = new Vector(0, 0);
this.xMax = 100;
this.yMax = 100;
this.radius = 10;
this.accel = new Vector(0,0);
}
return Position;
})();
Position.prototype = {
impact: function (point2) {
var point1 = this;
var normal = point1.toPoint(point2);
var normal2 = point2.toPoint(point1);
var tangent = new Vector(-normal.y, normal.x);
var tangent2 = new Vector(-normal2.y, normal2.x);
normal.norm();
normal2.norm();
tangent.norm();
tangent2.norm();
var midpoint = new Vector(((point1.x + point2.x) / 2.0),(point1.y + point2.y) / 2.0);
point1.x = ((point1.x + point2.x) / 2.0) - normal.x * this.radius;
point1.y = ((point1.y + point2.y) / 2.0) - normal.y * this.radius;
point2.x = ((point1.x + point2.x) / 2.0) - normal2.x * point2.radius;
point2.y = ((point1.y + point2.y) / 2.0) - normal2.y * point2.radius;
var v1n = normal.dot(point1.velocity),
v1t = tangent.dot(point1.velocity),
v2n = normal2.dot(point2.velocity),
v2t = tangent2.dot(point2.velocity);
normal.mult(v2n); //normal.mult(point1.velocity.mag);
normal2.mult(v1n); //normal2.mult(point2.velocity.mag);
tangent.mult(v1t); //tangent.mult(point1.velocity.mag);
tangent2.mult(v2t); //tangent2.mult(point2.velocity.mag);
var newv1 = new Vector(-(normal.x) + (tangent.x), -(normal.y) + (tangent.y));
var newv2 = new Vector(-(normal2.x) + (tangent2.x), -(normal2.y) + (tangent2.y));
point1.setvelocity(newv1);
point2.setvelocity(newv2);
},
checkBounds:function(){
var maxx = this.xMax;
var maxy = this.yMax;
if (this.x + this.velocity.x <= 0) {
this.x = (this.x ) * -1;
...