marcojrfurtado

11-10-2012, 05:41 PM

Hello, I guess I missed too many classes on geometry.

This code should compute the intersection between a line, with origin at s1 and s2 as direction, and a triangle, with vertices p0, p1 and p2. I'm using a function from GLM extensions to chack for these intersections. It writes the result to intersec

#include <cstdio>

#include <glm/glm.hpp>

#include <glm/gtx/intersect.hpp>

int main() {

glm::vec3 p0(1,0,1), p1(1,0,-1), p2(1,1,0);

glm::vec3 s1(0,0,0), s2(1,0,0);

glm::vec3 intersec;

if ( glm::intersectLineTriangle(s1,s2,p0,p1,p2,intersec ) )

printf("Intersected on (%lf %lf %lf)\n",intersec.x,intersec.y,intersec.z);

else

printf("Not intersected\n");

}

Does this output make sense?

Intersected on (1.000000 0.500000 -0.000000)

Shouldn't it be (1.00000 0.000000 0.0000000)?

This code should compute the intersection between a line, with origin at s1 and s2 as direction, and a triangle, with vertices p0, p1 and p2. I'm using a function from GLM extensions to chack for these intersections. It writes the result to intersec

#include <cstdio>

#include <glm/glm.hpp>

#include <glm/gtx/intersect.hpp>

int main() {

glm::vec3 p0(1,0,1), p1(1,0,-1), p2(1,1,0);

glm::vec3 s1(0,0,0), s2(1,0,0);

glm::vec3 intersec;

if ( glm::intersectLineTriangle(s1,s2,p0,p1,p2,intersec ) )

printf("Intersected on (%lf %lf %lf)\n",intersec.x,intersec.y,intersec.z);

else

printf("Not intersected\n");

}

Does this output make sense?

Intersected on (1.000000 0.500000 -0.000000)

Shouldn't it be (1.00000 0.000000 0.0000000)?