-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
intersectRayTriangle returns barycentric Z 4.5 #6
Comments
for any poor soul wandering upon this post in confusion, the baryPosition output uses barycentric coordinates for the x and y components. The z component is the scalar factor for ray. That is, 1.0 - baryPosition.x - baryPosition.y = actual z barycentric coordinate if you compute the point inside the triangle that corresponds to those barycentric coordinates, you'll find the exact same answer as if you did: tl;dr:
is equal to origin + direction * baryPosition.z |
Well, I feel it is exactly the way it should work, but should not it be documented? |
Can this be considered closed? |
Barycentric coordinates are still not explained in docs. |
If somebody is interested to improve / fix this code, I think a pull request is the best approach. :) |
This issue should be fixed in master branch for GLM 0.9.9 release. Thanks for reporting, |
It looks like now the barycentric z coordinate is never assigned, instead the value passed for it is merely divided by a determinant? (https://github.com/g-truc/glm/blob/master/glm/gtx/intersect.inl#L89) Also, the test case doesn't actually use the z coordinate for the triangle vertices which makes it impossible to catch this "bug" (?) with it: https://github.com/g-truc/glm/blob/master/test/gtx/gtx_intersect.cpp#L12 I guess you can always calculate it from the other two coordinates, in which case a little documentation about that would be very appreciated. Or am I missing something? Kind regards, Jonathan. |
thank you @nlguillemot for your explanation |
@nlguillemot So, if floating-point precision is an issue, use the latter. |
when fed with
ray origin glm::vec3(0,0,0);
ray direction glm::vec3(0,0,-1);
and 3 vertices (already transformed to world coordinates):
v0 = glm::vec3(0.5,0.5,-4.5);
v1 = glm::vec3(-0.5,-0.5,-4.5);
v2 = glm::vec3(0.5,-0.5,-4.5);
It returns barycentric coordinates a = 0, b = 0.5 , c = 4.5
If I understand correctly, a+b+c should equal to 1.
They don't seem to be barycentric coordinates, they seem like.. normal cartesian coordinates of the intersection point.
The text was updated successfully, but these errors were encountered: