Probleme avec Intersection rayon-triangle

dPompei2 Messages postés 55 Date d'inscription samedi 27 mars 2004 Statut Membre Dernière intervention 1 septembre 2006 - 13 mai 2006 à 00:44
dPompei2 Messages postés 55 Date d'inscription samedi 27 mars 2004 Statut Membre Dernière intervention 1 septembre 2006 - 13 mai 2006 à 00:54
J'aurais aussi bien pu placer ça dans openGl ou directX mais je trouve que ça a sa place ici. voila donc ma question:
J'ai cette fonction qui devrait nooormalement fonctionne (elle fonctionne parfaitement dans l'exemple d'ou je l'ai apprise et il y a aussi plusieurs tuts qui font presque idem ...) mais elle ne fonctionne pas ... si je donne un triangle et un rayon en parametere et je suis sur qu'ils se touchent (je les dessine et le vois de mes propres yeux :p) ça me dit que non ! et presque toujours après avoir calculé "u" ! si je "raccourcis" le vecteur de direction, elle stoppe parfois deja après avoir calculé la déterminante, ce qui n'est pas logique car la direction reste la même et un rayon a une longueur infinie ...

Enfin voila j'espere que vous pourrez m'aider ! Et si ce n'est pas le cas, p-e qqun sait m'éclairer sur les parties que je comprends pas (en pensant que je suis aps encore a l'unif mais j'ai une bonne base de math vectorielle et dans l'espace)



<meta http-equiv= "Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Kate, the KDE Advanced Text Editor">

FTSExp bool v_rayTriangle( SPos3D direction, SPos3D origin, SPos3D v1, SPos3D v2, SPos3D v3 )
{
#if 1
SPos3D edge1 = { 0.0f, 0.0f, 0.0f };
SPos3D edge2 = { 0.0f, 0.0f, 0.0f };
SPos3D pVec = { 0.0f, 0.0f, 0.0f };
SPos3D tVec = { 0.0f, 0.0f, 0.0f };
SPos3D qVec = { 0.0f, 0.0f, 0.0f };
float det = 0.0f;

float /*t = 0.0f,*/
u = 0.0f,
v = 0.0f;

/* Get the two edge vectors of the triangle that begin at v1. */
edge1 = v_minus( v2, v1 );
edge2 = v_minus( v3, v1 );

/* pVec is orthogonal to the triangle.
* Used to see if the ray is parallel to the triangle or not.
*/
pVec = v_vectProd( direction, edge2 );
det = v_scalProd( edge1, pVec );
FTSMSG( "det = %f\n", FTS_NOMSG, det );
if ( det < 0.0001 )
return false;

/* Now from here on, I don't understand it anymore. Ok, tVec is
* the vector that goes from the ray's origin to the one vertice
* that's common to edge1 and edge2, but why test if it's < 0 or
* > det ? And i know too that u v and t could be used to calculate
* texcoords, but I don't need this so i don't do it.
*/
tVec = v_minus( origin, v1 );
u = v_scalProd( tVec, pVec );
FTSMSG( "u = %f\n", FTS_NOMSG, u );
if ( u < 0.0f || u > det )
return false;

qVec = v_vectProd( tVec, edge1 );
v = v_scalProd( direction, qVec );
FTSMSG( "v = %f\n", FTS_NOMSG, v );
if ( v < 0.0f || u + v > det )
return false;

// t = v_scalProd( );
// t *= 1.0f / det;
// u *= 1.0f / det;
// v *= 1.0f / det;

return true;
}

1 réponse

dPompei2 Messages postés 55 Date d'inscription samedi 27 mars 2004 Statut Membre Dernière intervention 1 septembre 2006
13 mai 2006 à 00:54
Re voila le code en mieu formaté (fin j'espère) et j'ai vraiment besoin de votre aide !

bool v_rayTriangle( SPos3D direction, SPos3D origin, SPos3D v1, SPos3D v2, SPos3D v3 )
{
SPos3D edge, edge2, pVec, tVec, qVec;
float det, u, v;

/* Get the two edged of the triangle that have v1 as origin. */
edge1 = v_minus( v2, v1 );
edge2 = v_minus( v3, v1 );

/* pVec is orthogonal to the triangle. Used to see if the ray is parallel to the triangle or not. */
pVec = v_vectProd( direction, edge2 );
det = v_scalProd( edge1, pVec );
if( det < 0.0001f )
return false;

/* Now from here on, I don't understand it anymore... */
tVec = v_minus( origin, v1 );
u = v_scaleProd( tVec, pVec );
if( u < 0.0f || u > det )
return false; /* C'est ici que souvent, u est plus grand que det. */

qVec = v_vectProd( );
v = v_scalProd( direction, qVec );
if( v < 0.0f || u + v > det )
return false;

return true;
}

Ou v_vectProd est le produit vectoriel et v_scalProd est le produit scalaire.
0
Rejoignez-nous