Has anyone used GLM? - Hit detection in 3D
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.
typedef struct {
   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);


   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);



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;
      (L0, L1, T0, T1, T2, Intersect))
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.

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