donc, je dois faire intersection Ray-AABB Voici mon code, tiré d'un livreintersection Ray-AABB
bool intersection(point start, point dir){
float tmax, tmin, tmaxY, tminY, tmaxZ, tminZ;
float a;
point temp1, temp2;
//check x
a = 1/dir[0];
if(a > 0){
tmax = (max[0] - start[0]) * a;
tmin = (min[0] - start[0]) * a;
}else{
tmax = (min[0] - start[0]) * a;
tmin = (max[0] - start[0]) * a;
}
if(tmin > tmax) return false;
//check y
a = 1/dir[1];
if(a > 0){
tmaxY = (max[1] - start[1]) * a;
tminY = (min[1] - start[1]) * a;
}else{
tmaxY = (min[1] - start[1]) * a;
tminY = (max[1] - start[1]) * a;
}
if(tminY > tmin) tmin = tminY;
if(tmaxY < tmax) tmax = tmaxY;
if(tmin > tmax) return false;
//check z
a = 1/dir[2];
if(a > 0){
tmaxZ = (max[2] - start[2]) * a;
tminZ = (min[2] - start[2]) * a;
}else{
tmaxZ = (min[2] - start[2]) * a;
tminZ = (max[2] - start[2]) * a;
}
if(tminZ > tmin) tmin = tminZ;
if(tmaxZ < tmax) tmax = tmaxZ;
if(tmin > tmax) return false;
return true;
}
cependant, il ne fonctionne pas pour moi. L'intersection ci-dessus retourne faux (coz tminY> tmin mais plus petit que Tmax) quand il est censé revenir vrai (testé sans englobante AABB)
Observations:
start(0, 0, 5) and dir(-89.5, -99.5, -100)
bounding box: max(-5, 0, 0) and min(-5, -5, 0)
tmin = 0.055865921
tmax = 0.055865921
tminY = 0
tmaxY = 0.050251257, therefor tmax = 0.050251257
Because tmin > tmax -> return false
It is supposed to be true
Toute aide sera appréciée
Le bon outil pour résoudre ces problèmes est votre débogueur. Vous devez parcourir votre code ligne par ligne * avant * de demander Stack Overflow. Pour plus d'aide, veuillez lire [Comment déboguer de petits programmes (par Eric Lippert)] (https://ericlippert.com/2014/03/05/how-to-debug-small-programs/). Au minimum, vous devriez [modifier] votre question pour inclure un exemple [Minimal, complet et vérifiable] (http://stackoverflow.com/help/mcve) qui reproduit votre problème, ainsi que les observations que vous avez faites dans le débogueur. –
Une fois que vous faites vos devoirs de débogage, juste pour le plaisir: vérifiez comment l'extrait de code ci-dessus réagit à l'intersection le long des axes Ox/Oy/Oz (indice: division flottante par zéro). –
@ πάντα ῥεῖ Je l'ai débogué. Il donne vraiment tminY qui est supérieur à tmax, c'est pourquoi j'ai demandé sur Stack Overflow. Si vous avez trouvé l'erreur dans mon code s'il vous plaît dites-moi – RLin