Kodewerx https://www.kodewerx.org/forum/ |
|
Has anyone used GLM? - Hit detection in 3D https://www.kodewerx.org/forum/viewtopic.php?f=24&t=7101 |
Page 1 of 1 |
Author: | HyperHacker [ Mon Nov 16, 2009 10:35 pm ] |
Post subject: | Has anyone used GLM? - Hit detection in 3D |
Turns out this is fucking hard. I've found a nice-seeming GL math library called GLM, but it's almost completely devoid of documentation. (No, a list of function names is not documentation.) It's not calculating the intersection point correctly, probably because I have no fucking idea what I'm doing. Code: typedef struct { Just looking at the numbers you can tell the intersection point should be (0, 0, -3), but the result is (0.5, 0.5, 0.25), which doesn't make any damn sense to me.glm::vec4 Colour; glm::vec3 Position; } Vertex; typedef struct { std::vector<Vertex> Vtx; glm::vec3 Normal; } Poly; //[...] Vertex V1, V2, V3; V1.Position = glm::vec3(-1.0f, -1.0f, -4.0f); V2.Position = glm::vec3( 1.0f, 1.0f, -2.0f); V1.Colour = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f); V2.Colour = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); Line.Vtx.push_back(V1); Line.Vtx.push_back(V2); V1.Position = glm::vec3(-1.0f, 1.0f, -3.0f); V2.Position = glm::vec3( 0.0f, -1.0f, -3.0f); V3.Position = glm::vec3( 1.0f, 1.0f, -3.0f); V1.Colour = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f); V2.Colour = glm::vec4(0.0f, 1.0f, 0.0f, 1.0f); V3.Colour = glm::vec4(0.0f, 0.0f, 1.0f, 1.0f); Tri.Vtx.push_back(V1); Tri.Vtx.push_back(V2); Tri.Vtx.push_back(V3); //[...] glm::vec3 Intersect, L0, L1, T0, T1, T2, O; O = glm::vec3(0.0f, 0.0f, 0.0f); T0 = Tri.Vtx[0].Position; T1 = Tri.Vtx[1].Position; T2 = Tri.Vtx[2].Position; L0 = Line.Vtx[0].Position; L1 = Line.Vtx[1].Position - Line.Vtx[0].Position; if(glm::gtx::intersect::intersectLineTriangle<glm::vec3> (L0, L1, T0, T1, T2, Intersect)) //[...] Firefox also needs a beating with a cluebat. |
Page 1 of 1 | All times are UTC - 8 hours [ DST ] |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |