The method below computes the impact point in the planar surface Oxz with orthogonal walls by using the previous and the next position of the projectile :
public static final Impact computeImpactFromTargetoryBipoint(float x1,float z1,
float x2,float z2,float wx1,float wz1,float wx2,float wz2,float wnx,
float wnz){
boolean isHorizontal=(wnz!=0);
if(x1==x2)
{if(!isHorizontal)
{if(x1==wx1)
{if(wz1>wz2)
{if(wz2<=z2 && z2<=wz1)
{if(z1>z2)
return(new Impact(x1,0.0f,wz1,wnx,0,wnz));
else
return(new Impact(x1,0.0f,wz2,wnx,0,wnz));
}
else
return(null);
}
else
{if(wz1<=z2 && z2<=wz2)
{if(z1>z2)
return(new Impact(x1,0.0f,wz2,wnx,0,wnz));
else
return(new Impact(x1,0.0f,wz1,wnx,0,wnz));
}
else
return(null);
}
}
else
return(null);
}
else
{if(wx1>wx2)
{if(wx2<=x1 && x1<=wx1)
{if(z1>z2)
{if(z2<=wz1 && wz1<=z1)
return(new Impact(x1,0.0f,wz1,wnx,0,wnz));
else
return(null);
}
else
{if(z1<=wz1 && wz1<=z2)
return(new Impact(x1,0.0f,wz1,wnx,0,wnz));
else
return(null);
}
}
else
return(null);
}
else
{if(wx1<=x1 && x1<=wx2)
{if(z1>z2)
{if(z2<=wz1 && wz1<=z1)
return(new Impact(x1,0.0f,wz1,wnx,0,wnz));
else
return(null);
}
else
{if(z1<=wz1 && wz1<=z2)
return(new Impact(x1,0.0f,wz1,wnx,0,wnz));
else
return(null);
}
}
else
return(null);
}
}
}
else
{float a=(z2-z1)/(x2-x1);
float b=z1-(ax1);
float impx,impz;
if(!isHorizontal)
{impx=wx1;
impz=(aimpx)+b;
if(wz1>wz2)
{if(wz2<=impz && impz<=wz1)
return(new Impact(impx,0.0f,impz,wnx,0,wnz));
else
return(null);
}
else
{if(wz1<=impz && impz<=wz2)
return(new Impact(impx,0.0f,impz,wnx,0,wnz));
else
return(null);
}
}
else
{if(a!=0)
{impz=wz1;
impx=(impz-b)/a;
if(wx1>wx2)
{if(wx2<=impx && impx<=wx1)
return(new Impact(impx,0.0f,impz,wnx,0,wnz));
else
return(null);
}
else
{if(wx1<=impx && impx<=wx2)
return(new Impact(impx,0.0f,impz,wnx,0,wnz));
else
return(null);
}
}
else
{if(z1==wz1)
{if(wx1>wx2)
{if(wx2<=x2 && x2<=wx1)
{if(x1>x2)
return(new Impact(wx1,0.0f,z1,wnx,0,wnz));
else
return(new Impact(wx2,0.0f,z1,wnx,0,wnz));
}
else
return(null);
}
else
{if(wx1<=x2 && x2<=wx2)
{if(x1>x2)
return(new Impact(wx2,0.0f,z1,wnx,0,wnz));
else
return(new Impact(wx1,0.0f,z1,wnx,0,wnz));
}
else
return(null);
}
}
else
return(null);
}
}
}
}
Notice that I did my best to avoid any division by zero of course. Comparing two floats by using == might be dangerous but it depends on the way we have got them. in my case, it is not dangerous as they have been read from a file. It would be more dangerous if I had got them after some computations and some conversions from double to float, from float to double and then from double to float. I will try to draw a true progress bar tomorrow if I’m not too much tired.