/** * Calculates the point where given PhysicsEntity will land. * * @param e the physics entity which trajectory should be calculated * @return landing poisition */ public static Point3D calculateLanding(PhysicsEntity e) { int time = calculateLandingTime(e); // double t2 = -e.getZmom() - D; int x = e.getX() + e.getXmom() * time; int y = e.getY() + e.getYmom() * time; return new Point3D(x, y, 0); }
/** * Calculates the number of ticks to the landing of given PhysicsEntity. * * @param e the physics entity which trajectory should be calculated * @return number of ticks until first bounce */ public static int calculateLandingTime(PhysicsEntity e) { double d = e.getZmom() * e.getZmom() + 2 * e.getZ(); if (d < 0) { return -1; } d = Math.sqrt(d); double time = -e.getZmom() - d; time *= -1; return (int) time + 1; }