Time To Cover Distance

omniyo
Posts: 5
Joined: Tue Oct 30, 2012 6:50 pm

Time To Cover Distance

Post by omniyo »

Hi,

I need to predict how long(in seconds) it will take to an sphere to cover an specific distance without having into account Y axis.
It doesn't have to be strictly accurate but an aproximation. Before starting with Bullet I had this:

Code: Select all

double Ball::TimeToCoverDistance(Vector3 A,
                                                   Vector3 B,
                                                   double force)
{
	//this will be the velocity of the ball in the next time step *if*
	//the player was to make the pass.
	double speed = force / mMass;
	
	//calculate the velocity at B using the equation
	//
	//  v^2 = u^2 + 2as
	//

	//first calculate s (the distance between the two positions)
	double DistanceToCover = A.squaredDistance(B);
	double term = speed*speed + 2.0*DistanceToCover * Constants.friction; 

	//if  (u^2 + 2as) is negative it means the ball cannot reach point B.
	if (term <= 0.0) return -1.0;

	double v = sqrt(term);
	//it IS possible for the ball to reach B and we know its speed when it
	//gets there, so now it's easy to calculate the time using the equation
	//
	//    t = v-u
	//        ---
	//         a
	//
	return (v-speed)/Constants.friction;
}
But it is obvious that bullet have into account more features.

If It isn't possible I would like to know about it too.

Thanks in advance.