PDA

View Full Version : GLM, triangle intersect and barycentric result



otto87
01-31-2013, 06:58 AM
Hi,

I work on raytracing project and i have few questions:
When i use :

glm::intersectLineTriangle(rayon->Direction,ray->Origine,
m_Model->listVertex[m_Model->listFaces[i].s1],
m_Model->listVertex[m_Model->listFaces[i].s2],
m_Model->listVertex[m_Model->listFaces[i].s3],
tmp)
tmp contains the result as barycentric coordinate.
As i understand barycentric result:
tmp.x,tmp.y and tmp.z sould be between 0 and 1 if the line interssect the triangle.
and must be right tmp.x+tmp.y+tmp.z=1
But when i run my code, results are different:
ie : tmp.x+tmp.y+tmp.z=

1.11251
0.827902
0.582208
1.03863
0.587821
1.12883
0.649694
1.10107
0.522131
0.409886
1.09019
0.98119
0.805814
0.701678
0.484763
0.969776
0.883093
1.12744

is this normal?

otto87
01-31-2013, 10:27 AM
oops, a bug!
glm::intersectLineTriangle(ray->Origine,rayon->Direction,
m_Model->listVertex[m_Model->listFaces[i].s1],
m_Model->listVertex[m_Model->listFaces[i].s2],
m_Model->listVertex[m_Model->listFaces[i].s3],
tmp)

Is better but always a big problem with bary :
-2.50849 0.19588 0.299395
-2.47599 0.18083 0.404559
-2.51029 0.0094359 0.88424
etc