Réponse acceptée !
Tiens, je te poste ici une de mes fonctions pour savoir si il y a intersection, et ou... avec un triangle -> assez simple pour l'adapté au quad planaire...
Demi-droite : position (pos ) + une direction (dir) normalisée
Le triangle pt[3]
Le type CPoint3 represente un point ou un vecteur 3D....
bool CLASSE::Intersection(const CPoint3& pos,const CPoint3& dir,const CPoint3 pt[3])
{
// normale du triangle
CPoint3 normal=(pt[1]-pt[0])^(pt[2]-pt[0]); // produit vectoriel
// si la direction est // a la face FALSE
float dotProd2=normal*dir; // produit scalaire
if(dotProd2==0.0f)
{
return false;
}
// calcul de la distance entre position et intersection
float dotProd1=normal*pos;
float d=-(normal*pt[0]);
t=(-dotProd1-d)/(dotProd2);
// calcul de l'intersection
CPoint3 ptInters=pos+dir*t;
// Si l'intersection est egale a un des points TRUE
if(ptInters==pt[0] || ptInters==pt[1] || ptInters==pt[2])
{
return true;
}
CPoint3 vect1=pt[0]-ptInters;
CPoint3 vect2=pt[1]-ptInters;
CPoint3 vect3=pt[2]-ptInters;
CPoint3 crossProd1=vect1^vect2;
CPoint3 crossProd2=vect2^vect3;
CPoint3 crossProd3=vect3^vect1;
// Si l'intersection est sur une arete TRUE
if(crossProd1.IsNull() && (vect1*vect2<0.0f))
{
return true;
}
if(crossProd2.IsNull() && (vect2*vect3<0.0f))
{
return true;
}
if(crossProd3.IsNull() && (vect3*vect1<0.0f))
{
return true;
}
// Si le point est hors du triangle FALSE
if(crossProd1*crossProd2<=0.0f)
{
return false;
}
if(crossProd2*crossProd3<=0.0f)
{
return false;
}
// Si on arrive ici, l'intersection est dans le triangle TRUE
return true;
}
KeniiyK