Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
743 B
1
Indexable
// timer code (30 fps)

double[] v = Mass.vector(object1, object2);
object1.dx += v[0];
object1.dy += v[1];

Point p = new Point(
	(int) (object1.center.x + object1.dx),
	(int) (object1.center.y + object1.dy)
);
object1.center = p;

System.out.println("[" + object1.center.x + "," + object1.dy + "]");

// vector function

double force = force(obj1, obj2);
	    
double dX = Math.abs(obj1.center.x - obj2.center.x);
double dY = Math.abs(obj1.center.y - obj2.center.y);

double udX = dX / distance(obj1, obj2);
double udY = dY / distance(obj1, obj2);

double fx = - (udX * force);
double fy = - (udY * force);    

double x = obj1.dx + fx / obj1.mass * deltaTime;
double y = obj1.dy + fy / obj1.mass * deltaTime;

double[] v = {x, y};
return v;