Tu parles d'un mur, donc je ne pense pas que ce qu'on t'a proposé va suffire. J'ai un bout de code qui marche très bien pour des murs orthogonaux pour vérifier si un projectile quelconque passe à travers un mur (code source sous licence GPL version 2, extrait du First Person Shooter TUER) :
/**
* compute an impact from the bounds of a tarjectory
* in the simplified case (i.e with orthogonal walls and
* in the planar surface Oxz)
* @param x1: abscissa of the previous position of the projected object
* @param z1: applicate of the previous position of the projected object
* @param x2: abscissa of the next position of the projected object
* @param z2: applicate of the next position of the projected object
* @param wx1: abscissa of the first point of the wall
* @param wz1: applicate of the first point of the wall
* @param wx2: abscissa of the second point of the wall
* @param wz2: applicate of the second point of the wall
* @param wnx: abscissa of the normal at the impact
* @param wnz: applicate of the normal at the impact
* @return the computed impact if found, otherwise null
*/
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(wx1,0.0f,wz1,wnx,0,wnz));
else
return(new Impact(wx1,0.0f,wz2,wnx,0,wnz));
}
else
return(null);
}
else
{if(wz1<=z2 && z2<=wz2)
{if(z1>z2)
return(new Impact(wx1,0.0f,wz2,wnx,0,wnz));
else
return(new Impact(wx1,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-(a*x1);
float impx,impz;
if(!isHorizontal)
{impx=wx1;
impz=(a*impx)+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,wz1,wnx,0,wnz));
else
return(new Impact(wx2,0.0f,wz1,wnx,0,wnz));
}
else
return(null);
}
else
{if(wx1<=x2 && x2<=wx2)
{if(x1>x2)
return(new Impact(wx2,0.0f,wz1,wnx,0,wnz));
else
return(new Impact(wx1,0.0f,wz1,wnx,0,wnz));
}
else
return(null);
}
}
else
return(null);
}
}
}
}