* @param worldWidth is the width of the world.
* @param worldHeight is the height of the world.
* @return the real motion.
*/
Vector2d move(double dx, double dy, double simulationDuration, double worldWidth, double worldHeight) {
Vector2d r = new Vector2d(dx, dy);
double tx = this.position.x + dx;
double ty = this.position.y + dy;
double size = getSize();
if (tx<size) {
r.setX(size-this.position.x);
tx = size;
}
else if (tx>(worldWidth-size)) {
r.setX(worldWidth - size - this.position.x);
tx = worldWidth - size;
}
if (ty<size) {
r.setY(size-this.position.y);
ty = size;
}
else if (ty>(worldHeight-size)) {
r.setY(worldHeight - size - this.position.y);
ty = worldHeight - size;
}
this.position.set(tx, ty);